@@ -16,8 +16,9 @@ extern "C"
16
16
{
17
17
if (v->type == ValueType::String) {
18
18
assert (v->stringValue );
19
- delete v->stringValue ;
19
+ free ( v->stringValue ) ;
20
20
v->stringValue = nullptr ;
21
+ v->stringSize = 0 ;
21
22
}
22
23
}
23
24
@@ -105,32 +106,29 @@ extern "C"
105
106
/* ! Assigns string to the given value. */
106
107
void value_assign_string (ValueData *v, const std::string &stringValue)
107
108
{
108
- if (stringValue == " Infinity" ) {
109
+ value_assign_cstring (v, stringValue.c_str ());
110
+ }
111
+
112
+ /* ! Assigns C string to the given value. */
113
+ void value_assign_cstring (ValueData *v, const char *stringValue)
114
+ {
115
+ if (strcmp (stringValue, " Infinity" ) == 0 ) {
109
116
value_free (v);
110
117
v->type = ValueType::Infinity;
111
- } else if (stringValue == " -Infinity" ) {
118
+ } else if (strcmp ( stringValue, " -Infinity" ) == 0 ) {
112
119
value_free (v);
113
120
v->type = ValueType::NegativeInfinity;
114
- } else if (stringValue == " NaN" ) {
121
+ } else if (strcmp ( stringValue, " NaN" ) == 0 ) {
115
122
value_free (v);
116
123
v->type = ValueType::NaN;
124
+ } else if (v->type == ValueType::String) {
125
+ value_replaceStr (v, stringValue);
117
126
} else {
118
- if (v->type == ValueType::String)
119
- v->stringValue ->assign (stringValue);
120
- else {
121
- value_free (v);
122
- v->type = ValueType::String;
123
- v->stringValue = new std::string (stringValue);
124
- }
127
+ value_free (v);
128
+ value_initStr (v, stringValue);
125
129
}
126
130
}
127
131
128
- /* ! Assigns C string to the given value. */
129
- void value_assign_cstring (ValueData *v, const char *stringValue)
130
- {
131
- value_assign_string (v, std::string (stringValue));
132
- }
133
-
134
132
/* ! Assigns special value to the given value. */
135
133
void value_assign_special (ValueData *v, SpecialValue specialValue)
136
134
{
@@ -162,10 +160,10 @@ extern "C"
162
160
v->boolValue = another->boolValue ;
163
161
} else if (another->type == ValueType::String) {
164
162
if (v->type == ValueType::String)
165
- v-> stringValue -> assign (* another->stringValue );
163
+ value_replaceStr (v, another->stringValue );
166
164
else {
167
165
value_free (v);
168
- v-> stringValue = new std::string (* another->stringValue );
166
+ value_initStr (v, another->stringValue );
169
167
}
170
168
}
171
169
@@ -185,7 +183,7 @@ extern "C"
185
183
case ValueType::Double:
186
184
return value_isInf (v->doubleValue );
187
185
case ValueType::String:
188
- return * v->stringValue == " Infinity" ;
186
+ return strcmp ( v->stringValue , " Infinity" ) == 0 ;
189
187
default :
190
188
return false ;
191
189
}
@@ -202,7 +200,7 @@ extern "C"
202
200
case ValueType::Double:
203
201
return value_isNegativeInf (-v->doubleValue );
204
202
case ValueType::String:
205
- return * v->stringValue == " -Infinity" ;
203
+ return strcmp ( v->stringValue , " -Infinity" ) == 0 ;
206
204
default :
207
205
return false ;
208
206
}
@@ -218,7 +216,7 @@ extern "C"
218
216
assert (!std::isnan (v->doubleValue ));
219
217
return std::isnan (v->doubleValue );
220
218
case ValueType::String:
221
- return * v->stringValue == " NaN" ;
219
+ return strcmp ( v->stringValue , " NaN" ) == 0 ;
222
220
default :
223
221
return false ;
224
222
}
@@ -247,7 +245,7 @@ extern "C"
247
245
case ValueType::Bool:
248
246
return true ;
249
247
case ValueType::String:
250
- return v->stringValue -> empty () || value_checkString (* v->stringValue ) > 0 ;
248
+ return strlen ( v->stringValue ) == 0 || value_checkString (v->stringValue ) > 0 ;
251
249
default :
252
250
return false ;
253
251
}
@@ -270,7 +268,7 @@ extern "C"
270
268
return v->doubleValue == intpart;
271
269
}
272
270
case ValueType::String:
273
- return value_checkString (* v->stringValue ) == 1 ;
271
+ return value_checkString (v->stringValue ) == 1 ;
274
272
}
275
273
276
274
return false ;
@@ -300,7 +298,7 @@ extern "C"
300
298
else if (v->type == ValueType::Bool)
301
299
return v->boolValue ;
302
300
else if (v->type == ValueType::String)
303
- return value_stringToLong (* v->stringValue );
301
+ return value_stringToLong (v->stringValue );
304
302
else
305
303
return 0 ;
306
304
}
@@ -315,7 +313,7 @@ extern "C"
315
313
else if (v->type == ValueType::Bool)
316
314
return v->boolValue ;
317
315
else if (v->type == ValueType::String)
318
- return value_stringToLong (* v->stringValue );
316
+ return value_stringToLong (v->stringValue );
319
317
else
320
318
return 0 ;
321
319
}
@@ -330,7 +328,7 @@ extern "C"
330
328
else if (v->type == ValueType::Bool)
331
329
return v->boolValue ;
332
330
else if (v->type == ValueType::String)
333
- return value_stringToDouble (* v->stringValue );
331
+ return value_stringToDouble (v->stringValue );
334
332
else if (v->type == ValueType::Infinity)
335
333
return std::numeric_limits<double >::infinity ();
336
334
else if (v->type == ValueType::NegativeInfinity)
@@ -349,7 +347,7 @@ extern "C"
349
347
} else if (v->type == ValueType::Double) {
350
348
return v->doubleValue != 0 ;
351
349
} else if (v->type == ValueType::String) {
352
- return ! v->stringValue -> empty () && !value_stringsEqual (* v->stringValue , " false" ) && * v->stringValue != " 0 " ;
350
+ return strlen ( v->stringValue ) != 0 && !value_stringsEqual (v->stringValue , " false" ) && strcmp ( v->stringValue , " 0 " ) != 0 ;
353
351
} else if (v->type == ValueType::Infinity || v->type == ValueType::NegativeInfinity) {
354
352
return true ;
355
353
} else if (v->type == ValueType::NaN) {
@@ -363,7 +361,7 @@ extern "C"
363
361
void value_toString (const libscratchcpp::ValueData *v, std::string *dst)
364
362
{
365
363
if (v->type == ValueType::String)
366
- dst->assign (* v->stringValue );
364
+ dst->assign (v->stringValue );
367
365
else if (v->type == ValueType::Integer)
368
366
dst->assign (std::to_string (v->intValue ));
369
367
else if (v->type == ValueType::Double)
@@ -590,12 +588,12 @@ extern "C"
590
588
double n1, n2;
591
589
592
590
if (v1->type == ValueType::String)
593
- n1 = value_stringToDouble (* v1->stringValue );
591
+ n1 = value_stringToDouble (v1->stringValue );
594
592
else
595
593
n1 = value_toDouble (v1);
596
594
597
595
if (v2->type == ValueType::String)
598
- n2 = value_stringToDouble (* v2->stringValue );
596
+ n2 = value_stringToDouble (v2->stringValue );
599
597
else
600
598
n2 = value_toDouble (v2);
601
599
@@ -628,12 +626,12 @@ extern "C"
628
626
double n1, n2;
629
627
630
628
if (v1->type == ValueType::String)
631
- n1 = value_stringToDouble (* v1->stringValue );
629
+ n1 = value_stringToDouble (v1->stringValue );
632
630
else
633
631
n1 = value_toDouble (v1);
634
632
635
633
if (v2->type == ValueType::String)
636
- n2 = value_stringToDouble (* v2->stringValue );
634
+ n2 = value_stringToDouble (v2->stringValue );
637
635
else
638
636
n2 = value_toDouble (v2);
639
637
0 commit comments