2121 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222 */
2323
24- #include < Arduino.h>
24+ #include " Arduino.h"
2525#include " WString.h"
2626#include " stdlib_noniso.h"
2727#include " esp32-hal-log.h"
@@ -80,11 +80,7 @@ String::String(unsigned char value, unsigned char base) {
8080String::String (int value, unsigned char base) {
8181 init ();
8282 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);
8884 *this = buf;
8985}
9086
@@ -98,11 +94,7 @@ String::String(unsigned int value, unsigned char base) {
9894String::String (long value, unsigned char base) {
9995 init ();
10096 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);
10698 *this = buf;
10799}
108100
@@ -140,11 +132,7 @@ String::String(double value, unsigned int decimalPlaces) {
140132String::String (long long value, unsigned char base) {
141133 init ();
142134 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);
148136 *this = buf;
149137}
150138
@@ -159,9 +147,9 @@ String::~String() {
159147 invalidate ();
160148}
161149
162- // / *********************************************/
163- // / * Memory Management */
164- // / *********************************************/
150+ /* ********************************************/
151+ /* Memory Management */
152+ /* ********************************************/
165153
166154inline void String::init (void ) {
167155 setSSO (false );
@@ -221,8 +209,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
221209 // Copy the SSO buffer into allocated space
222210 memmove (newbuffer, sso.buff , sizeof (sso.buff ));
223211 }
224- if (newSize > oldSize)
225- {
212+ if (newSize > oldSize) {
226213 memset (newbuffer + oldSize, 0 , newSize - oldSize);
227214 }
228215 setSSO (false );
@@ -234,9 +221,9 @@ bool String::changeBuffer(unsigned int maxStrLen) {
234221 return false ;
235222}
236223
237- // / *********************************************/
238- // / * Copy and Move */
239- // / *********************************************/
224+ /* ********************************************/
225+ /* Copy and Move */
226+ /* ********************************************/
240227
241228String & String::copy (const char *cstr, unsigned int length) {
242229 if (!reserve (length)) {
@@ -292,12 +279,10 @@ void String::move(String &rhs) {
292279String & String::operator =(const String &rhs) {
293280 if (this == &rhs)
294281 return *this ;
295-
296282 if (rhs.buffer ())
297283 copy (rhs.buffer (), rhs.len ());
298284 else
299285 invalidate ();
300-
301286 return *this ;
302287}
303288
@@ -320,7 +305,6 @@ String & String::operator =(const char *cstr) {
320305 copy (cstr, strlen (cstr));
321306 else
322307 invalidate ();
323-
324308 return *this ;
325309}
326310
@@ -333,9 +317,9 @@ String & String::operator =(const __FlashStringHelper *pstr) {
333317 return *this ;
334318}
335319
336- // / *********************************************/
337- // / * concat */
338- // / *********************************************/
320+ /* ********************************************/
321+ /* concat */
322+ /* ********************************************/
339323
340324bool String::concat (const String &s) {
341325 // Special case if we're concatting ourself (s += s;) since we may end up
@@ -388,12 +372,14 @@ bool String::concat(char c) {
388372
389373bool String::concat (unsigned char num) {
390374 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));
392377}
393378
394379bool String::concat (int num) {
395380 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));
397383}
398384
399385bool String::concat (unsigned int num) {
@@ -404,7 +390,8 @@ bool String::concat(unsigned int num) {
404390
405391bool String::concat (long num) {
406392 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));
408395}
409396
410397bool String::concat (unsigned long num) {
@@ -413,6 +400,18 @@ bool String::concat(unsigned long num) {
413400 return concat (buf, strlen (buf));
414401}
415402
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+
416415bool String::concat (float num) {
417416 char buf[20 ];
418417 char * string = dtostrf (num, 4 , 2 , buf);
@@ -425,17 +424,6 @@ bool String::concat(double num) {
425424 return concat (string, strlen (string));
426425}
427426
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-
439427bool String::concat (const __FlashStringHelper * str) {
440428 if (!str)
441429 return false ;
@@ -546,9 +534,9 @@ StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHel
546534 return a;
547535}
548536
549- // / *********************************************/
550- // / * Comparison */
551- // / *********************************************/
537+ /* ********************************************/
538+ /* Comparison */
539+ /* ********************************************/
552540
553541int String::compareTo (const String &s) const {
554542 if (!buffer () || !s.buffer ()) {
@@ -650,9 +638,9 @@ bool String::endsWith(const String &s2) const {
650638 return strcmp (&buffer ()[len () - s2.len ()], s2.buffer ()) == 0 ;
651639}
652640
653- // / *********************************************/
654- // / * Character Access */
655- // / *********************************************/
641+ /* ********************************************/
642+ /* Character Access */
643+ /* ********************************************/
656644
657645char String::charAt (unsigned int loc) const {
658646 return operator [](loc);
@@ -692,9 +680,9 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind
692680 buf[n] = 0 ;
693681}
694682
695- // / *********************************************/
696- // / * Search */
697- // / *********************************************/
683+ /* ********************************************/
684+ /* Search */
685+ /* ********************************************/
698686
699687int String::indexOf (char c) const {
700688 return indexOf (c, 0 );
@@ -703,7 +691,7 @@ int String::indexOf(char c) const {
703691int String::indexOf (char ch, unsigned int fromIndex) const {
704692 if (fromIndex >= len ())
705693 return -1 ;
706- const char * temp = strchr (buffer () + fromIndex, ch);
694+ const char * temp = strchr (buffer () + fromIndex, ch);
707695 if (temp == NULL )
708696 return -1 ;
709697 return temp - buffer ();
@@ -773,9 +761,9 @@ String String::substring(unsigned int left, unsigned int right) const {
773761 return out;
774762}
775763
776- // / *********************************************/
777- // / * Modification */
778- // / *********************************************/
764+ /* ********************************************/
765+ /* Modification */
766+ /* ********************************************/
779767
780768void String::replace (char find, char replace) {
781769 if (!buffer ())
@@ -786,7 +774,7 @@ void String::replace(char find, char replace) {
786774 }
787775}
788776
789- void String::replace (const String& find, const String& replace) {
777+ void String::replace (const String & find, const String & replace) {
790778 if (len () == 0 || find.len () == 0 )
791779 return ;
792780 int diff = replace.len () - find.len ();
@@ -892,9 +880,9 @@ void String::trim(void) {
892880 wbuffer ()[newlen] = 0 ;
893881}
894882
895- // / *********************************************/
896- // / * Parsing / Conversion */
897- // / *********************************************/
883+ /* ********************************************/
884+ /* Parsing / Conversion */
885+ /* ********************************************/
898886
899887long String::toInt (void ) const {
900888 if (buffer ())
@@ -908,8 +896,7 @@ float String::toFloat(void) const {
908896 return 0 ;
909897}
910898
911- double String::toDouble (void ) const
912- {
899+ double String::toDouble (void ) const {
913900 if (buffer ())
914901 return atof (buffer ());
915902 return 0.0 ;
0 commit comments