File tree 4 files changed +56
-32
lines changed
Filter options
4 files changed +56
-32
lines changed
Original file line number Diff line number Diff line change @@ -65,14 +65,13 @@ String::String(const __FlashStringHelper *pstr)
65
65
66
66
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
67
67
String::String (String &&rval)
68
+ : buffer(rval.buffer)
69
+ , capacity(rval.capacity)
70
+ , len(rval.len)
68
71
{
69
- init ();
70
- move (rval);
71
- }
72
- String::String (StringSumHelper &&rval)
73
- {
74
- init ();
75
- move (rval);
72
+ rval.buffer = NULL ;
73
+ rval.capacity = 0 ;
74
+ rval.len = 0 ;
76
75
}
77
76
#endif
78
77
@@ -217,23 +216,18 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
217
216
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
218
217
void String::move (String &rhs)
219
218
{
220
- if (buffer) {
221
- if (rhs && capacity >= rhs.len ) {
222
- memcpy (buffer, rhs.buffer , rhs.len );
223
- len = rhs.len ;
224
- buffer[len] = ' \0 ' ;
225
- rhs.len = 0 ;
226
- return ;
227
- } else {
228
- free (buffer);
229
- }
219
+ if (this != &rhs)
220
+ {
221
+ free (buffer);
222
+
223
+ buffer = rhs.buffer ;
224
+ len = rhs.len ;
225
+ capacity = rhs.capacity ;
226
+
227
+ rhs.buffer = NULL ;
228
+ rhs.len = 0 ;
229
+ rhs.capacity = 0 ;
230
230
}
231
- buffer = rhs.buffer ;
232
- capacity = rhs.capacity ;
233
- len = rhs.len ;
234
- rhs.buffer = NULL ;
235
- rhs.capacity = 0 ;
236
- rhs.len = 0 ;
237
231
}
238
232
#endif
239
233
@@ -250,13 +244,7 @@ String & String::operator = (const String &rhs)
250
244
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
251
245
String & String::operator = (String &&rval)
252
246
{
253
- if (this != &rval) move (rval);
254
- return *this ;
255
- }
256
-
257
- String & String::operator = (StringSumHelper &&rval)
258
- {
259
- if (this != &rval) move (rval);
247
+ move (rval);
260
248
return *this ;
261
249
}
262
250
#endif
Original file line number Diff line number Diff line change @@ -74,7 +74,6 @@ class String
74
74
String (const __FlashStringHelper *str);
75
75
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
76
76
String (String &&rval);
77
- String (StringSumHelper &&rval);
78
77
#endif
79
78
explicit String (char c);
80
79
explicit String (unsigned char , unsigned char base=10 );
@@ -101,7 +100,6 @@ class String
101
100
String & operator = (const __FlashStringHelper *str);
102
101
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
103
102
String & operator = (String &&rval);
104
- String & operator = (StringSumHelper &&rval);
105
103
#endif
106
104
107
105
// concatenate (works w/ built-in types)
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ set(TEST_SRCS
66
66
src/String /test_indexOf.cpp
67
67
src/String /test_lastIndexOf.cpp
68
68
src/String /test_length.cpp
69
+ src/String /test_move.cpp
69
70
src/String /test_remove.cpp
70
71
src/String /test_replace.cpp
71
72
src/String /test_String.cpp
Original file line number Diff line number Diff line change
1
+ #include < catch.hpp>
2
+
3
+ #include < String.h>
4
+
5
+ #include " StringPrinter.h"
6
+
7
+ #include < utility>
8
+
9
+ TEST_CASE (" Testing String move constructor" , " [String-move-01]" )
10
+ {
11
+ arduino::String a (" src" );
12
+ char const * const a_str = a.c_str ();
13
+ arduino::String b (std::move (a));
14
+ REQUIRE (a.length () == 0 );
15
+ REQUIRE (a.c_str () == nullptr );
16
+ REQUIRE (b.c_str () == a_str);
17
+ REQUIRE (b.length () == 3 );
18
+ }
19
+
20
+ TEST_CASE (" Testing String move assignment" , " [String-move-02]" )
21
+ {
22
+ arduino::String a (" src" );
23
+ char const * const a_str = a.c_str ();
24
+ arduino::String b;
25
+ b = std::move (a);
26
+ REQUIRE (a.length () == 0 );
27
+ REQUIRE (a.c_str () == nullptr );
28
+ REQUIRE (b == arduino::String (" src" ));
29
+ REQUIRE (b.c_str () == a_str);
30
+ }
31
+
32
+ TEST_CASE (" Testing String move self assignment" , " [String-move-03]" )
33
+ {
34
+ arduino::String a (" src" );
35
+ a = std::move (a);
36
+ REQUIRE (a == " src" );
37
+ }
You can’t perform that action at this time.
0 commit comments