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 <cstring>
62 #include <sming_attr.h>
63 
64 #include <FlashString/String.hpp>
65 
70 
71 // When compiling programs with this class, the following gcc parameters
72 // dramatically increase performance and memory (RAM) efficiency, typically
73 // with little or no increase in code size.
74 // -felide-constructors
75 // -std=c++0x
76 
77 // An inherited class for holding the result of a concatenation. These
78 // result objects are assumed to be writable by subsequent concatenations.
79 class StringSumHelper;
80 
86 // Arduino-style flash strings
87 class __FlashStringHelper; // Never actually defined
92 using flash_string_t = const __FlashStringHelper*;
93 
98 #define FPSTR(pstr_pointer) reinterpret_cast<flash_string_t>(pstr_pointer)
99 
109 #define F(string_literal) String(FPSTR(PSTR_COUNTED(string_literal)), sizeof(string_literal) - 1)
110 
132 class String
133 {
134 protected:
135  // use a function pointer to allow for "if (s)" without the
136  // complications of an operator bool(). for more information, see:
137  // http://www.artima.com/cppsource/safebool.html
138  using StringIfHelperType = void (String::*)() const;
139  void StringIfHelper() const
140  {
141  }
142 
143 public:
144  // Use these for const references, e.g. in function return values
145  static const String nullstr;
146  static const String empty;
147 
152  String() : ptr{nullptr, 0, 0}
153  {
154  }
155 
164  String(const char* cstr);
165  String(const char* cstr, size_t length) : String()
166  {
167  if(cstr)
168  copy(cstr, length);
169  }
170  String(const String& str) : String()
171  {
172  *this = str;
173  }
174  explicit String(flash_string_t pstr, size_t length) : String()
175  {
176  setString(pstr, length);
177  }
178  explicit String(flash_string_t pstr) : String()
179  {
180  setString(pstr);
181  }
182 
183  String(String&& rval) noexcept : String()
184  {
185  move(rval);
186  }
187  String(StringSumHelper&& rval) noexcept;
188  explicit String(char c);
189  explicit String(unsigned char, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
190  explicit String(int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
191  : String(long(num), base, width, pad)
192  {
193  }
194  explicit String(unsigned int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
195  : String((unsigned long)(num), base, width, pad)
196  {
197  }
198  explicit String(long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
199  explicit String(long long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
200  explicit String(unsigned long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
201  explicit String(unsigned long long, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
202  explicit String(float, unsigned char decimalPlaces = 2);
203  explicit String(double, unsigned char decimalPlaces = 2);
206  ~String(void)
207  {
208  invalidate();
209  }
210 
211  void setString(const char* cstr);
212  void setString(const char* cstr, size_t length);
214  void setString(flash_string_t pstr, size_t length);
215 
216  // memory management
217 
226  bool reserve(size_t size);
227 
233  bool setLength(size_t length);
234 
238  inline size_t length(void) const
239  {
240  return sso.set ? sso.len : ptr.len;
241  }
242 
246  struct Buffer {
247  char* data;
248  size_t size;
249  size_t length;
250  };
251 
258  bool setBuffer(const Buffer& buffer);
259 
266 
275  String& operator=(const String& rhs);
276  String& operator=(const char* cstr);
297  String& operator=(String&& rval) noexcept
298  {
299  if(this != &rval)
300  move(rval);
301  return *this;
302  }
303  String& operator=(StringSumHelper&& rval) noexcept;
316  bool concat(const String& str)
317  {
318  return concat(str.cbuffer(), str.length());
319  }
320  bool concat(const FlashString& fstr);
321  bool concat(const char* cstr);
322  bool concat(const char* cstr, size_t length);
323  bool concat(char c)
324  {
325  return concat(&c, 1);
326  }
327  bool concat(unsigned char num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
328  bool concat(int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
329  {
330  return concat(long(num), base, width, pad);
331  }
332  bool concat(unsigned int num, unsigned char base = DEC, unsigned char width = 0, char pad = '0')
333  {
334  return concat((unsigned long)(num), base, width, pad);
335  }
336  bool concat(long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
337  bool concat(long long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
338  bool concat(unsigned long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
339  bool concat(unsigned long long num, unsigned char base = DEC, unsigned char width = 0, char pad = '0');
340  bool concat(float num);
341  bool concat(double num);
342 
343  template <typename E>
344  constexpr typename std::enable_if<std::is_enum<E>::value && !std::is_convertible<E, int>::value, bool>::type
345  concat(E value)
346  {
347  extern String toString(E);
348  return concat(toString(value));
349  }
360  String& operator+=(const String& rhs)
361  {
362  concat(rhs);
363  return (*this);
364  }
366  {
367  concat(rhs);
368  return (*this);
369  }
370  String& operator+=(const char* cstr)
371  {
372  concat(cstr);
373  return (*this);
374  }
375  template <typename T> String& operator+=(T value)
376  {
377  concat(value);
378  return *this;
379  }
382  friend StringSumHelper& operator+(const StringSumHelper& lhs, const String& rhs);
383  friend StringSumHelper& operator+(const StringSumHelper& lhs, const char* cstr);
384  friend StringSumHelper& operator+(const StringSumHelper& lhs, char c);
385  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned char num);
386  friend StringSumHelper& operator+(const StringSumHelper& lhs, int num);
387  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned int num);
388  friend StringSumHelper& operator+(const StringSumHelper& lhs, long num);
389  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned long num);
390  friend StringSumHelper& operator+(const StringSumHelper& lhs, unsigned long long num);
391  friend StringSumHelper& operator+(const StringSumHelper& lhs, float num);
392  friend StringSumHelper& operator+(const StringSumHelper& lhs, double num);
393 
399  operator StringIfHelperType() const
400  {
401  return isNull() ? 0 : &String::StringIfHelper;
402  }
403 
414  int compareTo(const char* cstr, size_t length) const;
415  int compareTo(const String& s) const
416  {
417  return compareTo(s.cbuffer(), s.length());
418  }
430  bool equals(const String& s) const
431  {
432  return equals(s.cbuffer(), s.length());
433  }
434  bool equals(const char* cstr) const;
435  bool equals(const char* cstr, size_t length) const;
436  bool equals(const FlashString& fstr) const
437  {
438  return fstr.equals(*this);
439  }
447  bool operator==(const String& rhs) const
448  {
449  return equals(rhs);
450  }
451  bool operator==(const char* cstr) const
452  {
453  return equals(cstr);
454  }
455  bool operator==(const FlashString& fstr) const
456  {
457  return equals(fstr);
458  }
466  bool operator!=(const String& rhs) const
467  {
468  return !equals(rhs);
469  }
470  bool operator!=(const char* cstr) const
471  {
472  return !equals(cstr);
473  }
480  bool operator<(const String& rhs) const
481  {
482  return compareTo(rhs) < 0;
483  }
484  bool operator>(const String& rhs) const
485  {
486  return compareTo(rhs) > 0;
487  }
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  }
506  bool equalsIgnoreCase(const char* cstr) const;
507  bool equalsIgnoreCase(const char* cstr, size_t length) const;
508  bool equalsIgnoreCase(const String& s2) const
509  {
510  return equalsIgnoreCase(s2.cbuffer(), s2.length());
511  }
512  bool equalsIgnoreCase(const FlashString& fstr) const
513  {
514  return fstr.equalsIgnoreCase(*this);
515  }
524  bool startsWith(const String& prefix) const
525  {
526  return startsWith(prefix, 0);
527  }
528 
538  bool startsWith(const String& prefix, size_t offset) const;
539 
545  bool endsWith(char suffix) const;
546 
552  bool endsWith(const String& suffix) const;
553 
554  // character access
555 
562  char charAt(size_t index) const
563  {
564  return operator[](index);
565  }
566 
573  void setCharAt(size_t index, char c);
574 
582  char operator[](size_t index) const;
583  char& operator[](size_t index);
594  size_t getBytes(unsigned char* buf, size_t bufsize, size_t index = 0) const;
595 
600  void toCharArray(char* buf, size_t bufsize, size_t index = 0) const
601  {
602  getBytes(reinterpret_cast<unsigned char*>(buf), bufsize, index);
603  }
604 
609  const char* c_str() const
610  {
611  return cbuffer() ?: empty.cbuffer();
612  }
613 
618  char* begin()
619  {
620  return buffer();
621  }
622 
628  char* end()
629  {
630  return buffer() + length();
631  }
632  const char* begin() const
633  {
634  return c_str();
635  }
636  const char* end() const
637  {
638  return c_str() + length();
639  }
640 
641  // search
642 
653  int indexOf(char ch, size_t fromIndex = 0) const;
654  int indexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const;
655  int indexOf(const char* s2_buf, size_t fromIndex = 0) const
656  {
657  return indexOf(s2_buf, fromIndex, strlen(s2_buf));
658  }
659  int indexOf(const String& s2, size_t fromIndex = 0) const
660  {
661  return indexOf(s2.cbuffer(), fromIndex, s2.length());
662  }
675  int lastIndexOf(char ch) const;
676  int lastIndexOf(char ch, size_t fromIndex) const;
677  int lastIndexOf(const String& s2) const;
678  int lastIndexOf(const String& s2, size_t fromIndex) const;
679  int lastIndexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const;
704  String substring(size_t from, size_t to) const;
705  String substring(size_t from) const
706  {
707  return substring(from, length());
708  }
711  // modification
712 
725  void replace(char find, char replace);
726  bool replace(const String& find, const String& replace);
727  bool replace(const char* find_buf, size_t find_len, const char* replace_buf, size_t replace_len);
742  void remove(size_t index)
743  {
744  remove(index, SIZE_MAX);
745  }
746  void remove(size_t index, size_t count);
752  void toLowerCase(void);
753 
757  void toUpperCase(void);
758 
763  void trim(const char* set = " \t\n\v\f\r");
764 
781  String& padLeft(uint16_t minWidth, char c = ' ')
782  {
783  return pad(int16_t(-minWidth), c);
784  }
785 
789  String& padRight(uint16_t minWidth, char c = ' ')
790  {
791  return pad(int16_t(minWidth), c);
792  }
793 
798  String& pad(int16_t minWidth, char c = ' ');
799 
802  // parsing/conversion
803  long toInt(void) const;
804  float toFloat(void) const;
805 
807  static constexpr size_t SSO_SIZE = std::max(size_t(STRING_OBJECT_SIZE), sizeof(char*) * 3);
808  static constexpr size_t SSO_CAPACITY = SSO_SIZE - 2;
809 
810 protected:
812  struct PtrBuf {
813  char* buffer; // the actual char array
814  size_t len; // the String length (not counting the '\0')
815  size_t capacity; // the array length minus one (for the '\0')
816  };
817  // For small strings we can store data directly without requiring the heap
818  struct SsoBuf {
819  char buffer[SSO_CAPACITY + 1];
820  unsigned char len : 7;
821  unsigned char set : 1;
822  };
823  union {
826  };
827 
828  static_assert(SSO_SIZE == sizeof(SsoBuf), "SSO Buffer alignment problem");
829  static_assert(SSO_SIZE >= sizeof(PtrBuf), "STRING_OBJECT_SIZE too small");
830  static_assert(SSO_SIZE <= 128, "STRING_OBJECT_SIZE too large (max. 128)");
831  static_assert(SSO_SIZE % 4 == 0, "STRING_OBJECT_SIZE must be a multiple of 4");
832 
833 protected:
834  // Free any heap memory and set to non-SSO mode; isNull() will return true
835  void invalidate(void);
836 
837  // String is Null (invalid) by default, i.e. non-SSO and null buffer
838  __forceinline bool isNull() const
839  {
840  return !sso.set && (ptr.buffer == nullptr);
841  }
842 
843  // Get writeable buffer pointer
844  __forceinline char* buffer()
845  {
846  return sso.set ? sso.buffer : ptr.buffer;
847  }
848 
849  // Get read-only buffer pointer
850  __forceinline const char* cbuffer() const
851  {
852  return sso.set ? sso.buffer : ptr.buffer;
853  }
854 
855  // Get currently assigned capacity for current mode
856  __forceinline size_t capacity() const
857  {
858  return sso.set ? SSO_CAPACITY : ptr.capacity;
859  }
860 
861  // Called whenever string length changes to ensure NUL terminator is set
862  __forceinline void setlen(size_t len)
863  {
864  if(sso.set) {
865  sso.len = len;
866  sso.buffer[len] = '\0';
867  } else {
868  ptr.len = len;
869  if(ptr.buffer != nullptr) {
870  ptr.buffer[len] = '\0';
871  }
872  }
873  }
874 
875  // copy and move
876  String& copy(const char* cstr, size_t length);
878  void move(String& rhs);
879 };
880 
883 class StringSumHelper : public String
884 {
885 public:
887  {
888  }
889  StringSumHelper(const char* p) : String(p)
890  {
891  }
892  StringSumHelper(char c) : String(c)
893  {
894  }
895  StringSumHelper(unsigned char num) : String(num)
896  {
897  }
898  StringSumHelper(int num) : String(num)
899  {
900  }
901  StringSumHelper(unsigned int num) : String(num)
902  {
903  }
904  StringSumHelper(long num) : String(num)
905  {
906  }
907  StringSumHelper(long long num) : String(num)
908  {
909  }
910  StringSumHelper(unsigned long num) : String(num)
911  {
912  }
913  StringSumHelper(unsigned long long num) : String(num)
914  {
915  }
916  StringSumHelper(float num) : String(num)
917  {
918  }
919  StringSumHelper(double num) : String(num)
920  {
921  }
922 };
923 
924 #include "SplitString.h"
925 
926 #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:92
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:884
StringSumHelper(unsigned int num)
Definition: WString.h:901
StringSumHelper(char c)
Definition: WString.h:892
StringSumHelper(double num)
Definition: WString.h:919
StringSumHelper(long long num)
Definition: WString.h:907
StringSumHelper(long num)
Definition: WString.h:904
StringSumHelper(const char *p)
Definition: WString.h:889
StringSumHelper(unsigned char num)
Definition: WString.h:895
StringSumHelper(int num)
Definition: WString.h:898
StringSumHelper(unsigned long num)
Definition: WString.h:910
StringSumHelper(unsigned long long num)
Definition: WString.h:913
StringSumHelper(float num)
Definition: WString.h:916
StringSumHelper(const String &s)
Definition: WString.h:886
The String class.
Definition: WString.h:133
void setString(flash_string_t pstr)
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:609
char * buffer()
Definition: WString.h:844
friend StringSumHelper & operator+(const StringSumHelper &lhs, int num)
size_t capacity() const
Definition: WString.h:856
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:508
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:524
bool equals(const String &s) const
Definition: WString.h:430
void(String::*)() const StringIfHelperType
Definition: WString.h:138
bool concat(unsigned int num, unsigned char base=DEC, unsigned char width=0, char pad='0')
Definition: WString.h:332
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:636
bool concat(const String &str)
Definition: WString.h:316
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:838
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:781
int indexOf(const String &s2, size_t fromIndex=0) const
Definition: WString.h:659
void replace(char find, char replace)
void setString(flash_string_t pstr, size_t length)
bool operator!=(const char *cstr) const
Definition: WString.h:470
void move(String &rhs)
static constexpr size_t SSO_SIZE
Max chars. (excluding NUL terminator) we can store in SSO mode.
Definition: WString.h:807
PtrBuf ptr
Definition: WString.h:824
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:850
void remove(size_t index)
Definition: WString.h:742
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:512
static const String nullstr
A null string evaluates to false.
Definition: WString.h:145
String & padRight(uint16_t minWidth, char c=' ')
Insert padding at end of string if length is less than given width.
Definition: WString.h:789
String(flash_string_t pstr, size_t length)
Definition: WString.h:174
bool equals(const FlashString &fstr) const
Definition: WString.h:436
int compareTo(const char *cstr, size_t length) const
String(const String &str)
Definition: WString.h:170
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:360
bool operator==(const FlashString &fstr) const
Definition: WString.h:455
bool operator<=(const String &rhs) const
Definition: WString.h:488
void setlen(size_t len)
Definition: WString.h:862
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
Definition: WString.h:808
String substring(size_t from) const
Definition: WString.h:705
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:139
int indexOf(const char *s2_buf, size_t fromIndex=0) const
Definition: WString.h:655
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:183
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:194
void toCharArray(char *buf, size_t bufsize, size_t index=0) const
Read contents of String into a buffer.
Definition: WString.h:600
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:152
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:562
int lastIndexOf(char ch, size_t fromIndex) const
char operator[](size_t index) const
bool operator==(const char *cstr) const
Definition: WString.h:451
int indexOf(char ch, size_t fromIndex=0) const
String(flash_string_t pstr)
Definition: WString.h:178
bool operator==(const String &rhs) const
Definition: WString.h:447
bool operator<(const String &rhs) const
Definition: WString.h:480
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:206
String & operator+=(const char *cstr)
Definition: WString.h:370
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:415
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:190
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:165
float toFloat(void) const
char * end()
Get a modifiable pointer to one-past the end of the String.
Definition: WString.h:628
void remove(size_t index, size_t count)
bool operator!=(const String &rhs) const
Definition: WString.h:466
String & operator+=(const FlashString &rhs)
Definition: WString.h:365
constexpr std::enable_if< std::is_enum< E >::value &&!std::is_convertible< E, int >::value, bool >::type concat(E value)
Definition: WString.h:345
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:484
bool operator>=(const String &rhs) const
Definition: WString.h:492
bool concat(int num, unsigned char base=DEC, unsigned char width=0, char pad='0')
Definition: WString.h:328
bool concat(char c)
Definition: WString.h:323
void toUpperCase(void)
Convert the entire String content to upper case.
String & operator=(String &&rval) noexcept
Definition: WString.h:297
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:375
bool concat(const char *cstr)
String & operator=(const String &rhs)
bool equals(const char *cstr, size_t length) const
SsoBuf sso
Definition: WString.h:825
const char * begin() const
Definition: WString.h:632
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:618
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:238
static const String empty
An empty string evaluates to true.
Definition: WString.h:146
int lastIndexOf(const String &s2) const
Used with setBuffer and getBuffer methods.
Definition: WString.h:246
size_t length
Length of content, MUST be < size.
Definition: WString.h:249
size_t size
Size of memory allocation.
Definition: WString.h:248
char * data
Allocated using malloc.
Definition: WString.h:247
Used when contents allocated on heap.
Definition: WString.h:812
char * buffer
Definition: WString.h:813
size_t capacity
Definition: WString.h:815
size_t len
Definition: WString.h:814
Definition: WString.h:818
unsigned char set
true for SSO mode
Definition: WString.h:821
unsigned char len
Definition: WString.h:820
char buffer[SSO_CAPACITY+1]
Definition: WString.h:819
#define str(s)
Definition: testrunner.h:124