Skip to content

Commit 146ac15

Browse files
sand1kruben-ayrapetyan
authored andcommitted
Change locus type from size_t to lit_utf8_iterator_pos_t.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov [email protected]
1 parent 7dd1d01 commit 146ac15

File tree

7 files changed

+177
-139
lines changed

7 files changed

+177
-139
lines changed

jerry-core/lit/lit-strings.cpp

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,38 @@
1919

2020
JERRY_STATIC_ASSERT (sizeof (lit_utf8_iterator_pos_t) == sizeof (lit_utf8_size_t));
2121

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+
2254
/**
2355
* Validate utf-8 string
2456
*
@@ -157,10 +189,7 @@ lit_utf8_iterator_create (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string *
157189
{
158190
utf8_buf_p,
159191
buf_size,
160-
{
161-
0,
162-
false
163-
}
192+
LIT_ITERATOR_POS_ZERO
164193
};
165194

166195
return buf_iter;
@@ -479,48 +508,6 @@ lit_utf8_iterator_is_bos (const lit_utf8_iterator_t *iter_p)
479508
return (iter_p->buf_pos.offset == 0 && iter_p->buf_pos.is_non_bmp_middle == false);
480509
} /* lit_utf8_iterator_is_bos */
481510

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-
524511
/**
525512
* Calculate size of a zero-terminated utf-8 string
526513
*

jerry-core/lit/lit-strings.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ typedef struct
9898
* 4-byte char */
9999
} lit_utf8_iterator_pos_t;
100100

101+
/**
102+
* Value of an iterator, positioned to beginning of a string
103+
*/
104+
#define LIT_ITERATOR_POS_ZERO {0, false}
105+
101106
/**
102107
* Represents an iterator over utf-8 buffer
103108
*/
@@ -108,6 +113,8 @@ typedef struct
108113
lit_utf8_iterator_pos_t buf_pos; /* position in the buffer */
109114
} lit_utf8_iterator_t;
110115

116+
int32_t lit_utf8_iterator_pos_cmp (lit_utf8_iterator_pos_t, lit_utf8_iterator_pos_t);
117+
111118
/* validation */
112119
bool lit_is_utf8_string_valid (const lit_utf8_byte_t *, lit_utf8_size_t);
113120

@@ -139,11 +146,6 @@ ecma_char_t lit_utf8_iterator_read_prev (lit_utf8_iterator_t *);
139146
bool lit_utf8_iterator_is_eos (const lit_utf8_iterator_t *);
140147
bool lit_utf8_iterator_is_bos (const lit_utf8_iterator_t *);
141148

142-
lit_utf8_size_t lit_utf8_iterator_get_offset (const lit_utf8_iterator_t *);
143-
void lit_utf8_iterator_set_offset (lit_utf8_iterator_t *, lit_utf8_size_t);
144-
145-
lit_utf8_byte_t *lit_utf8_iterator_get_ptr (const lit_utf8_iterator_t *);
146-
147149
/* size */
148150
lit_utf8_size_t lit_zt_utf8_string_size (const lit_utf8_byte_t *);
149151

0 commit comments

Comments
 (0)