New trim helper function (#3014)
Created a new trim helper function which is used in every situation where we need to trim a string Co-authored-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
committed by
Dániel Bátyai
parent
fd075322fb
commit
97e348528a
@@ -111,31 +111,6 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
|
||||
return ecma_op_eval (ecma_get_string_from_value (x), parse_opts);
|
||||
} /* ecma_builtin_global_object_eval */
|
||||
|
||||
/**
|
||||
* Helper function for trimming leading whitespaces
|
||||
* for the Global object's 'parseInt' and 'parseFloat' routines
|
||||
*/
|
||||
static void
|
||||
ecma_builtin_global_remove_leading_white_spaces (const lit_utf8_byte_t **string_curr_p, /**< [in, out] current string
|
||||
* position */
|
||||
const lit_utf8_byte_t *string_end_p, /**< end of the string buffer */
|
||||
const lit_utf8_byte_t **start_p) /**< [in, out] start position of the
|
||||
* trimmed string */
|
||||
{
|
||||
while (*string_curr_p < string_end_p)
|
||||
{
|
||||
ecma_char_t current_char = lit_utf8_read_next (string_curr_p);
|
||||
|
||||
if (!lit_char_is_white_space (current_char)
|
||||
&& !lit_char_is_line_terminator (current_char))
|
||||
{
|
||||
lit_utf8_decr (string_curr_p);
|
||||
*start_p = *string_curr_p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_global_remove_leading_white_spaces */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseInt' routine
|
||||
*
|
||||
@@ -158,13 +133,13 @@ ecma_builtin_global_object_parse_int (const lit_utf8_byte_t *string_buff, /**< r
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *string_curr_p = string_buff;
|
||||
const lit_utf8_byte_t *string_end_p = string_buff + string_buff_size;
|
||||
|
||||
/* 2. Remove leading whitespace. */
|
||||
const lit_utf8_byte_t *start_p = string_end_p;
|
||||
const lit_utf8_byte_t *end_p = start_p;
|
||||
ecma_string_trim_helper (&string_curr_p, &string_buff_size);
|
||||
|
||||
ecma_builtin_global_remove_leading_white_spaces (&string_curr_p, string_end_p, &start_p);
|
||||
const lit_utf8_byte_t *string_end_p = string_curr_p + string_buff_size;
|
||||
const lit_utf8_byte_t *start_p = string_curr_p;
|
||||
const lit_utf8_byte_t *end_p = string_end_p;
|
||||
|
||||
if (string_curr_p >= string_end_p)
|
||||
{
|
||||
@@ -336,14 +311,14 @@ ecma_builtin_global_object_parse_float (const lit_utf8_byte_t *string_buff, /**<
|
||||
}
|
||||
|
||||
const lit_utf8_byte_t *str_curr_p = string_buff;
|
||||
const lit_utf8_byte_t *str_end_p = string_buff + string_buff_size;
|
||||
|
||||
const lit_utf8_byte_t *start_p = str_end_p;
|
||||
/* 2. Remove leading whitespace. */
|
||||
ecma_string_trim_helper (&str_curr_p, &string_buff_size);
|
||||
|
||||
const lit_utf8_byte_t *str_end_p = str_curr_p + string_buff_size;
|
||||
const lit_utf8_byte_t *start_p = str_curr_p;
|
||||
const lit_utf8_byte_t *end_p = str_end_p;
|
||||
|
||||
/* 2. Find first non whitespace char and set starting position. */
|
||||
ecma_builtin_global_remove_leading_white_spaces (&str_curr_p, str_end_p, &start_p);
|
||||
|
||||
bool sign = false;
|
||||
ecma_char_t current;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user