5
5
Copyright 2011, Paul Stoffregen, [email protected]
6
6
Modified by Ivan Grokhotkov, 2014 - esp8266 support
7
7
Modified by Michael C. Miller, 2015 - esp8266 progmem support
8
-
8
+
9
9
This library is free software; you can redistribute it and/or
10
10
modify it under the terms of the GNU Lesser General Public
11
11
License as published by the Free Software Foundation; either
12
12
version 2.1 of the License, or (at your option) any later version.
13
-
14
13
This library is distributed in the hope that it will be useful,
15
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
16
Lesser General Public License for more details.
18
-
17
+
19
18
You should have received a copy of the GNU Lesser General Public
20
19
License along with this library; if not, write to the Free Software
21
20
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -45,17 +44,15 @@ String::String(const __FlashStringHelper *pstr) {
45
44
*this = pstr; // see operator =
46
45
}
47
46
48
- #ifdef __GXX_EXPERIMENTAL_CXX0X__
49
- String::String (String &&rval) {
47
+ String::String (String &&rval) noexcept {
50
48
init ();
51
49
move (rval);
52
50
}
53
51
54
- String::String (StringSumHelper &&rval) {
52
+ String::String (StringSumHelper &&rval) noexcept {
55
53
init ();
56
54
move (rval);
57
55
}
58
- #endif
59
56
60
57
String::String (char c) {
61
58
init ();
@@ -120,19 +117,9 @@ String::String(double value, unsigned char decimalPlaces) {
120
117
*this = dtostrf (value, (decimalPlaces + 2 ), decimalPlaces, buf);
121
118
}
122
119
123
- String::~String () {
124
- invalidate ();
125
- }
126
-
127
- // /*********************************************/
128
- // /* Memory Management */
129
- // /*********************************************/
130
-
131
- inline void String::init (void ) {
132
- setSSO (true );
133
- setLen (0 );
134
- wbuffer ()[0 ] = 0 ;
135
- }
120
+ /* ********************************************/
121
+ /* Memory Management */
122
+ /* ********************************************/
136
123
137
124
void String::invalidate (void ) {
138
125
if (!isSSO () && wbuffer ())
@@ -199,9 +186,9 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
199
186
return 0 ;
200
187
}
201
188
202
- // / *********************************************/
203
- // / * Copy and Move */
204
- // / *********************************************/
189
+ /* ********************************************/
190
+ /* Copy and Move */
191
+ /* ********************************************/
205
192
206
193
String & String::copy (const char *cstr, unsigned int length) {
207
194
if (!reserve (length)) {
@@ -223,36 +210,11 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
223
210
return *this ;
224
211
}
225
212
226
- #ifdef __GXX_EXPERIMENTAL_CXX0X__
227
- void String::move (String &rhs) {
228
- if (buffer ()) {
229
- if (capacity () >= rhs.len ()) {
230
- memmove_P (wbuffer (), rhs.buffer (), rhs.length () + 1 );
231
- setLen (rhs.len ());
232
- rhs.invalidate ();
233
- return ;
234
- } else {
235
- if (!isSSO ()) {
236
- free (wbuffer ());
237
- setBuffer (nullptr );
238
- }
239
- }
240
- }
241
- if (rhs.isSSO ()) {
242
- setSSO (true );
243
- memmove_P (sso.buff , rhs.sso .buff , sizeof (sso.buff ));
244
- } else {
245
- setSSO (false );
246
- setBuffer (rhs.wbuffer ());
247
- }
248
- setCapacity (rhs.capacity ());
249
- setLen (rhs.len ());
250
- rhs.setSSO (false );
251
- rhs.setCapacity (0 );
252
- rhs.setLen (0 );
253
- rhs.setBuffer (nullptr );
213
+ void String::move (String &rhs) noexcept {
214
+ invalidate ();
215
+ sso = rhs.sso ;
216
+ rhs.init ();
254
217
}
255
- #endif
256
218
257
219
String & String::operator =(const String &rhs) {
258
220
if (this == &rhs)
@@ -266,19 +228,17 @@ String & String::operator =(const String &rhs) {
266
228
return *this ;
267
229
}
268
230
269
- #ifdef __GXX_EXPERIMENTAL_CXX0X__
270
- String & String::operator =(String &&rval) {
231
+ String & String::operator =(String &&rval) noexcept {
271
232
if (this != &rval)
272
233
move (rval);
273
234
return *this ;
274
235
}
275
236
276
- String & String::operator =(StringSumHelper &&rval) {
237
+ String & String::operator =(StringSumHelper &&rval) noexcept {
277
238
if (this != &rval)
278
239
move (rval);
279
240
return *this ;
280
241
}
281
- #endif
282
242
283
243
String & String::operator =(const char *cstr) {
284
244
if (cstr)
@@ -297,9 +257,9 @@ String & String::operator = (const __FlashStringHelper *pstr)
297
257
return *this ;
298
258
}
299
259
300
- // / *********************************************/
301
- // / * concat */
302
- // / *********************************************/
260
+ /* ********************************************/
261
+ /* concat */
262
+ /* ********************************************/
303
263
304
264
unsigned char String::concat (const String &s) {
305
265
// Special case if we're concatting ourself (s += s;) since we may end up
@@ -483,9 +443,9 @@ StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHel
483
443
return a;
484
444
}
485
445
486
- // / *********************************************/
487
- // / * Comparison */
488
- // / *********************************************/
446
+ /* ********************************************/
447
+ /* Comparison */
448
+ /* ********************************************/
489
449
490
450
int String::compareTo (const String &s) const {
491
451
if (!buffer () || !s.buffer ()) {
@@ -587,13 +547,9 @@ unsigned char String::endsWith(const String &s2) const {
587
547
return strcmp (&buffer ()[len () - s2.len ()], s2.buffer ()) == 0 ;
588
548
}
589
549
590
- // /*********************************************/
591
- // /* Character Access */
592
- // /*********************************************/
593
-
594
- char String::charAt (unsigned int loc) const {
595
- return operator [](loc);
596
- }
550
+ /* ********************************************/
551
+ /* Character Access */
552
+ /* ********************************************/
597
553
598
554
void String::setCharAt (unsigned int loc, char c) {
599
555
if (loc < len ())
@@ -629,9 +585,9 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind
629
585
buf[n] = 0 ;
630
586
}
631
587
632
- // / *********************************************/
633
- // / * Search */
634
- // / *********************************************/
588
+ /* ********************************************/
589
+ /* Search */
590
+ /* ********************************************/
635
591
636
592
int String::indexOf (char c) const {
637
593
return indexOf (c, 0 );
@@ -713,9 +669,9 @@ String String::substring(unsigned int left, unsigned int right) const {
713
669
return out;
714
670
}
715
671
716
- // / *********************************************/
717
- // / * Modification */
718
- // / *********************************************/
672
+ /* ********************************************/
673
+ /* Modification */
674
+ /* ********************************************/
719
675
720
676
void String::replace (char find, char replace) {
721
677
if (!buffer ())
@@ -828,9 +784,9 @@ void String::trim(void) {
828
784
wbuffer ()[newlen] = 0 ;
829
785
}
830
786
831
- // / *********************************************/
832
- // / * Parsing / Conversion */
833
- // / *********************************************/
787
+ /* ********************************************/
788
+ /* Parsing / Conversion */
789
+ /* ********************************************/
834
790
835
791
long String::toInt (void ) const {
836
792
if (buffer ())
0 commit comments