[API] Add RegExp C API (#2542)

This patch supports creating a RegExp object through the C API.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
This commit is contained in:
Daniel Balla
2018-11-19 12:18:00 +00:00
committed by László Langó
parent 47fa5904b1
commit 704eb45cb8
7 changed files with 227 additions and 15 deletions
+78
View File
@@ -62,6 +62,16 @@ Possible compile time enabled feature types:
- JERRY_FEATURE_LINE_INFO - line info available
- JERRY_FEATURE_LOGGING - logging
## jerry_regexp_flags_t
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_parse_opts_t
Option bits for [jerry_parse](#jerry_parse) and
@@ -3406,6 +3416,74 @@ jerry_create_string_sz (const jerry_char_t *str_p,
- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8)
## jerry_create_regexp
**Summary**
Returns a jerry_value_t RegExp object or an error, if the construction of the object fails.
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t);
**Prototype**
```c
jerry_value_t
jerry_create_regexp (const jerry_char_t *pattern_p, jerry_regexp_flags_t flags);
```
- `pattern_p` - the RegExp pattern as a zero-terminated UTF-8 string
- `flags` - optional flags for the RegExp object
- return value - the RegExp object as a `jerry_value_t`
**Example**
```c
{
jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
jerry_regexp_flags_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
jerry_value_t regexp = jerry_create_regexp (pattern_p, pattern_flags);
...
jerry_release_value (regexp);
}
```
## jerry_create_regexp_sz
**Summary**
Returns a jerry_value_t RegExp object or an error, if the construction of the object fails.
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t);
**Prototype**
```c
jerry_value_t
jerry_create_regexp_sz (const jerry_char_t *pattern_p, jerry_size_t pattern_size, jerry_regexp_flags_t flags);
```
- `pattern_p` - the RegExp pattern as a zero-terminated UTF-8 string
- `pattern_size` - size of the `pattern`
- `flags` - optional flags for the RegExp object
- return value - the RegExp object as a `jerry_value_t`
**Example**
```c
{
jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
jerry_size_t pattern_size = sizeof (pattern_p) - 1;
jerry_regexp_flags_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
jerry_value_t regexp = jerry_create_regexp_sz (pattern_p, pattern_size, pattern_flags);
...
jerry_release_value (regexp);
}
```
## jerry_create_typedarray
**Summary**