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 protected:
139  // use a function pointer to allow for "if (s)" without the
140  // complications of an operator bool(). for more information, see:
141  // http://www.artima.com/cppsource/safebool.html
142  using StringIfHelperType = void (String::*)() const;
143  void StringIfHelper() const
144  {
145  }
146 
147 public:
148  // Use these for const references, e.g. in function return values
149  static const String nullstr;
150  static const String empty;
151 
156  String() : ptr{nullptr, 0, 0}
157  {
158  }
159 
168  String(const char* cstr);
169  String(const char* cstr, size_t length) : String()
170  {
171  if(cstr)
172  copy(cstr, length);
173  }
174  String(const String& str) : String()
175  {
176  *this = str;
177  }
178  explicit String(flash_string_t pstr, size_t length) : String()
179  {
180  setString(pstr, length);
181  }
182  explicit String(flash_string_t pstr) : String()
183  {
184  setString(pstr);
185  }
186 
187 #ifdef __GXX_EXPERIMENTAL_CXX0X__
188  String(String&& rval) noexcept : String()
189  {
190  move(rval);
191  }
192  String(StringSumHelper&& rval) noexcept;
193 #endif
194  explicit String(char c);
195  explicit String(unsigned char, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
196  explicit String(int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
197  : String(long(num), base, width, pad)
198  {
199  }
200  explicit String(unsigned int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
201  : String((unsigned long)(num), base, width, pad)
202  {
203  }
204  explicit String(long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
205  explicit String(long long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
206  explicit String(unsigned long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
207  explicit String(unsigned long long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
208  explicit String(float, unsigned char decimalPlaces = 2);
209  explicit String(double, unsigned char decimalPlaces = 2);
212  ~String(void)
213  {
214  invalidate();
215  }
216 
217  void setString(const char* cstr);
218  void setString(const char* cstr, size_t length);
220  void setString(flash_string_t pstr, size_t length);
221 
222  // memory management
223 
232  bool reserve(size_t size);
233 
239  bool setLength(size_t length);
240 
244  inline size_t length(void) const
245  {
246  return sso.set ? sso.len : ptr.len;
247  }
248 
252  struct Buffer {
253  char* data;
254  size_t size;
255  size_t length;
256  };
257 
264  bool setBuffer(const Buffer& buffer);
265 
272 
281  String& operator=(const String& rhs);
282  String& operator=(const char* cstr);
303 #ifdef __GXX_EXPERIMENTAL_CXX0X__
304  String& operator=(String&& rval) noexcept
305  {
306  if(this != &rval)
307  move(rval);
308  return *this;
309  }
310  String& operator=(StringSumHelper&& rval) noexcept;
311 #endif
324  bool concat(const String& str)
325  {
326  return concat(str.cbuffer(), str.length());
327  }
328  bool concat(const FlashString& fstr);
329  bool concat(const char* cstr);
330  bool concat(const char* cstr, size_t length);
331  bool concat(char c)
332  {
333  return concat(&c, 1);
334  }
335  bool concat(unsigned char num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
336  bool concat(int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
337  {
338  return concat(long(num), base, width, pad);
339  }
340  bool concat(unsigned int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
341  {
342  return concat((unsigned long)(num), base, width, pad);
343  }
344  bool concat(long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
345  bool concat(long long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
346  bool concat(unsigned long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
347  bool concat(unsigned long long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
348  bool concat(float num);
349  bool concat(double num);
350 
351  template <typename E>
352  constexpr typename std::enable_if<std::is_enum<E>::value && !std::is_convertible<E, int>::value, bool>::type
353  concat(E value)
354  {
355  extern String toString(E);
356  return concat(toString(value));
357  }
368  String& operator+=(const String& rhs)
369  {
370  concat(rhs);
371  return (*this);
372  }
374  {
375  concat(rhs);
376  return (*this);
377  }
378  String& operator+=(const char* cstr)
379  {
380  concat(cstr);
381  return (*this);
382  }
383  template <typename T> String& operator+=(T value)
384  {
385  concat(value);
386  return *this;
387  }
390  friend StringSumHelper& operator+(const StringSumHelper& lhs, const String& rhs);
391  friend StringSumHelper& operator+(const StringSumHelper& lhs, const char* cstr);
392  friend StringSumHelper& operator+(const StringSumHelper& lhs, char c);
393  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned char num);
394  friend StringSumHelper& operator+(const StringSumHelper& lhs, int num);
395  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned int num);
396  friend StringSumHelper& operator+(const StringSumHelper& lhs, long num);
397  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned long num);
398  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned long long num);
399  friend StringSumHelper& operator+(const StringSumHelper& lhs, float num);
400  friend StringSumHelper& operator+(const StringSumHelper& lhs, double num);
401 
407  operator StringIfHelperType() const
408  {
409  return isNull() ? 0 : &String::StringIfHelper;
410  }
411 
422  int compareTo(const char* cstr, size_t length) const;
423  int compareTo(const String& s) const
424  {
425  return compareTo(s.cbuffer(), s.length());
426  }
438  bool equals(const String& s) const
439  {
440  return equals(s.cbuffer(), s.length());
441  }
442  bool equals(const char* cstr) const;
443  bool equals(const char* cstr, size_t length) const;
444  bool equals(const FlashString& fstr) const
445  {
446  return fstr.equals(*this);
447  }
455  bool operator==(const String& rhs) const
456  {
457  return equals(rhs);
458  }
459  bool operator==(const char* cstr) const
460  {
461  return equals(cstr);
462  }
463  bool operator==(const FlashString& fstr) const
464  {
465  return equals(fstr);
466  }
474  bool operator!=(const String& rhs) const
475  {
476  return !equals(rhs);
477  }
478  bool operator!=(const char* cstr) const
479  {
480  return !equals(cstr);
481  }
488  bool operator<(const String& rhs) const
489  {
490  return compareTo(rhs) < 0;
491  }
492  bool operator>(const String& rhs) const
493  {
494  return compareTo(rhs) > 0;
495  }
496  bool operator<=(const String& rhs) const
497  {
498  return compareTo(rhs) <= 0;
499  }
500  bool operator>=(const String& rhs) const
501  {
502  return compareTo(rhs) >= 0;
503  }
514  bool equalsIgnoreCase(const char* cstr) const;
515  bool equalsIgnoreCase(const char* cstr, size_t length) const;
516  bool equalsIgnoreCase(const String& s2) const
517  {
518  return equalsIgnoreCase(s2.cbuffer(), s2.length());
519  }
520  bool equalsIgnoreCase(const FlashString& fstr) const
521  {
522  return fstr.equalsIgnoreCase(*this);
523  }
532  bool startsWith(const String& prefix) const
533  {
534  return startsWith(prefix, 0);
535  }
536 
546  bool startsWith(const String& prefix, size_t offset) const;
547 
553  bool endsWith(char suffix) const;
554 
560  bool endsWith(const String& suffix) const;
561 
562  // character access
563 
570  char charAt(size_t index) const
571  {
572  return operator[](index);
573  }
574 
581  void setCharAt(size_t index, char c);
582 
590  char operator[](size_t index) const;
591  char& operator[](size_t index);
602  size_t getBytes(unsigned char* buf, size_t bufsize, size_t index = 0) const;
603 
608  void toCharArray(char* buf, size_t bufsize, size_t index = 0) const
609  {
610  getBytes(reinterpret_cast<unsigned char*>(buf), bufsize, index);
611  }
612 
617  const char* c_str() const
618  {
619  return cbuffer() ?: empty.cbuffer();
620  }
621 
626  char* begin()
627  {
628  return buffer();
629  }
630 
636  char* end()
637  {
638  return buffer() + length();
639  }
640  const char* begin() const
641  {
642  return c_str();
643  }
644  const char* end() const
645  {
646  return c_str() + length();
647  }
648 
649  // search
650 
661  int indexOf(char ch, size_t fromIndex = 0) const;
662  int indexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const;
663  int indexOf(const char* s2_buf, size_t fromIndex = 0) const
664  {
665  return indexOf(s2_buf, fromIndex, strlen(s2_buf));
666  }
667  int indexOf(const String& s2, size_t fromIndex = 0) const
668  {
669  return indexOf(s2.cbuffer(), fromIndex, s2.length());
670  }
683  int lastIndexOf(char ch) const;
684  int lastIndexOf(char ch, size_t fromIndex) const;
685  int lastIndexOf(const String& s2) const;
686  int lastIndexOf(const String& s2, size_t fromIndex) const;
687  int lastIndexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const;
712  String substring(size_t from, size_t to) const;
713  String substring(size_t from) const
714  {
715  return substring(from, length());
716  }
719  // modification
720 
733  void replace(char find, char replace);
734  bool replace(const String& find, const String& replace);
735  bool replace(const char* find_buf, size_t find_len, const char* replace_buf, size_t replace_len);
750  void remove(size_t index)
751  {
752  remove(index, SIZE_MAX);
753  }
754  void remove(size_t index, size_t count);
760  void toLowerCase(void);
761 
765  void toUpperCase(void);
766 
771  void trim(const char* set = " \t\n\v\f\r");
772 
789  String& padLeft(uint16_t minWidth, char c = ' ')
790  {
791  return pad(int16_t(-minWidth), c);
792  }
793 
797  String& padRight(uint16_t minWidth, char c = ' ')
798  {
799  return pad(int16_t(minWidth), c);
800  }
801 
806  String& pad(int16_t minWidth, char c = ' ');
807 
810  // parsing/conversion
811  long toInt(void) const;
812  float toFloat(void) const;
813 
815  static constexpr size_t SSO_CAPACITY = STRING_OBJECT_SIZE - 2;
816 
817 protected:
819  struct PtrBuf {
820  char* buffer; // the actual char array
821  size_t len; // the String length (not counting the '\0')
822  size_t capacity; // the array length minus one (for the '\0')
823  };
824  // For small strings we can store data directly without requiring the heap
825  struct SsoBuf {
826  char buffer[SSO_CAPACITY + 1];
827  unsigned char len : 7;
828  unsigned char set : 1;
829  };
830  union {
833  };
834 
835  static_assert(STRING_OBJECT_SIZE == sizeof(SsoBuf), "SSO Buffer alignment problem");
836  static_assert(STRING_OBJECT_SIZE >= sizeof(PtrBuf), "STRING_OBJECT_SIZE too small");
837  static_assert(STRING_OBJECT_SIZE <= 128, "STRING_OBJECT_SIZE too large (max. 128)");
838  static_assert(STRING_OBJECT_SIZE % 4 == 0, "STRING_OBJECT_SIZE must be a multiple of 4");
839 
840 protected:
841  // Free any heap memory and set to non-SSO mode; isNull() will return true
842  void invalidate(void);
843 
844  // String is Null (invalid) by default, i.e. non-SSO and null buffer
845  __forceinline bool isNull() const
846  {
847  return !sso.set && (ptr.buffer == nullptr);
848  }
849 
850  // Get writeable buffer pointer
851  __forceinline char* buffer()
852  {
853  return sso.set ? sso.buffer : ptr.buffer;
854  }
855 
856  // Get read-only buffer pointer
857  __forceinline const char* cbuffer() const
858  {
859  return sso.set ? sso.buffer : ptr.buffer;
860  }
861 
862  // Get currently assigned capacity for current mode
863  __forceinline size_t capacity() const
864  {
865  return sso.set ? SSO_CAPACITY : ptr.capacity;
866  }
867 
868  // Called whenever string length changes to ensure NUL terminator is set
869  __forceinline void setlen(size_t len)
870  {
871  if(sso.set) {
872  sso.len = len;
873  sso.buffer[len] = '\0';
874  } else {
875  ptr.len = len;
876  if(ptr.buffer != nullptr) {
877  ptr.buffer[len] = '\0';
878  }
879  }
880  }
881 
882  // copy and move
883  String& copy(const char* cstr, size_t length);
885 #ifdef __GXX_EXPERIMENTAL_CXX0X__
886  void move(String& rhs);
887 #endif
888 };
889 
892 class StringSumHelper : public String
893 {
894 public:
896  {
897  }
898  StringSumHelper(const char* p) : String(p)
899  {
900  }
901  StringSumHelper(char c) : String(c)
902  {
903  }
904  StringSumHelper(unsigned char num) : String(num)
905  {
906  }
907  StringSumHelper(int num) : String(num)
908  {
909  }
910  StringSumHelper(unsigned int num) : String(num)
911  {
912  }
913  StringSumHelper(long num) : String(num)
914  {
915  }
916  StringSumHelper(long long num) : String(num)
917  {
918  }
919  StringSumHelper(unsigned long num) : String(num)
920  {
921  }
922  StringSumHelper(unsigned long long num) : String(num)
923  {
924  }
925  StringSumHelper(float num) : String(num)
926  {
927  }
928  StringSumHelper(double num) : String(num)
929  {
930  }
931 };
932 
933 #include "SplitString.h"
934 
935 #endif // __cplusplus
std::enable_if< std::is_integral< T >::value, String >::type toString(T value)
Definition: BitSet.h:481
#define DEC
Definition: WConstants.h:67
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:203
bool equals(const char *cstr, size_t len, bool ignoreCase=false) const
Check for equality with a C-string.
Definition: WString.h:893
StringSumHelper(unsigned int num)
Definition: WString.h:910
StringSumHelper(char c)
Definition: WString.h:901
StringSumHelper(double num)
Definition: WString.h:928
StringSumHelper(long long num)
Definition: WString.h:916
StringSumHelper(long num)
Definition: WString.h:913
StringSumHelper(const char *p)
Definition: WString.h:898
StringSumHelper(unsigned char num)
Definition: WString.h:904
StringSumHelper(int num)
Definition: WString.h:907
StringSumHelper(unsigned long num)
Definition: WString.h:919
StringSumHelper(unsigned long long num)
Definition: WString.h:922
StringSumHelper(float num)
Definition: WString.h:925
StringSumHelper(const String &s)
Definition: WString.h:895
The String class.
Definition: WString.h:137
void setString(flash_string_t pstr)
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:617
char * buffer()
Definition: WString.h:851
friend StringSumHelper & operator+(const StringSumHelper &lhs, int num)
size_t capacity() const
Definition: WString.h:863
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:516
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:532
bool equals(const String &s) const
Definition: WString.h:438
void(String::*)() const StringIfHelperType
Definition: WString.h:142
bool concat(unsigned int num, unsigned char base=DEC, unsigned char width=0, char pad='0')
Definition: WString.h:340
int lastIndexOf(const String &s2, size_t fromIndex) const
bool concat(long num, unsigned char base=DEC, unsigned char width=0, char pad='0')
const char * end() const
Definition: WString.h:644
bool concat(const String &str)
Definition: WString.h:324
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:845
friend StringSumHelper & operator+(const StringSumHelper &lhs, const String &rhs)
bool concat(double num)
String & padLeft(uint16_t minWidth, char c=' ')
Insert padding at start of string if length is less than given width.
Definition: WString.h:789
int indexOf(const String &s2, size_t fromIndex=0) const
Definition: WString.h:667
void replace(char find, char replace)
void setString(flash_string_t pstr, size_t length)
bool operator!=(const char *cstr) const
Definition: WString.h:478
void move(String &rhs)
PtrBuf ptr
Definition: WString.h:831
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:857
void remove(size_t index)
Definition: WString.h:750
String(long, unsigned char base=DEC, unsigned char width=0, char pad='0')
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:520
static const String nullstr
A null string evaluates to false.
Definition: WString.h:149
String & padRight(uint16_t minWidth, char c=' ')
Insert padding at end of string if length is less than given width.
Definition: WString.h:797
String(flash_string_t pstr, size_t length)
Definition: WString.h:178
bool equals(const FlashString &fstr) const
Definition: WString.h:444
int compareTo(const char *cstr, size_t length) const
String(const String &str)
Definition: WString.h:174
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:368
bool operator==(const FlashString &fstr) const
Definition: WString.h:463
bool operator<=(const String &rhs) const
Definition: WString.h:496
void setlen(size_t len)
Definition: WString.h:869
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:815
String substring(size_t from) const
Definition: WString.h:713
String(unsigned long long, unsigned char base=DEC, unsigned char width=0, char pad='0')
bool concat(long long num, unsigned char base=DEC, unsigned char width=0, char pad='0')
bool concat(const FlashString &fstr)
void StringIfHelper() const
Definition: WString.h:143
int indexOf(const char *s2_buf, size_t fromIndex=0) const
Definition: WString.h:663
String & copy(flash_string_t pstr, size_t length)
String(long long, unsigned char base=DEC, unsigned char width=0, char pad='0')
String(String &&rval) noexcept
Definition: WString.h:188
bool endsWith(const String &suffix) const
Compare the end of a String.
bool concat(float num)
Buffer getBuffer()
Get String content using move semantics.
String(unsigned int num, unsigned char base=DEC, unsigned char width=0, char pad='0')
Definition: WString.h:200
void toCharArray(char *buf, size_t bufsize, size_t index=0) const
Read contents of String into a buffer.
Definition: WString.h:608
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:156
friend StringSumHelper & operator+(const StringSumHelper &lhs, unsigned char num)
char charAt(size_t index) const
Obtain the character at the given index.
Definition: WString.h:570
int lastIndexOf(char ch, size_t fromIndex) const
char operator[](size_t index) const
bool operator==(const char *cstr) const
Definition: WString.h:459
int indexOf(char ch, size_t fromIndex=0) const
String(flash_string_t pstr)
Definition: WString.h:182
bool operator==(const String &rhs) const
Definition: WString.h:455
bool operator<(const String &rhs) const
Definition: WString.h:488
friend StringSumHelper & operator+(const StringSumHelper &lhs, float num)
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:212
String & operator+=(const char *cstr)
Definition: WString.h:378
bool concat(unsigned char num, unsigned char base=DEC, unsigned char width=0, char pad='0')
bool concat(unsigned long long num, unsigned char base=DEC, unsigned char width=0, char pad='0')
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:423
bool equals(const char *cstr) const
bool equalsIgnoreCase(const char *cstr, size_t length) const
String substring(size_t from, size_t to) const
String(int num, unsigned char base=DEC, unsigned char width=0, char pad='0')
Definition: WString.h:196
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:169
float toFloat(void) const
char * end()
Get a modifiable pointer to one-past the end of the String.
Definition: WString.h:636
void remove(size_t index, size_t count)
bool operator!=(const String &rhs) const
Definition: WString.h:474
String & operator+=(const FlashString &rhs)
Definition: WString.h:373
constexpr std::enable_if< std::is_enum< E >::value &&!std::is_convertible< E, int >::value, bool >::type concat(E value)
Definition: WString.h:353
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:492
bool operator>=(const String &rhs) const
Definition: WString.h:500
bool concat(int num, unsigned char base=DEC, unsigned char width=0, char pad='0')
Definition: WString.h:336
bool concat(char c)
Definition: WString.h:331
void toUpperCase(void)
Convert the entire String content to upper case.
String & operator=(String &&rval) noexcept
Definition: WString.h:304
String & copy(const char *cstr, size_t length)
bool concat(unsigned long num, unsigned char base=DEC, unsigned char width=0, char pad='0')
String & operator+=(T value)
Definition: WString.h:383
bool concat(const char *cstr)
String & operator=(const String &rhs)
bool equals(const char *cstr, size_t length) const
SsoBuf sso
Definition: WString.h:832
const char * begin() const
Definition: WString.h:640
String(unsigned char, unsigned char base=DEC, unsigned char width=0, char pad='0')
char * begin()
Get a modifiable pointer to String content.
Definition: WString.h:626
String(unsigned long, unsigned char base=DEC, unsigned char width=0, char pad='0')
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:244
static const String empty
An empty string evaluates to true.
Definition: WString.h:150
int lastIndexOf(const String &s2) const
Used with setBuffer and getBuffer methods.
Definition: WString.h:252
size_t length
Length of content, MUST be < size.
Definition: WString.h:255
size_t size
Size of memory allocation.
Definition: WString.h:254
char * data
Allocated using malloc.
Definition: WString.h:253
Used when contents allocated on heap.
Definition: WString.h:819
char * buffer
Definition: WString.h:820
size_t capacity
Definition: WString.h:822
size_t len
Definition: WString.h:821
Definition: WString.h:825
unsigned char set
true for SSO mode
Definition: WString.h:828
unsigned char len
Definition: WString.h:827
char buffer[SSO_CAPACITY+1]
Definition: WString.h:826
#define str(s)
Definition: testrunner.h:124