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_cesu8_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_cesu8_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_cesu8_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_cesu8_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
+ && lit_cesu8_peek_next (&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
+ lit_cesu8_incr (&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
+ && lit_cesu8_peek_next (&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
+ lit_cesu8_incr (&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
+ && lit_cesu8_peek_next (&date_str_curr_p ) == ' T' )
257
253
{
254
+ /* eat up 'T' */
255
+ lit_cesu8_incr (&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
+ lit_cesu8_incr (&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
+ && lit_cesu8_peek_next (&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
+ lit_cesu8_incr (&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
+ && lit_cesu8_peek_next (&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
+ lit_cesu8_incr (&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,35 @@ 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
+ && lit_cesu8_peek_next (&date_str_curr_p ) == ' Z'
329
327
&& !ecma_number_is_nan (time))
330
328
{
331
- lit_utf8_iterator_incr (&iter );
329
+ lit_cesu8_incr (&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
+ && (lit_cesu8_peek_next (&date_str_curr_p ) == ' +'
334
+ || lit_cesu8_peek_next (&date_str_curr_p ) == ' -' ))
337
335
{
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 ;
336
+ ecma_length_t remaining_length;
337
+ remaining_length = lit_utf8_string_length (date_str_curr_p,
338
+ (lit_utf8_size_t ) (date_str_end_p - date_str_curr_p)) - 1 ;
340
339
341
- if ((date_str_len - num_of_visited_chars) == 5 )
340
+ if (remaining_length == 5 )
342
341
{
343
342
bool is_negative = false ;
344
343
345
- if (lit_utf8_iterator_peek_next (&iter ) == ' -' )
344
+ if (lit_cesu8_peek_next (&date_str_curr_p ) == ' -' )
346
345
{
347
346
is_negative = true ;
348
347
}
349
348
350
349
/* eat up '+/-' */
351
- lit_utf8_iterator_incr (&iter );
350
+ lit_cesu8_incr (&date_str_curr_p );
352
351
353
352
/* read hours and minutes */
354
- hours = ecma_date_parse_date_chars (&iter , 2 );
353
+ hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
355
354
356
355
if (hours < 0 || hours > 24 )
357
356
{
@@ -363,9 +362,9 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
363
362
}
364
363
365
364
/* eat up ':' */
366
- lit_utf8_iterator_incr (&iter );
365
+ lit_cesu8_incr (&date_str_curr_p );
367
366
368
- minutes = ecma_date_parse_date_chars (&iter , 2 );
367
+ minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p , 2 );
369
368
370
369
if (minutes < 0 || minutes > 59 )
371
370
{
@@ -384,7 +383,7 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
384
383
}
385
384
}
386
385
387
- if (lit_utf8_iterator_is_eos (&iter) )
386
+ if (date_str_curr_p >= date_str_end_p )
388
387
{
389
388
ecma_number_t date = ecma_date_make_day (year, month - 1 , day);
390
389
*date_num_p = ecma_date_make_date (date, time);
0 commit comments