21
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
22
*/
23
23
24
- #include < Arduino.h>
24
+ #include " Arduino.h"
25
25
#include " WString.h"
26
26
#include " stdlib_noniso.h"
27
27
#include " esp32-hal-log.h"
@@ -80,11 +80,7 @@ String::String(unsigned char value, unsigned char base) {
80
80
String::String (int value, unsigned char base) {
81
81
init ();
82
82
char buf[2 + 8 * sizeof (int )];
83
- if (base == 10 ) {
84
- sprintf (buf, " %d" , value);
85
- } else {
86
- itoa (value, buf, base);
87
- }
83
+ itoa (value, buf, base);
88
84
*this = buf;
89
85
}
90
86
@@ -98,11 +94,7 @@ String::String(unsigned int value, unsigned char base) {
98
94
String::String (long value, unsigned char base) {
99
95
init ();
100
96
char buf[2 + 8 * sizeof (long )];
101
- if (base==10 ) {
102
- sprintf (buf, " %ld" , value);
103
- } else {
104
- ltoa (value, buf, base);
105
- }
97
+ ltoa (value, buf, base);
106
98
*this = buf;
107
99
}
108
100
@@ -140,11 +132,7 @@ String::String(double value, unsigned int decimalPlaces) {
140
132
String::String (long long value, unsigned char base) {
141
133
init ();
142
134
char buf[2 + 8 * sizeof (long long )];
143
- if (base==10 ) {
144
- sprintf (buf, " %lld" , value); // NOT SURE - NewLib Nano ... does it support %lld?
145
- } else {
146
- lltoa (value, buf, base);
147
- }
135
+ lltoa (value, buf, base);
148
136
*this = buf;
149
137
}
150
138
@@ -159,9 +147,9 @@ String::~String() {
159
147
invalidate ();
160
148
}
161
149
162
- // / *********************************************/
163
- // / * Memory Management */
164
- // / *********************************************/
150
+ /* ********************************************/
151
+ /* Memory Management */
152
+ /* ********************************************/
165
153
166
154
inline void String::init (void ) {
167
155
setSSO (false );
@@ -221,8 +209,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
221
209
// Copy the SSO buffer into allocated space
222
210
memmove (newbuffer, sso.buff , sizeof (sso.buff ));
223
211
}
224
- if (newSize > oldSize)
225
- {
212
+ if (newSize > oldSize) {
226
213
memset (newbuffer + oldSize, 0 , newSize - oldSize);
227
214
}
228
215
setSSO (false );
@@ -234,9 +221,9 @@ bool String::changeBuffer(unsigned int maxStrLen) {
234
221
return false ;
235
222
}
236
223
237
- // / *********************************************/
238
- // / * Copy and Move */
239
- // / *********************************************/
224
+ /* ********************************************/
225
+ /* Copy and Move */
226
+ /* ********************************************/
240
227
241
228
String & String::copy (const char *cstr, unsigned int length) {
242
229
if (!reserve (length)) {
@@ -292,12 +279,10 @@ void String::move(String &rhs) {
292
279
String & String::operator =(const String &rhs) {
293
280
if (this == &rhs)
294
281
return *this ;
295
-
296
282
if (rhs.buffer ())
297
283
copy (rhs.buffer (), rhs.len ());
298
284
else
299
285
invalidate ();
300
-
301
286
return *this ;
302
287
}
303
288
@@ -320,7 +305,6 @@ String & String::operator =(const char *cstr) {
320
305
copy (cstr, strlen (cstr));
321
306
else
322
307
invalidate ();
323
-
324
308
return *this ;
325
309
}
326
310
@@ -333,9 +317,9 @@ String & String::operator =(const __FlashStringHelper *pstr) {
333
317
return *this ;
334
318
}
335
319
336
- // / *********************************************/
337
- // / * concat */
338
- // / *********************************************/
320
+ /* ********************************************/
321
+ /* concat */
322
+ /* ********************************************/
339
323
340
324
bool String::concat (const String &s) {
341
325
// Special case if we're concatting ourself (s += s;) since we may end up
@@ -388,12 +372,14 @@ bool String::concat(char c) {
388
372
389
373
bool String::concat (unsigned char num) {
390
374
char buf[1 + 3 * sizeof (unsigned char )];
391
- return concat (buf, sprintf (buf, " %d" , num));
375
+ utoa (num, buf, 10 );
376
+ return concat (buf, strlen (buf));
392
377
}
393
378
394
379
bool String::concat (int num) {
395
380
char buf[2 + 3 * sizeof (int )];
396
- return concat (buf, sprintf (buf, " %d" , num));
381
+ itoa (num, buf, 10 );
382
+ return concat (buf, strlen (buf));
397
383
}
398
384
399
385
bool String::concat (unsigned int num) {
@@ -404,7 +390,8 @@ bool String::concat(unsigned int num) {
404
390
405
391
bool String::concat (long num) {
406
392
char buf[2 + 3 * sizeof (long )];
407
- return concat (buf, sprintf (buf, " %ld" , num));
393
+ ltoa (num, buf, 10 );
394
+ return concat (buf, strlen (buf));
408
395
}
409
396
410
397
bool String::concat (unsigned long num) {
@@ -413,6 +400,18 @@ bool String::concat(unsigned long num) {
413
400
return concat (buf, strlen (buf));
414
401
}
415
402
403
+ bool String::concat (long long num) {
404
+ char buf[2 + 3 * sizeof (long long )];
405
+ lltoa (num, buf, 10 );
406
+ return concat (buf, strlen (buf));
407
+ }
408
+
409
+ bool String::concat (unsigned long long num) {
410
+ char buf[1 + 3 * sizeof (unsigned long long )];
411
+ ulltoa (num, buf, 10 );
412
+ return concat (buf, strlen (buf));
413
+ }
414
+
416
415
bool String::concat (float num) {
417
416
char buf[20 ];
418
417
char * string = dtostrf (num, 4 , 2 , buf);
@@ -425,17 +424,6 @@ bool String::concat(double num) {
425
424
return concat (string, strlen (string));
426
425
}
427
426
428
- bool String::concat (long long num) {
429
- char buf[2 + 3 * sizeof (long long )];
430
- return concat (buf, sprintf (buf, " %lld" , num)); // NOT SURE - NewLib Nano ... does it support %lld?
431
- }
432
-
433
- bool String::concat (unsigned long long num) {
434
- char buf[1 + 3 * sizeof (unsigned long long )];
435
- ulltoa (num, buf, 10 );
436
- return concat (buf, strlen (buf));
437
- }
438
-
439
427
bool String::concat (const __FlashStringHelper * str) {
440
428
if (!str)
441
429
return false ;
@@ -546,9 +534,9 @@ StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHel
546
534
return a;
547
535
}
548
536
549
- // / *********************************************/
550
- // / * Comparison */
551
- // / *********************************************/
537
+ /* ********************************************/
538
+ /* Comparison */
539
+ /* ********************************************/
552
540
553
541
int String::compareTo (const String &s) const {
554
542
if (!buffer () || !s.buffer ()) {
@@ -650,9 +638,9 @@ bool String::endsWith(const String &s2) const {
650
638
return strcmp (&buffer ()[len () - s2.len ()], s2.buffer ()) == 0 ;
651
639
}
652
640
653
- // / *********************************************/
654
- // / * Character Access */
655
- // / *********************************************/
641
+ /* ********************************************/
642
+ /* Character Access */
643
+ /* ********************************************/
656
644
657
645
char String::charAt (unsigned int loc) const {
658
646
return operator [](loc);
@@ -692,9 +680,9 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind
692
680
buf[n] = 0 ;
693
681
}
694
682
695
- // / *********************************************/
696
- // / * Search */
697
- // / *********************************************/
683
+ /* ********************************************/
684
+ /* Search */
685
+ /* ********************************************/
698
686
699
687
int String::indexOf (char c) const {
700
688
return indexOf (c, 0 );
@@ -703,7 +691,7 @@ int String::indexOf(char c) const {
703
691
int String::indexOf (char ch, unsigned int fromIndex) const {
704
692
if (fromIndex >= len ())
705
693
return -1 ;
706
- const char * temp = strchr (buffer () + fromIndex, ch);
694
+ const char * temp = strchr (buffer () + fromIndex, ch);
707
695
if (temp == NULL )
708
696
return -1 ;
709
697
return temp - buffer ();
@@ -773,9 +761,9 @@ String String::substring(unsigned int left, unsigned int right) const {
773
761
return out;
774
762
}
775
763
776
- // / *********************************************/
777
- // / * Modification */
778
- // / *********************************************/
764
+ /* ********************************************/
765
+ /* Modification */
766
+ /* ********************************************/
779
767
780
768
void String::replace (char find, char replace) {
781
769
if (!buffer ())
@@ -786,7 +774,7 @@ void String::replace(char find, char replace) {
786
774
}
787
775
}
788
776
789
- void String::replace (const String& find, const String& replace) {
777
+ void String::replace (const String & find, const String & replace) {
790
778
if (len () == 0 || find.len () == 0 )
791
779
return ;
792
780
int diff = replace.len () - find.len ();
@@ -892,9 +880,9 @@ void String::trim(void) {
892
880
wbuffer ()[newlen] = 0 ;
893
881
}
894
882
895
- // / *********************************************/
896
- // / * Parsing / Conversion */
897
- // / *********************************************/
883
+ /* ********************************************/
884
+ /* Parsing / Conversion */
885
+ /* ********************************************/
898
886
899
887
long String::toInt (void ) const {
900
888
if (buffer ())
@@ -908,8 +896,7 @@ float String::toFloat(void) const {
908
896
return 0 ;
909
897
}
910
898
911
- double String::toDouble (void ) const
912
- {
899
+ double String::toDouble (void ) const {
913
900
if (buffer ())
914
901
return atof (buffer ());
915
902
return 0.0 ;
0 commit comments