|
19 | 19 |
|
20 | 20 | JERRY_STATIC_ASSERT (sizeof (lit_utf8_iterator_pos_t) == sizeof (lit_utf8_size_t));
|
21 | 21 |
|
| 22 | +/** |
| 23 | + * Compare two iterator positions |
| 24 | + * |
| 25 | + * @return +1, if pos1 > pos2 |
| 26 | + * 0, if pos1 == pos2 |
| 27 | + * -1, otherwise |
| 28 | + */ |
| 29 | +int32_t |
| 30 | +lit_utf8_iterator_pos_cmp (lit_utf8_iterator_pos_t pos1, /**< first position of the iterator */ |
| 31 | + lit_utf8_iterator_pos_t pos2) /**< second position of the iterator */ |
| 32 | +{ |
| 33 | + if (pos1.offset < pos2.offset) |
| 34 | + { |
| 35 | + return -1; |
| 36 | + } |
| 37 | + else if (pos1.offset > pos2.offset) |
| 38 | + { |
| 39 | + return 1; |
| 40 | + } |
| 41 | + |
| 42 | + if (pos1.is_non_bmp_middle == false && pos2.is_non_bmp_middle == true) |
| 43 | + { |
| 44 | + return -1; |
| 45 | + } |
| 46 | + else if (pos1.is_non_bmp_middle == true && pos2.is_non_bmp_middle == false) |
| 47 | + { |
| 48 | + return 1; |
| 49 | + } |
| 50 | + |
| 51 | + return 0; |
| 52 | +} /* lit_utf8_iterator_pos_cmp */ |
| 53 | + |
22 | 54 | /**
|
23 | 55 | * Validate utf-8 string
|
24 | 56 | *
|
@@ -157,10 +189,7 @@ lit_utf8_iterator_create (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string *
|
157 | 189 | {
|
158 | 190 | utf8_buf_p,
|
159 | 191 | buf_size,
|
160 |
| - { |
161 |
| - 0, |
162 |
| - false |
163 |
| - } |
| 192 | + LIT_ITERATOR_POS_ZERO |
164 | 193 | };
|
165 | 194 |
|
166 | 195 | return buf_iter;
|
@@ -479,48 +508,6 @@ lit_utf8_iterator_is_bos (const lit_utf8_iterator_t *iter_p)
|
479 | 508 | return (iter_p->buf_pos.offset == 0 && iter_p->buf_pos.is_non_bmp_middle == false);
|
480 | 509 | } /* lit_utf8_iterator_is_bos */
|
481 | 510 |
|
482 |
| -/** |
483 |
| - * Get offset of the iterator |
484 |
| - * |
485 |
| - * @return: current offset in bytes of the iterator from the beginning of buffer |
486 |
| - */ |
487 |
| -lit_utf8_size_t |
488 |
| -lit_utf8_iterator_get_offset (const lit_utf8_iterator_t *iter_p) /**< iterator */ |
489 |
| -{ |
490 |
| - return iter_p->buf_pos.offset; |
491 |
| -} /* lit_utf8_iterator_get_offset */ |
492 |
| - |
493 |
| -/** |
494 |
| - * Set iterator to point to specified offset |
495 |
| - */ |
496 |
| -void |
497 |
| -lit_utf8_iterator_set_offset (lit_utf8_iterator_t *iter_p, /**< pointer to iterator */ |
498 |
| - lit_utf8_size_t offset) /**< offset from the begging of the iterated buffer */ |
499 |
| -{ |
500 |
| - JERRY_ASSERT (offset <= iter_p->buf_size); |
501 |
| - |
502 |
| -#ifndef JERRY_NDEBUG |
503 |
| - if (offset < iter_p->buf_size) |
504 |
| - { |
505 |
| - JERRY_ASSERT (((*(iter_p->buf_p + offset)) & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER); |
506 |
| - } |
507 |
| -#endif |
508 |
| - |
509 |
| - iter_p->buf_pos.offset = (offset) & LIT_ITERATOR_OFFSET_MASK; |
510 |
| - iter_p->buf_pos.is_non_bmp_middle = false; |
511 |
| -} /* lit_utf8_iterator_set_offset */ |
512 |
| - |
513 |
| -/** |
514 |
| - * Get pointer to the current utf-8 char which iterator points to |
515 |
| - * |
516 |
| - * @return: pointer to utf-8 char |
517 |
| - */ |
518 |
| -lit_utf8_byte_t * |
519 |
| -lit_utf8_iterator_get_ptr (const lit_utf8_iterator_t *iter_p) /**< iterator */ |
520 |
| -{ |
521 |
| - return (lit_utf8_byte_t *) iter_p->buf_p + iter_p->buf_pos.offset; |
522 |
| -} /* lit_utf8_iterator_get_ptr */ |
523 |
| - |
524 | 511 | /**
|
525 | 512 | * Calculate size of a zero-terminated utf-8 string
|
526 | 513 | *
|
|
0 commit comments