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 );
@@ -222,8 +210,7 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
222
210
// Copy the SSO buffer into allocated space
223
211
memmove (newbuffer, sso.buff , sizeof (sso.buff ));
224
212
}
225
- if (newSize > oldSize)
226
- {
213
+ if (newSize > oldSize) {
227
214
memset (newbuffer + oldSize, 0 , newSize - oldSize);
228
215
}
229
216
setSSO (false );
@@ -235,9 +222,9 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
235
222
return 0 ;
236
223
}
237
224
238
- // / *********************************************/
239
- // / * Copy and Move */
240
- // / *********************************************/
225
+ /* ********************************************/
226
+ /* Copy and Move */
227
+ /* ********************************************/
241
228
242
229
String & String::copy (const char *cstr, unsigned int length) {
243
230
if (!reserve (length)) {
@@ -293,12 +280,10 @@ void String::move(String &rhs) {
293
280
String & String::operator =(const String &rhs) {
294
281
if (this == &rhs)
295
282
return *this ;
296
-
297
283
if (rhs.buffer ())
298
284
copy (rhs.buffer (), rhs.len ());
299
285
else
300
286
invalidate ();
301
-
302
287
return *this ;
303
288
}
304
289
@@ -321,7 +306,6 @@ String & String::operator =(const char *cstr) {
321
306
copy (cstr, strlen (cstr));
322
307
else
323
308
invalidate ();
324
-
325
309
return *this ;
326
310
}
327
311
@@ -334,9 +318,9 @@ String & String::operator =(const __FlashStringHelper *pstr) {
334
318
return *this ;
335
319
}
336
320
337
- // / *********************************************/
338
- // / * concat */
339
- // / *********************************************/
321
+ /* ********************************************/
322
+ /* concat */
323
+ /* ********************************************/
340
324
341
325
unsigned char String::concat (const String &s) {
342
326
// Special case if we're concatting ourself (s += s;) since we may end up
@@ -389,12 +373,14 @@ unsigned char String::concat(char c) {
389
373
390
374
unsigned char String::concat (unsigned char num) {
391
375
char buf[1 + 3 * sizeof (unsigned char )];
392
- return concat (buf, sprintf (buf, " %d" , num));
376
+ utoa (num, buf, 10 );
377
+ return concat (buf, strlen (buf));
393
378
}
394
379
395
380
unsigned char String::concat (int num) {
396
381
char buf[2 + 3 * sizeof (int )];
397
- return concat (buf, sprintf (buf, " %d" , num));
382
+ itoa (num, buf, 10 );
383
+ return concat (buf, strlen (buf));
398
384
}
399
385
400
386
unsigned char String::concat (unsigned int num) {
@@ -405,7 +391,8 @@ unsigned char String::concat(unsigned int num) {
405
391
406
392
unsigned char String::concat (long num) {
407
393
char buf[2 + 3 * sizeof (long )];
408
- return concat (buf, sprintf (buf, " %ld" , num));
394
+ ltoa (num, buf, 10 );
395
+ return concat (buf, strlen (buf));
409
396
}
410
397
411
398
unsigned char String::concat (unsigned long num) {
@@ -428,7 +415,8 @@ unsigned char String::concat(double num) {
428
415
429
416
unsigned char String::concat (long long num) {
430
417
char buf[2 + 3 * sizeof (long long )];
431
- return concat (buf, sprintf (buf, " %lld" , num)); // NOT SURE - NewLib Nano ... does it support %lld?
418
+ lltoa (num, buf, 10 );
419
+ return concat (buf, strlen (buf));
432
420
}
433
421
434
422
unsigned char String::concat (unsigned long long num) {
@@ -544,9 +532,9 @@ StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHel
544
532
return a;
545
533
}
546
534
547
- // / *********************************************/
548
- // / * Comparison */
549
- // / *********************************************/
535
+ /* ********************************************/
536
+ /* Comparison */
537
+ /* ********************************************/
550
538
551
539
int String::compareTo (const String &s) const {
552
540
if (!buffer () || !s.buffer ()) {
@@ -648,9 +636,9 @@ unsigned char String::endsWith(const String &s2) const {
648
636
return strcmp (&buffer ()[len () - s2.len ()], s2.buffer ()) == 0 ;
649
637
}
650
638
651
- // / *********************************************/
652
- // / * Character Access */
653
- // / *********************************************/
639
+ /* ********************************************/
640
+ /* Character Access */
641
+ /* ********************************************/
654
642
655
643
char String::charAt (unsigned int loc) const {
656
644
return operator [](loc);
@@ -690,9 +678,9 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind
690
678
buf[n] = 0 ;
691
679
}
692
680
693
- // / *********************************************/
694
- // / * Search */
695
- // / *********************************************/
681
+ /* ********************************************/
682
+ /* Search */
683
+ /* ********************************************/
696
684
697
685
int String::indexOf (char c) const {
698
686
return indexOf (c, 0 );
@@ -701,7 +689,7 @@ int String::indexOf(char c) const {
701
689
int String::indexOf (char ch, unsigned int fromIndex) const {
702
690
if (fromIndex >= len ())
703
691
return -1 ;
704
- const char * temp = strchr (buffer () + fromIndex, ch);
692
+ const char * temp = strchr (buffer () + fromIndex, ch);
705
693
if (temp == NULL )
706
694
return -1 ;
707
695
return temp - buffer ();
@@ -771,9 +759,9 @@ String String::substring(unsigned int left, unsigned int right) const {
771
759
return out;
772
760
}
773
761
774
- // / *********************************************/
775
- // / * Modification */
776
- // / *********************************************/
762
+ /* ********************************************/
763
+ /* Modification */
764
+ /* ********************************************/
777
765
778
766
void String::replace (char find, char replace) {
779
767
if (!buffer ())
@@ -784,7 +772,7 @@ void String::replace(char find, char replace) {
784
772
}
785
773
}
786
774
787
- void String::replace (const String& find, const String& replace) {
775
+ void String::replace (const String & find, const String & replace) {
788
776
if (len () == 0 || find.len () == 0 )
789
777
return ;
790
778
int diff = replace.len () - find.len ();
@@ -890,9 +878,9 @@ void String::trim(void) {
890
878
wbuffer ()[newlen] = 0 ;
891
879
}
892
880
893
- // / *********************************************/
894
- // / * Parsing / Conversion */
895
- // / *********************************************/
881
+ /* ********************************************/
882
+ /* Parsing / Conversion */
883
+ /* ********************************************/
896
884
897
885
long String::toInt (void ) const {
898
886
if (buffer ())
@@ -906,8 +894,7 @@ float String::toFloat(void) const {
906
894
return 0 ;
907
895
}
908
896
909
- double String::toDouble (void ) const
910
- {
897
+ double String::toDouble (void ) const {
911
898
if (buffer ())
912
899
return atof (buffer ());
913
900
return 0.0 ;
0 commit comments