@@ -1115,28 +1115,27 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1115
1115
}
1116
1116
else
1117
1117
{
1118
- ecma_length_t string_len = ecma_string_get_length (space_str_p);
1118
+ ecma_length_t string_size = ecma_string_get_size (space_str_p);
1119
1119
1120
- MEM_DEFINE_LOCAL_ARRAY (zt_string_buff, string_len , lit_utf8_byte_t );
1120
+ MEM_DEFINE_LOCAL_ARRAY (string_buff, string_size , lit_utf8_byte_t );
1121
1121
1122
- size_t string_buf_size = (size_t ) (string_len) * sizeof (lit_utf8_byte_t );
1123
1122
ssize_t bytes_copied = ecma_string_to_utf8_string (space_str_p,
1124
- zt_string_buff ,
1125
- (ssize_t ) string_buf_size );
1123
+ string_buff ,
1124
+ (ssize_t ) string_size );
1126
1125
JERRY_ASSERT (bytes_copied > 0 );
1127
1126
1128
- /* Buffer for the first 10 characters. */
1129
- MEM_DEFINE_LOCAL_ARRAY (space_buff , 10 , lit_utf8_byte_t );
1127
+ lit_utf8_iterator_t iter = lit_utf8_iterator_create (string_buff, string_size);
1128
+ lit_utf8_iterator_advance (&iter , 10 );
1130
1129
1131
- for ( uint32_t i = 0 ; i < 10 ; i++)
1132
- {
1133
- space_buff[i] = zt_string_buff[i] ;
1134
- }
1130
+ uint32_t space_buff_size = iter. buf_pos . offset ;
1131
+ /* Buffer for the first 10 characters. */
1132
+ MEM_DEFINE_LOCAL_ARRAY ( space_buff, space_buff_size, lit_utf8_byte_t ) ;
1133
+ memcpy (space_buff, string_buff, space_buff_size);
1135
1134
1136
- context_p.gap_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) space_buff, 10 );
1135
+ context_p.gap_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) space_buff, space_buff_size );
1137
1136
1138
1137
MEM_FINALIZE_LOCAL_ARRAY (space_buff);
1139
- MEM_FINALIZE_LOCAL_ARRAY (zt_string_buff );
1138
+ MEM_FINALIZE_LOCAL_ARRAY (string_buff );
1140
1139
}
1141
1140
}
1142
1141
/* 8. */
@@ -1198,23 +1197,24 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1198
1197
ecma_string_t *product_str_p = ecma_copy_or_ref_ecma_string (quote_str_p);
1199
1198
ecma_string_t *tmp_str_p;
1200
1199
1201
- ecma_length_t string_len = ecma_string_get_length (string_p);
1200
+ ecma_length_t string_size = ecma_string_get_size (string_p);
1202
1201
1203
- MEM_DEFINE_LOCAL_ARRAY (zt_string_buff, string_len , lit_utf8_byte_t );
1202
+ MEM_DEFINE_LOCAL_ARRAY (string_buff, string_size , lit_utf8_byte_t );
1204
1203
1205
- size_t string_buf_size = (size_t ) (string_len) * sizeof (lit_utf8_byte_t );
1206
1204
ssize_t bytes_copied = ecma_string_to_utf8_string (string_p,
1207
- zt_string_buff,
1208
- (ssize_t ) string_buf_size);
1209
- JERRY_ASSERT (bytes_copied > 0 || !string_len);
1205
+ string_buff,
1206
+ (ssize_t ) string_size);
1210
1207
1211
- /* 2. */
1212
- for (ecma_length_t i = 0 ; i < string_len; i++)
1208
+ JERRY_ASSERT (bytes_copied > 0 || !string_size);
1209
+
1210
+ lit_utf8_iterator_t iter = lit_utf8_iterator_create (string_buff, string_size);
1211
+
1212
+ while (!lit_utf8_iterator_is_eos (&iter))
1213
1213
{
1214
- lit_utf8_byte_t c = zt_string_buff[i] ;
1214
+ ecma_char_t current_char = lit_utf8_iterator_read_next (&iter) ;
1215
1215
1216
1216
/* 2.a */
1217
- if (c == LIT_CHAR_BACKSLASH || c == LIT_CHAR_DOUBLE_QUOTE)
1217
+ if (current_char == LIT_CHAR_BACKSLASH || current_char == LIT_CHAR_DOUBLE_QUOTE)
1218
1218
{
1219
1219
ecma_string_t *backslash_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_BACKSLASH_CHAR);
1220
1220
@@ -1225,16 +1225,19 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1225
1225
product_str_p = tmp_str_p;
1226
1226
1227
1227
/* 2.a.ii */
1228
- ecma_string_t *c_str_p = ecma_new_ecma_string_from_utf8 (&c, 1 );
1228
+ ecma_string_t *current_char_str_p = ecma_new_ecma_string_from_code_unit (current_char );
1229
1229
1230
- tmp_str_p = ecma_concat_ecma_strings (product_str_p, c_str_p );
1230
+ tmp_str_p = ecma_concat_ecma_strings (product_str_p, current_char_str_p );
1231
1231
ecma_deref_ecma_string (product_str_p);
1232
- ecma_deref_ecma_string (c_str_p );
1232
+ ecma_deref_ecma_string (current_char_str_p );
1233
1233
product_str_p = tmp_str_p;
1234
1234
}
1235
1235
/* 2.b */
1236
- else if (c == LIT_CHAR_BS || c == LIT_CHAR_FF || c == LIT_CHAR_LF
1237
- || c == LIT_CHAR_CR || c == LIT_CHAR_TAB)
1236
+ else if (current_char == LIT_CHAR_BS
1237
+ || current_char == LIT_CHAR_FF
1238
+ || current_char == LIT_CHAR_LF
1239
+ || current_char == LIT_CHAR_CR
1240
+ || current_char == LIT_CHAR_TAB)
1238
1241
{
1239
1242
ecma_string_t *backslash_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_BACKSLASH_CHAR);
1240
1243
@@ -1247,7 +1250,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1247
1250
/* 2.b.ii */
1248
1251
lit_utf8_byte_t abbrev = LIT_CHAR_SP;
1249
1252
1250
- switch (c )
1253
+ switch (current_char )
1251
1254
{
1252
1255
case LIT_CHAR_BS:
1253
1256
{
@@ -1285,7 +1288,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1285
1288
product_str_p = tmp_str_p;
1286
1289
}
1287
1290
/* 2.c */
1288
- else if (c < LIT_CHAR_SP)
1291
+ else if (current_char < LIT_CHAR_SP)
1289
1292
{
1290
1293
ecma_string_t *backslash_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_BACKSLASH_CHAR);
1291
1294
@@ -1305,7 +1308,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1305
1308
product_str_p = tmp_str_p;
1306
1309
1307
1310
/* 2.c.iii */
1308
- ecma_string_t *hex_str_p = ecma_builtin_helper_json_create_hex_digit_ecma_string (c );
1311
+ ecma_string_t *hex_str_p = ecma_builtin_helper_json_create_hex_digit_ecma_string (( uint8_t ) current_char );
1309
1312
1310
1313
/* 2.c.iv */
1311
1314
tmp_str_p = ecma_concat_ecma_strings (product_str_p, hex_str_p);
@@ -1316,16 +1319,16 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1316
1319
/* 2.d */
1317
1320
else
1318
1321
{
1319
- ecma_string_t *c_str_p = ecma_new_ecma_string_from_utf8 (&c, 1 );
1322
+ ecma_string_t *current_char_str_p = ecma_new_ecma_string_from_code_unit (current_char );
1320
1323
1321
- tmp_str_p = ecma_concat_ecma_strings (product_str_p, c_str_p );
1324
+ tmp_str_p = ecma_concat_ecma_strings (product_str_p, current_char_str_p );
1322
1325
ecma_deref_ecma_string (product_str_p);
1323
- ecma_deref_ecma_string (c_str_p );
1326
+ ecma_deref_ecma_string (current_char_str_p );
1324
1327
product_str_p = tmp_str_p;
1325
1328
}
1326
1329
}
1327
1330
1328
- MEM_FINALIZE_LOCAL_ARRAY (zt_string_buff );
1331
+ MEM_FINALIZE_LOCAL_ARRAY (string_buff );
1329
1332
1330
1333
/* 3. */
1331
1334
tmp_str_p = ecma_concat_ecma_strings (product_str_p, quote_str_p);
0 commit comments