WString.h
Go to the documentation of this file.
1 /* $Id: WString.h 1156 2011-06-07 04:01:16Z bhagman $
2 ||
3 || @author Paul Stoffregen <paul@pjrc.com>
4 || @url http://wiring.org.co/
5 || @contribution Hernando Barragan <b@wiring.org.co>
6 || @contribution Brett Hagman <bhagman@wiring.org.co>
7 || @contribution Alexander Brevig <abrevig@wiring.org.co>
8 ||
9 || @description
10 || | String class.
11 || |
12 || | Wiring Common API
13 || #
14 ||
15 || @license Please see cores/Common/License.txt.
16 ||
17 */
18 
19 /*
20  * @author: 2 Oct 2018 - mikee47 <mike@sillyhouse.net>
21  *
22  * The standard String object default constructor creates an empty string, which requires a heap allocation of 1 byte.
23  * I changed this behaviour to default to a null string (invalid) to avoid this (usually) un-necessary allocation.
24  * If the value of the string hasn't actually been assigned yet then an 'invalid' (or null) string is the more logical choice.
25  * Additional changes ensure that the content of such a string are equivalent to an empty string "".
26  *
27  * Background
28  *
29  * The intent of the Wiring authors seems to be that an expression producing a String object will fail and produce
30  * an 'invalid' String (that evaluates to False) if any of the allocations within that expression fail. This could
31  * be due to heap fragmentation, low memory or a String which is just too big.
32  *
33  * By example:
34  *
35  * String tmp = String("A") + String("B");
36  *
37  * If a heap allocation fails on either "A" or "B" the the result should be a null string. However, this is not actually
38  * the case. In practice, if "A" fails but "B" does not then the result will be "B", while if "A" succeeds but "B" fails
39  * then the result will be 'invalid'. This would appear to be an oversight in the Wiring library (last updated July 2016).
40  *
41  * I made a decision with these changes that heap allocation errors are a rare enough occurrence that attempting to deal with
42  * them in such a manner causes more problems than it solves.
43  *
44  * These changes have a knock-on effect in that if any of the allocations in an expression fail, then the result, tmp,
45  * will be unpredictable.
46  *
47  * @author Nov 2019 mikee47 <mike@sillyhouse.net>
48  *
49  * Small String Optimisation (SSO). Based on the Arduino ESP8266 core implementation.
50  * An empty String object now consumes 12 bytes (from 8) but provides an SSO capacity of 11 characters.
51  * Capacity and length types changed to size_t, thus String is no longer restricted to 64K.
52  *
53  */
54 
55 #pragma once
56 
57 #ifdef __cplusplus
58 
59 #include "WConstants.h"
60 #include <cstddef>
61 #include <string.h>
62 #include <sming_attr.h>
63 
64 #include <FlashString/String.hpp>
65 
70 
71 #ifndef __GXX_EXPERIMENTAL_CXX0X__
72 #define __GXX_EXPERIMENTAL_CXX0X__
73 #endif
74 
75 // When compiling programs with this class, the following gcc parameters
76 // dramatically increase performance and memory (RAM) efficiency, typically
77 // with little or no increase in code size.
78 // -felide-constructors
79 // -std=c++0x
80 
81 // An inherited class for holding the result of a concatenation. These
82 // result objects are assumed to be writable by subsequent concatenations.
83 class StringSumHelper;
84 
90 // Arduino-style flash strings
91 class __FlashStringHelper; // Never actually defined
96 using flash_string_t = const __FlashStringHelper*;
97 
102 #define FPSTR(pstr_pointer) reinterpret_cast<flash_string_t>(pstr_pointer)
103 
113 #define F(string_literal) String(FPSTR(PSTR_COUNTED(string_literal)), sizeof(string_literal) - 1)
114 
136 class String
137 {
138  // use a function pointer to allow for "if (s)" without the
139  // complications of an operator bool(). for more information, see:
140  // http://www.artima.com/cppsource/safebool.html
141  using StringIfHelperType = void (String::*)() const;
142  void StringIfHelper() const
143  {
144  }
145 
146 public:
147  // Use these for const references, e.g. in function return values
148  static const String nullstr;
149  static const String empty;
150 
155  String() : ptr{nullptr, 0, 0}
156  {
157  }
158 
167  String(const char* cstr);
168  String(const char* cstr, size_t length) : String()
169  {
170  if(cstr)
171  copy(cstr, length);
172  }
173  String(const String& str) : String()
174  {
175  *this = str;
176  }
177  explicit String(flash_string_t pstr, size_t length) : String()
178  {
179  setString(pstr, length);
180  }
181  explicit String(flash_string_t pstr) : String()
182  {
183  setString(pstr);
184  }
185 
186 #ifdef __GXX_EXPERIMENTAL_CXX0X__
187  String(String&& rval) noexcept : String()
188  {
189  move(rval);
190  }
191  String(StringSumHelper&& rval) noexcept;
192 #endif
193  explicit String(char c);
194  explicit String(unsigned char, unsigned char base = 10, unsigned char width = 0, char pad = '0');
195  explicit String(int num, unsigned char base = 10, unsigned char width = 0, char pad = '0')
196  : String(long(num), base, width, pad)
197  {
198  }
199  explicit String(unsigned int num, unsigned char base = 10, unsigned char width = 0, char pad = '0')
200  : String((unsigned long)(num), base, width, pad)
201  {
202  }
203  explicit String(long, unsigned char base = 10, unsigned char width = 0, char pad = '0');
204  explicit String(long long, unsigned char base = 10, unsigned char width = 0, char pad = '0');
205  explicit String(unsigned long, unsigned char base = 10, unsigned char width = 0, char pad = '0');
206  explicit String(unsigned long long, unsigned char base = 10, unsigned char width = 0, char pad = '0');
207  explicit String(float, unsigned char decimalPlaces = 2);
208  explicit String(double, unsigned char decimalPlaces = 2);
211  ~String(void)
212  {
213  invalidate();
214  }
215 
216  void setString(const char* cstr);
217  void setString(const char* cstr, size_t length);
219  void setString(flash_string_t pstr, size_t length);
220 
221  // memory management
222 
231  bool reserve(size_t size);
232 
238  bool setLength(size_t length);
239 
243  inline size_t length(void) const
244  {
245  return sso.set ? sso.len : ptr.len;
246  }
247 
251  struct Buffer {
252  char* data;
253  size_t size;
254  size_t length;
255  };
256 
263  bool setBuffer(const Buffer& buffer);
264 
271 
280  String& operator=(const String& rhs);
281  String& operator=(const char* cstr);
302 #ifdef __GXX_EXPERIMENTAL_CXX0X__
303  String& operator=(String&& rval) noexcept
304  {
305  if(this != &rval)
306  move(rval);
307  return *this;
308  }
309  String& operator=(StringSumHelper&& rval) noexcept;
310 #endif
323  bool concat(const String& str)
324  {
325  return concat(str.cbuffer(), str.length());
326  }
327  bool concat(const FlashString& fstr);
328  bool concat(const char* cstr);
329  bool concat(const char* cstr, size_t length);
330  bool concat(char c)
331  {
332  return concat(&c, 1);
333  }
334  bool concat(unsigned char num, unsigned char base = 10, unsigned char width = 0, char pad = '0');
335  bool concat(int num, unsigned char base = 10, unsigned char width = 0, char pad = '0')
336  {
337  return concat(long(num), base, width, pad);
338  }
339  bool concat(unsigned int num, unsigned char base = 10, unsigned char width = 0, char pad = '0')
340  {
341  return concat((unsigned long)(num), base, width, pad);
342  }
343  bool concat(long num, unsigned char base = 10, unsigned char width = 0, char pad = '0');
344  bool concat(long long num, unsigned char base = 10, unsigned char width = 0, char pad = '0');
345  bool concat(unsigned long num, unsigned char base = 10, unsigned char width = 0, char pad = '0');
346  bool concat(unsigned long long num, unsigned char base = 10, unsigned char width = 0, char pad = '0');
347  bool concat(float num);
348  bool concat(double num);
349 
350  template <typename E>
351  constexpr typename std::enable_if<std::is_enum<E>::value && !std::is_convertible<E, int>::value, bool>::type
352  concat(E value)
353  {
354  extern String toString(E);
355  return concat(toString(value));
356  }
367  String& operator+=(const String& rhs)
368  {
369  concat(rhs);
370  return (*this);
371  }
373  {
374  concat(rhs);
375  return (*this);
376  }
377  String& operator+=(const char* cstr)
378  {
379  concat(cstr);
380  return (*this);
381  }
382  template <typename T> String& operator+=(T value)
383  {
384  concat(value);
385  return *this;
386  }
389  friend StringSumHelper& operator+(const StringSumHelper& lhs, const String& rhs);
390  friend StringSumHelper& operator+(const StringSumHelper& lhs, const char* cstr);
391  friend StringSumHelper& operator+(const StringSumHelper& lhs, char c);
392  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned char num);
393  friend StringSumHelper& operator+(const StringSumHelper& lhs, int num);
394  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned int num);
395  friend StringSumHelper& operator+(const StringSumHelper& lhs, long num);
396  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned long num);
397  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned long long num);
398  friend StringSumHelper& operator+(const StringSumHelper& lhs, float num);
399  friend StringSumHelper& operator+(const StringSumHelper& lhs, double num);
400 
406  operator StringIfHelperType() const
407  {
408  return isNull() ? 0 : &String::StringIfHelper;
409  }
410 
421  int compareTo(const char* cstr, size_t length) const;
422  int compareTo(const String& s) const
423  {
424  return compareTo(s.cbuffer(), s.length());
425  }
437  bool equals(const String& s) const
438  {
439  return equals(s.cbuffer(), s.length());
440  }
441  bool equals(const char* cstr) const;
442  bool equals(const char* cstr, size_t length) const;
443  bool equals(const FlashString& fstr) const
444  {
445  return fstr.equals(*this);
446  }
454  bool operator==(const String& rhs) const
455  {
456  return equals(rhs);
457  }
458  bool operator==(const char* cstr) const
459  {
460  return equals(cstr);
461  }
462  bool operator==(const FlashString& fstr) const
463  {
464  return equals(fstr);
465  }
473  bool operator!=(const String& rhs) const
474  {
475  return !equals(rhs);
476  }
477  bool operator!=(const char* cstr) const
478  {
479  return !equals(cstr);
480  }
487  bool operator<(const String& rhs) const
488  {
489  return compareTo(rhs) < 0;
490  }
491  bool operator>(const String& rhs) const
492  {
493  return compareTo(rhs) > 0;
494  }
495  bool operator<=(const String& rhs) const
496  {
497  return compareTo(rhs) <= 0;
498  }
499  bool operator>=(const String& rhs) const
500  {
501  return compareTo(rhs) >= 0;
502  }
513  bool equalsIgnoreCase(const char* cstr) const;
514  bool equalsIgnoreCase(const char* cstr, size_t length) const;
515  bool equalsIgnoreCase(const String& s2) const
516  {
517  return equalsIgnoreCase(s2.cbuffer(), s2.length());
518  }
519  bool equalsIgnoreCase(const FlashString& fstr) const
520  {
521  return fstr.equalsIgnoreCase(*this);
522  }
531  bool startsWith(const String& prefix) const
532  {
533  return startsWith(prefix, 0);
534  }
535 
545  bool startsWith(const String& prefix, size_t offset) const;
546 
552  bool endsWith(char suffix) const;
553 
559  bool endsWith(const String& suffix) const;
560 
561  // character access
562 
569  char charAt(size_t index) const
570  {
571  return operator[](index);
572  }
573 
580  void setCharAt(size_t index, char c);
581 
589  char operator[](size_t index) const;
590  char& operator[](size_t index);
601  size_t getBytes(unsigned char* buf, size_t bufsize, size_t index = 0) const;
602 
607  void toCharArray(char* buf, size_t bufsize, size_t index = 0) const
608  {
609  getBytes((unsigned char*)buf, bufsize, index);
610  }
611 
616  const char* c_str() const
617  {
618  return cbuffer() ?: empty.cbuffer();
619  }
620 
625  char* begin()
626  {
627  return buffer();
628  }
629 
635  char* end()
636  {
637  return buffer() + length();
638  }
639  const char* begin() const
640  {
641  return c_str();
642  }
643  const char* end() const
644  {
645  return c_str() + length();
646  }
647 
648  // search
649 
660  int indexOf(char ch, size_t fromIndex = 0) const;
661  int indexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const;
662  int indexOf(const char* s2_buf, size_t fromIndex = 0) const
663  {
664  return indexOf(s2_buf, fromIndex, strlen(s2_buf));
665  }
666  int indexOf(const String& s2, size_t fromIndex = 0) const
667  {
668  return indexOf(s2.cbuffer(), fromIndex, s2.length());
669  }
682  int lastIndexOf(char ch) const;
683  int lastIndexOf(char ch, size_t fromIndex) const;
684  int lastIndexOf(const String& s2) const;
685  int lastIndexOf(const String& s2, size_t fromIndex) const;
686  int lastIndexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const;
711  String substring(size_t from, size_t to) const;
712  String substring(size_t from) const
713  {
714  return substring(from, length());
715  }
718  // modification
719 
732  void replace(char find, char replace);
733  bool replace(const String& find, const String& replace);
734  bool replace(const char* find_buf, size_t find_len, const char* replace_buf, size_t replace_len);
749  void remove(size_t index)
750  {
751  remove(index, SIZE_MAX);
752  }
753  void remove(size_t index, size_t count);
759  void toLowerCase(void);
760 
764  void toUpperCase(void);
765 
770  void trim(const char* set = " \t\n\v\f\r");
771 
788  String& padLeft(uint16_t minWidth, char c = ' ')
789  {
790  return pad(-minWidth, c);
791  }
792 
796  String& padRight(uint16_t minWidth, char c = ' ')
797  {
798  return pad(minWidth, c);
799  }
800 
805  String& pad(int16_t minWidth, char c = ' ');
806 
809  // parsing/conversion
810  long toInt(void) const;
811  float toFloat(void) const;
812 
814  static constexpr size_t SSO_CAPACITY = STRING_OBJECT_SIZE - 2;
815 
816 protected:
818  struct PtrBuf {
819  char* buffer; // the actual char array
820  size_t len; // the String length (not counting the '\0')
821  size_t capacity; // the array length minus one (for the '\0')
822  };
823  // For small strings we can store data directly without requiring the heap
824  struct SsoBuf {
825  char buffer[SSO_CAPACITY + 1];
826  unsigned char len : 7;
827  unsigned char set : 1;
828  };
829  union {
832  };
833 
834  static_assert(STRING_OBJECT_SIZE == sizeof(SsoBuf), "SSO Buffer alignment problem");
835  static_assert(STRING_OBJECT_SIZE >= sizeof(PtrBuf), "STRING_OBJECT_SIZE too small");
836  static_assert(STRING_OBJECT_SIZE <= 128, "STRING_OBJECT_SIZE too large (max. 128)");
837  static_assert(STRING_OBJECT_SIZE % 4 == 0, "STRING_OBJECT_SIZE must be a multiple of 4");
838 
839 protected:
840  // Free any heap memory and set to non-SSO mode; isNull() will return true
841  void invalidate(void);
842 
843  // String is Null (invalid) by default, i.e. non-SSO and null buffer
844  __forceinline bool isNull() const
845  {
846  return !sso.set && (ptr.buffer == nullptr);
847  }
848 
849  // Get writeable buffer pointer
850  __forceinline char* buffer()
851  {
852  return sso.set ? sso.buffer : ptr.buffer;
853  }
854 
855  // Get read-only buffer pointer
856  __forceinline const char* cbuffer() const
857  {
858  return sso.set ? sso.buffer : ptr.buffer;
859  }
860 
861  // Get currently assigned capacity for current mode
862  __forceinline size_t capacity() const
863  {
864  return sso.set ? SSO_CAPACITY : ptr.capacity;
865  }
866 
867  // Called whenever string length changes to ensure NUL terminator is set
868  __forceinline void setlen(size_t len)
869  {
870  if(sso.set) {
871  sso.len = len;
872  sso.buffer[len] = '\0';
873  } else {
874  ptr.len = len;
875  if(ptr.buffer != nullptr) {
876  ptr.buffer[len] = '\0';
877  }
878  }
879  }
880 
881  // copy and move
882  String& copy(const char* cstr, size_t length);
884 #ifdef __GXX_EXPERIMENTAL_CXX0X__
885  void move(String& rhs);
886 #endif
887 };
888 
891 class StringSumHelper : public String
892 {
893 public:
895  {
896  }
897  StringSumHelper(const char* p) : String(p)
898  {
899  }
900  StringSumHelper(char c) : String(c)
901  {
902  }
903  StringSumHelper(unsigned char num) : String(num)
904  {
905  }
906  StringSumHelper(int num) : String(num)
907  {
908  }
909  StringSumHelper(unsigned int num) : String(num)
910  {
911  }
912  StringSumHelper(long num) : String(num)
913  {
914  }
915  StringSumHelper(long long num) : String(num)
916  {
917  }
918  StringSumHelper(unsigned long num) : String(num)
919  {
920  }
921  StringSumHelper(unsigned long long num) : String(num)
922  {
923  }
924  StringSumHelper(float num) : String(num)
925  {
926  }
927  StringSumHelper(double num) : String(num)
928  {
929  }
930 };
931 
932 #include "SplitString.h"
933 
934 #endif // __cplusplus
std::enable_if< std::is_integral< T >::value, String >::type toString(T value)
Definition: BitSet.h:481
const __FlashStringHelper * flash_string_t
Provides a strongly-typed pointer to allow safe implicit operation using String class methods.
Definition: WString.h:96
describes a counted string stored in flash memory
Definition: String.hpp:174
bool equalsIgnoreCase(const char *cstr, size_t len) const
Definition: String.hpp:202
bool equals(const char *cstr, size_t len, bool ignoreCase=false) const
Check for equality with a C-string.
Definition: WString.h:892
StringSumHelper(unsigned int num)
Definition: WString.h:909
StringSumHelper(char c)
Definition: WString.h:900
StringSumHelper(double num)
Definition: WString.h:927
StringSumHelper(long long num)
Definition: WString.h:915
StringSumHelper(long num)
Definition: WString.h:912
StringSumHelper(const char *p)
Definition: WString.h:897
StringSumHelper(unsigned char num)
Definition: WString.h:903
StringSumHelper(int num)
Definition: WString.h:906
StringSumHelper(unsigned long num)
Definition: WString.h:918
StringSumHelper(unsigned long long num)
Definition: WString.h:921
StringSumHelper(float num)
Definition: WString.h:924
StringSumHelper(const String &s)
Definition: WString.h:894
The String class.
Definition: WString.h:137
void setString(flash_string_t pstr)
String(unsigned long, unsigned char base=10, unsigned char width=0, char pad='0')
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:616
char * buffer()
Definition: WString.h:850
friend StringSumHelper & operator+(const StringSumHelper &lhs, int num)
String(long long, unsigned char base=10, unsigned char width=0, char pad='0')
size_t capacity() const
Definition: WString.h:862
friend StringSumHelper & operator+(const StringSumHelper &lhs, char c)
friend StringSumHelper & operator+(const StringSumHelper &lhs, unsigned long long num)
bool equalsIgnoreCase(const String &s2) const
Definition: WString.h:515
String(char c)
friend StringSumHelper & operator+(const StringSumHelper &lhs, unsigned int num)
void setString(const char *cstr, size_t length)
bool startsWith(const String &prefix) const
Compare the start of a String Comparison is case-sensitive, must match exactly.
Definition: WString.h:531
bool equals(const String &s) const
Definition: WString.h:437
int lastIndexOf(const String &s2, size_t fromIndex) const
bool concat(long num, unsigned char base=10, unsigned char width=0, char pad='0')
const char * end() const
Definition: WString.h:643
bool concat(const String &str)
Definition: WString.h:323
void toLowerCase(void)
Convert the entire String content to lower case.
char & operator[](size_t index)
long toInt(void) const
bool isNull() const
Definition: WString.h:844
friend StringSumHelper & operator+(const StringSumHelper &lhs, const String &rhs)
bool concat(double num)
bool concat(unsigned long long num, unsigned char base=10, unsigned char width=0, char pad='0')
String & padLeft(uint16_t minWidth, char c=' ')
Insert padding at start of string if length is less than given width.
Definition: WString.h:788
int indexOf(const String &s2, size_t fromIndex=0) const
Definition: WString.h:666
void replace(char find, char replace)
void setString(flash_string_t pstr, size_t length)
bool operator!=(const char *cstr) const
Definition: WString.h:477
void move(String &rhs)
bool concat(unsigned char num, unsigned char base=10, unsigned char width=0, char pad='0')
PtrBuf ptr
Definition: WString.h:830
bool reserve(size_t size)
Pre-allocate String memory.
bool endsWith(char suffix) const
Compare the end of a String.
const char * cbuffer() const
Definition: WString.h:856
void remove(size_t index)
Definition: WString.h:749
friend StringSumHelper & operator+(const StringSumHelper &lhs, long num)
bool startsWith(const String &prefix, size_t offset) const
Compare a string portion.
bool equalsIgnoreCase(const FlashString &fstr) const
Definition: WString.h:519
static const String nullstr
A null string evaluates to false.
Definition: WString.h:148
String & padRight(uint16_t minWidth, char c=' ')
Insert padding at end of string if length is less than given width.
Definition: WString.h:796
String(flash_string_t pstr, size_t length)
Definition: WString.h:177
bool equals(const FlashString &fstr) const
Definition: WString.h:443
int compareTo(const char *cstr, size_t length) const
String(const String &str)
Definition: WString.h:173
bool setBuffer(const Buffer &buffer)
Set String content using move semantics from external memory buffer.
String(float, unsigned char decimalPlaces=2)
String & operator+=(const String &rhs)
Definition: WString.h:367
bool operator==(const FlashString &fstr) const
Definition: WString.h:462
bool operator<=(const String &rhs) const
Definition: WString.h:495
void setlen(size_t len)
Definition: WString.h:868
friend StringSumHelper & operator+(const StringSumHelper &lhs, unsigned long num)
bool setLength(size_t length)
set the string length accordingly, expanding if necessary
int lastIndexOf(char ch) const
String(StringSumHelper &&rval) noexcept
void setCharAt(size_t index, char c)
Sets the character at a given index.
size_t getBytes(unsigned char *buf, size_t bufsize, size_t index=0) const
Read contents of a String into a buffer.
int lastIndexOf(const char *s2_buf, size_t fromIndex, size_t s2_len) const
static constexpr size_t SSO_CAPACITY
Max chars. (excluding NUL terminator) we can store in SSO mode.
Definition: WString.h:814
String substring(size_t from) const
Definition: WString.h:712
bool concat(const FlashString &fstr)
int indexOf(const char *s2_buf, size_t fromIndex=0) const
Definition: WString.h:662
String & copy(flash_string_t pstr, size_t length)
String(String &&rval) noexcept
Definition: WString.h:187
bool endsWith(const String &suffix) const
Compare the end of a String.
bool concat(float num)
Buffer getBuffer()
Get String content using move semantics.
void toCharArray(char *buf, size_t bufsize, size_t index=0) const
Read contents of String into a buffer.
Definition: WString.h:607
String(unsigned int num, unsigned char base=10, unsigned char width=0, char pad='0')
Definition: WString.h:199
void setString(const char *cstr)
String(double, unsigned char decimalPlaces=2)
String & pad(int16_t minWidth, char c=' ')
Pad string if length is less than given width.
bool replace(const char *find_buf, size_t find_len, const char *replace_buf, size_t replace_len)
String()
Default constructor.
Definition: WString.h:155
friend StringSumHelper & operator+(const StringSumHelper &lhs, unsigned char num)
String(unsigned long long, unsigned char base=10, unsigned char width=0, char pad='0')
char charAt(size_t index) const
Obtain the character at the given index.
Definition: WString.h:569
int lastIndexOf(char ch, size_t fromIndex) const
char operator[](size_t index) const
bool operator==(const char *cstr) const
Definition: WString.h:458
int indexOf(char ch, size_t fromIndex=0) const
String(flash_string_t pstr)
Definition: WString.h:181
bool operator==(const String &rhs) const
Definition: WString.h:454
bool operator<(const String &rhs) const
Definition: WString.h:487
friend StringSumHelper & operator+(const StringSumHelper &lhs, float num)
bool concat(unsigned int num, unsigned char base=10, unsigned char width=0, char pad='0')
Definition: WString.h:339
void invalidate(void)
friend StringSumHelper & operator+(const StringSumHelper &lhs, const char *cstr)
bool equalsIgnoreCase(const char *cstr) const
String & operator=(StringSumHelper &&rval) noexcept
bool replace(const String &find, const String &replace)
~String(void)
Definition: WString.h:211
String & operator+=(const char *cstr)
Definition: WString.h:377
String & operator=(const char *cstr)
int indexOf(const char *s2_buf, size_t fromIndex, size_t s2_len) const
String(const char *cstr)
int compareTo(const String &s) const
Definition: WString.h:422
bool equals(const char *cstr) const
bool equalsIgnoreCase(const char *cstr, size_t length) const
String substring(size_t from, size_t to) const
bool concat(int num, unsigned char base=10, unsigned char width=0, char pad='0')
Definition: WString.h:335
bool concat(long long num, unsigned char base=10, unsigned char width=0, char pad='0')
void trim(const char *set=" \t\n\v\f\r")
Remove all leading and trailing characters from the String.
String(const char *cstr, size_t length)
Definition: WString.h:168
float toFloat(void) const
char * end()
Get a modifiable pointer to one-past the end of the String.
Definition: WString.h:635
void remove(size_t index, size_t count)
bool concat(unsigned long num, unsigned char base=10, unsigned char width=0, char pad='0')
bool operator!=(const String &rhs) const
Definition: WString.h:473
String & operator+=(const FlashString &rhs)
Definition: WString.h:372
constexpr std::enable_if< std::is_enum< E >::value &&!std::is_convertible< E, int >::value, bool >::type concat(E value)
Definition: WString.h:352
friend StringSumHelper & operator+(const StringSumHelper &lhs, double num)
bool concat(const char *cstr, size_t length)
bool operator>(const String &rhs) const
Definition: WString.h:491
bool operator>=(const String &rhs) const
Definition: WString.h:499
bool concat(char c)
Definition: WString.h:330
void toUpperCase(void)
Convert the entire String content to upper case.
String & operator=(String &&rval) noexcept
Definition: WString.h:303
String & copy(const char *cstr, size_t length)
String(int num, unsigned char base=10, unsigned char width=0, char pad='0')
Definition: WString.h:195
String & operator+=(T value)
Definition: WString.h:382
bool concat(const char *cstr)
String & operator=(const String &rhs)
bool equals(const char *cstr, size_t length) const
SsoBuf sso
Definition: WString.h:831
String(unsigned char, unsigned char base=10, unsigned char width=0, char pad='0')
const char * begin() const
Definition: WString.h:639
char * begin()
Get a modifiable pointer to String content.
Definition: WString.h:625
String(long, unsigned char base=10, unsigned char width=0, char pad='0')
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:243
static const String empty
An empty string evaluates to true.
Definition: WString.h:149
int lastIndexOf(const String &s2) const
Used with setBuffer and getBuffer methods.
Definition: WString.h:251
size_t length
Length of content, MUST be < size.
Definition: WString.h:254
size_t size
Size of memory allocation.
Definition: WString.h:253
char * data
Allocated using malloc.
Definition: WString.h:252
Used when contents allocated on heap.
Definition: WString.h:818
char * buffer
Definition: WString.h:819
size_t capacity
Definition: WString.h:821
size_t len
Definition: WString.h:820
Definition: WString.h:824
unsigned char set
true for SSO mode
Definition: WString.h:827
unsigned char len
Definition: WString.h:826
char buffer[SSO_CAPACITY+1]
Definition: WString.h:825
#define str(s)
Definition: testrunner.h:124