mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Extend Jerry API & API documentation with regex flags (#4246)
JerryScript-DCO-1.0-Signed-off-by: Virag Orkenyi orkvi@inf.u-szeged.hu
This commit is contained in:
parent
1237bef0f0
commit
f7b7873a02
@ -183,11 +183,20 @@ RegExp object optional flags:
|
||||
|
||||
- JERRY_REGEXP_FLAG_GLOBAL - global match; find all matches rather than stopping after the first match
|
||||
- JERRY_REGEXP_FLAG_IGNORE_CASE - ignore case
|
||||
- JERRY_REGEXP_FLAG_MULTILINE - multiline; treat beginning and end characters (^ and $) as working over
|
||||
multiple lines (i.e., match the beginning or end of each line (delimited by \n or \r), not only the
|
||||
very beginning or end of the whole input string)
|
||||
- JERRY_REGEXP_FLAG_MULTILINE - multiline; treat beginning and end characters (^ and $) as working
|
||||
over
|
||||
multiple lines (i.e., match the beginning or end of each line (delimited by \n or \r), not only the
|
||||
very beginning or end of the whole input string)
|
||||
- JERRY_REGEXP_FLAG_STICKY - The sticky flag indicates that it matches only from the index indicated
|
||||
by the lastIndex property
|
||||
- JERRY_REGEXP_FLAG_UNICODE - The unicode flag enables various Unicode-related features
|
||||
- JERRY_REGEXP_FLAG_DOTALL -The dotall flag indicates that the dot special character (".") should
|
||||
additionally match the following line terminator ("newline") characters in a string;
|
||||
|
||||
|
||||
*New in version 2.0*.
|
||||
*Changed in version[[NEXT_RELEASE]]* : Added `JERRY_REGEXP_FLAG_STICKY`, `JERRY_REGEXP_FLAG_UNICODE` , `JERRY_REGEXP_FLAG_DOTALL` values.
|
||||
|
||||
|
||||
## jerry_parse_opts_t
|
||||
|
||||
|
||||
@ -71,7 +71,10 @@ JERRY_STATIC_ASSERT ((int) ECMA_INIT_EMPTY == (int) JERRY_INIT_EMPTY
|
||||
#if ENABLED (JERRY_BUILTIN_REGEXP)
|
||||
JERRY_STATIC_ASSERT ((int) RE_FLAG_GLOBAL == (int) JERRY_REGEXP_FLAG_GLOBAL
|
||||
&& (int) RE_FLAG_MULTILINE == (int) JERRY_REGEXP_FLAG_MULTILINE
|
||||
&& (int) RE_FLAG_IGNORE_CASE == (int) JERRY_REGEXP_FLAG_IGNORE_CASE,
|
||||
&& (int) RE_FLAG_IGNORE_CASE == (int) JERRY_REGEXP_FLAG_IGNORE_CASE
|
||||
&& (int) RE_FLAG_STICKY== (int) JERRY_REGEXP_FLAG_STICKY
|
||||
&& (int) RE_FLAG_UNICODE == (int) JERRY_REGEXP_FLAG_UNICODE
|
||||
&& (int) RE_FLAG_DOTALL == (int) JERRY_REGEXP_FLAG_DOTALL,
|
||||
re_flags_t_must_be_equal_to_jerry_regexp_flags_t);
|
||||
#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */
|
||||
|
||||
|
||||
@ -135,7 +135,10 @@ typedef enum
|
||||
{
|
||||
JERRY_REGEXP_FLAG_GLOBAL = (1u << 1), /**< Globally scan string */
|
||||
JERRY_REGEXP_FLAG_IGNORE_CASE = (1u << 2), /**< Ignore case */
|
||||
JERRY_REGEXP_FLAG_MULTILINE = (1u << 3) /**< Multiline string scan */
|
||||
JERRY_REGEXP_FLAG_MULTILINE = (1u << 3), /**< Multiline string scan */
|
||||
JERRY_REGEXP_FLAG_STICKY = (1u << 4), /**< ECMAScript v11, 21.2.5.14 */
|
||||
JERRY_REGEXP_FLAG_UNICODE = (1u << 5), /**< ECMAScript v11, 21.2.5.17 */
|
||||
JERRY_REGEXP_FLAG_DOTALL = (1u << 6) /**< ECMAScript v11, 21.2.5.3 */
|
||||
} jerry_regexp_flags_t;
|
||||
|
||||
/**
|
||||
|
||||
79
tests/unit-core/test-regexp-dotall-unicode.c
Normal file
79
tests/unit-core/test-regexp-dotall-unicode.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
TEST_INIT ();
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL))
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ES.next support is disabled\n");
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
jerry_value_t undefined_this_arg = jerry_create_undefined ();
|
||||
jerry_char_t pattern2[] = "\\u{61}.\\u{62}";
|
||||
uint16_t flags = JERRY_REGEXP_FLAG_DOTALL | JERRY_REGEXP_FLAG_UNICODE | JERRY_REGEXP_FLAG_STICKY;
|
||||
jerry_value_t regex_obj = jerry_create_regexp (pattern2, flags);
|
||||
TEST_ASSERT (jerry_value_is_object (regex_obj));
|
||||
|
||||
const jerry_char_t func_resource[] = "unknown";
|
||||
const jerry_char_t func_arg_list[] = "regex";
|
||||
const jerry_char_t func_src2[] = "return [regex.exec('a\\nb'), regex.dotAll, regex.sticky, regex.unicode ];";
|
||||
jerry_value_t func_val = jerry_parse_function (func_resource,
|
||||
sizeof (func_resource) - 1,
|
||||
func_arg_list,
|
||||
sizeof (func_arg_list) - 1,
|
||||
func_src2,
|
||||
sizeof (func_src2) - 1,
|
||||
JERRY_PARSE_NO_OPTS);
|
||||
|
||||
jerry_value_t res = jerry_call_function (func_val, undefined_this_arg, ®ex_obj, 1);
|
||||
jerry_value_t regex_res = jerry_get_property_by_index (res, 0);
|
||||
jerry_value_t regex_res_str = jerry_get_property_by_index (regex_res, 0);
|
||||
jerry_value_t is_dotall = jerry_get_property_by_index (res, 1);
|
||||
jerry_value_t is_sticky = jerry_get_property_by_index (res, 2);
|
||||
jerry_value_t is_unicode = jerry_get_property_by_index (res, 3);
|
||||
|
||||
jerry_size_t str_size = jerry_get_string_size (regex_res_str);
|
||||
JERRY_VLA (jerry_char_t, res_buff, str_size);
|
||||
jerry_size_t res_size = jerry_string_to_char_buffer (regex_res_str, res_buff, str_size);
|
||||
|
||||
const char expected_result[] = "a\nb";
|
||||
TEST_ASSERT (res_size == (sizeof (expected_result) - 1));
|
||||
TEST_ASSERT (strncmp (expected_result, (const char *) res_buff, res_size) == 0);
|
||||
TEST_ASSERT (jerry_get_boolean_value (is_dotall));
|
||||
TEST_ASSERT (jerry_get_boolean_value (is_sticky));
|
||||
TEST_ASSERT (jerry_get_boolean_value (is_unicode));
|
||||
|
||||
jerry_release_value (regex_obj);
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (func_val);
|
||||
jerry_release_value (regex_res);
|
||||
jerry_release_value (regex_res_str);
|
||||
jerry_release_value (is_dotall);
|
||||
jerry_release_value (is_sticky);
|
||||
jerry_release_value (is_unicode);
|
||||
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
} /* main */
|
||||
Loading…
x
Reference in New Issue
Block a user