48
48
* @return NaN if cannot read from string, ToNumber() otherwise
49
49
*/
50
50
static ecma_number_t
51
- ecma_date_parse_date_chars (lit_utf8_iterator_t *iter, /* *< iterator of the utf8 string */
51
+ ecma_date_parse_date_chars (lit_utf8_byte_t **str_p, /* *< pointer to the cesu8 string */
52
+ const lit_utf8_byte_t *str_end_p, /* *< pointer to the end of the string */
52
53
uint32_t num_of_chars) /* *< number of characters to read and convert */
53
54
{
54
55
JERRY_ASSERT (num_of_chars > 0 );
55
-
56
- lit_utf8_size_t copy_size = 0 ;
57
- const lit_utf8_byte_t *str_start_p = iter->buf_p + iter->buf_pos .offset ;
56
+ const lit_utf8_byte_t *str_start_p = *str_p;
58
57
59
58
while (num_of_chars--)
60
59
{
61
- if (lit_utf8_iterator_is_eos (iter)
62
- || !lit_char_is_decimal_digit (lit_utf8_iterator_peek_next (iter)))
60
+ if (*str_p >= str_end_p || !lit_char_is_decimal_digit (lit_utf8_read_next (str_p)))
63
61
{
64
62
return ecma_number_make_nan ();
65
63
}
66
-
67
- copy_size += lit_get_unicode_char_size_by_utf8_first_byte (*(iter->buf_p + iter->buf_pos .offset ));
68
- lit_utf8_iterator_incr (iter);
69
64
}
70
65
71
- return ecma_utf8_string_to_number (str_start_p, copy_size );
66
+ return ecma_utf8_string_to_number (str_start_p, ( lit_utf8_size_t ) (*str_p - str_start_p) );
72
67
} /* ecma_date_parse_date_chars */
73
68
74
69
/* *
@@ -211,10 +206,11 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
211
206
ssize_t sz = ecma_string_to_utf8_string (date_str_p, date_start_p, (ssize_t ) date_str_size);
212
207
JERRY_ASSERT (sz >= 0 );
213
208
214
- lit_utf8_iterator_t iter = lit_utf8_iterator_create (date_start_p, date_str_size);
209
+ lit_utf8_byte_t *date_str_curr_p = date_start_p;
210
+ const lit_utf8_byte_t *date_str_end_p = date_start_p + date_str_size;
215
211
216
212
/* 1. read year */
217
- ecma_number_t year = ecma_date_parse_date_chars (&iter , 4 );
213
+ ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 4 );
218
214
219
215
if (!ecma_number_is_nan (year)
220
216
&& year >= 0 )
@@ -224,12 +220,12 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
224
220
ecma_number_t time = ECMA_NUMBER_ZERO;
225
221
226
222
/* 2. read month if any */
227
- if (! lit_utf8_iterator_is_eos (&iter)
228
- && lit_utf8_iterator_peek_next (&iter) == ' -' )
223
+ if (date_str_curr_p < date_str_end_p
224
+ && *date_str_curr_p == ' -' )
229
225
{
230
226
/* eat up '-' */
231
- lit_utf8_iterator_incr (&iter) ;
232
- month = ecma_date_parse_date_chars (&iter , 2 );
227
+ date_str_curr_p++ ;
228
+ month = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
233
229
234
230
if (month > 12 || month < 1 )
235
231
{
@@ -238,12 +234,12 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
238
234
}
239
235
240
236
/* 3. read day if any */
241
- if (! lit_utf8_iterator_is_eos (&iter)
242
- && lit_utf8_iterator_peek_next (&iter) == ' -' )
237
+ if (date_str_curr_p < date_str_end_p
238
+ && *date_str_curr_p == ' -' )
243
239
{
244
240
/* eat up '-' */
245
- lit_utf8_iterator_incr (&iter) ;
246
- day = ecma_date_parse_date_chars (&iter , 2 );
241
+ date_str_curr_p++ ;
242
+ day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
247
243
248
244
if (day < 1 || day > 31 )
249
245
{
@@ -252,24 +248,24 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
252
248
}
253
249
254
250
/* 4. read time if any */
255
- if (! lit_utf8_iterator_is_eos (&iter)
256
- && lit_utf8_iterator_peek_next (&iter) == ' T' )
251
+ if (date_str_curr_p < date_str_end_p
252
+ && *date_str_curr_p == ' T' )
257
253
{
254
+ /* eat up 'T' */
255
+ date_str_curr_p++;
256
+
258
257
ecma_number_t hours = ECMA_NUMBER_ZERO;
259
258
ecma_number_t minutes = ECMA_NUMBER_ZERO;
260
259
ecma_number_t seconds = ECMA_NUMBER_ZERO;
261
260
ecma_number_t milliseconds = ECMA_NUMBER_ZERO;
262
261
263
- ecma_length_t num_of_visited_chars = lit_utf8_iterator_get_index (&iter);
264
- ecma_length_t date_str_len = lit_utf8_string_length (iter. buf_p , iter. buf_size ) - 1 ;
262
+ ecma_length_t remaining_length = lit_utf8_string_length (date_str_curr_p,
263
+ ( lit_utf8_size_t ) (date_str_end_p - date_str_curr_p)) ;
265
264
266
- if ((date_str_len - num_of_visited_chars) >= 5 )
265
+ if (remaining_length >= 5 )
267
266
{
268
- /* eat up 'T' */
269
- lit_utf8_iterator_incr (&iter);
270
-
271
267
/* 4.1 read hours and minutes */
272
- hours = ecma_date_parse_date_chars (&iter , 2 );
268
+ hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
273
269
274
270
if (hours < 0 || hours > 24 )
275
271
{
@@ -281,33 +277,35 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
281
277
}
282
278
283
279
/* eat up ':' */
284
- lit_utf8_iterator_incr (&iter) ;
280
+ date_str_curr_p++ ;
285
281
286
- minutes = ecma_date_parse_date_chars (&iter , 2 );
282
+ minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
287
283
288
284
if (minutes < 0 || minutes > 59 )
289
285
{
290
286
minutes = ecma_number_make_nan ();
291
287
}
292
288
293
289
/* 4.2 read seconds if any */
294
- if (!lit_utf8_iterator_is_eos (&iter) && lit_utf8_iterator_peek_next (&iter) == ' :' )
290
+ if (date_str_curr_p < date_str_end_p
291
+ && *date_str_curr_p == ' :' )
295
292
{
296
293
/* eat up ':' */
297
- lit_utf8_iterator_incr (&iter) ;
298
- seconds = ecma_date_parse_date_chars (&iter , 2 );
294
+ date_str_curr_p++ ;
295
+ seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
299
296
300
297
if (seconds < 0 || seconds > 59 )
301
298
{
302
299
seconds = ecma_number_make_nan ();
303
300
}
304
301
305
302
/* 4.3 read milliseconds if any */
306
- if (!lit_utf8_iterator_is_eos (&iter) && lit_utf8_iterator_peek_next (&iter) == ' .' )
303
+ if (date_str_curr_p < date_str_end_p
304
+ && *date_str_curr_p == ' .' )
307
305
{
308
306
/* eat up '.' */
309
- lit_utf8_iterator_incr (&iter) ;
310
- milliseconds = ecma_date_parse_date_chars (&iter , 3 );
307
+ date_str_curr_p++ ;
308
+ milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 3 );
311
309
312
310
if (milliseconds < 0 )
313
311
{
@@ -324,34 +322,34 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
324
322
}
325
323
326
324
/* 4.4 read timezone if any */
327
- if (! lit_utf8_iterator_is_eos (&iter)
328
- && lit_utf8_iterator_peek_next (&iter) == ' Z'
325
+ if (date_str_curr_p < date_str_end_p
326
+ && *date_str_curr_p == ' Z'
329
327
&& !ecma_number_is_nan (time))
330
328
{
331
- lit_utf8_iterator_incr (&iter) ;
329
+ date_str_curr_p++ ;
332
330
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
333
331
}
334
- else if (!lit_utf8_iterator_is_eos (&iter)
335
- && (lit_utf8_iterator_peek_next (&iter) == ' +'
336
- || lit_utf8_iterator_peek_next (&iter) == ' -' ))
332
+ else if (date_str_curr_p < date_str_end_p
333
+ && (*date_str_curr_p == ' +' || *date_str_curr_p == ' -' ))
337
334
{
338
- ecma_length_t num_of_visited_chars = lit_utf8_iterator_get_index (&iter);
339
- ecma_length_t date_str_len = lit_utf8_string_length (iter.buf_p , iter.buf_size ) - 1 ;
335
+ ecma_length_t remaining_length;
336
+ remaining_length = lit_utf8_string_length (date_str_curr_p,
337
+ (lit_utf8_size_t ) (date_str_end_p - date_str_curr_p)) - 1 ;
340
338
341
- if ((date_str_len - num_of_visited_chars) == 5 )
339
+ if (remaining_length == 5 )
342
340
{
343
341
bool is_negative = false ;
344
342
345
- if (lit_utf8_iterator_peek_next (&iter) == ' -' )
343
+ if (*date_str_curr_p == ' -' )
346
344
{
347
345
is_negative = true ;
348
346
}
349
347
350
348
/* eat up '+/-' */
351
- lit_utf8_iterator_incr (&iter) ;
349
+ date_str_curr_p++ ;
352
350
353
351
/* read hours and minutes */
354
- hours = ecma_date_parse_date_chars (&iter , 2 );
352
+ hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
355
353
356
354
if (hours < 0 || hours > 24 )
357
355
{
@@ -363,9 +361,9 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
363
361
}
364
362
365
363
/* eat up ':' */
366
- lit_utf8_iterator_incr (&iter) ;
364
+ date_str_curr_p++ ;
367
365
368
- minutes = ecma_date_parse_date_chars (&iter , 2 );
366
+ minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
369
367
370
368
if (minutes < 0 || minutes > 59 )
371
369
{
@@ -384,7 +382,7 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
384
382
}
385
383
}
386
384
387
- if (lit_utf8_iterator_is_eos (&iter) )
385
+ if (date_str_curr_p >= date_str_end_p )
388
386
{
389
387
ecma_number_t date = ecma_date_make_day (year, month - 1 , day);
390
388
*date_num_p = ecma_date_make_date (date, time);
0 commit comments