summaryrefslogtreecommitdiff
path: root/yarp/extension.c
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2023-07-29 16:13:52 +0200
committerTakashi Kokubun <[email protected]>2023-08-16 17:47:32 -0700
commit2ccaaaa1017fa411134648bbaa6fa8f8b875e16d (patch)
treea6188584b7796c4617005c1a73a87787eeb09334 /yarp/extension.c
parent31960a9627f7810a294b835dfe073cab1106e1de (diff)
[ruby/yarp] Add simpler exported unescape function to librubyparser
* Moves logic from the C extension to librubyparser which can be shared with the Fiddle backend. https://github.com/ruby/yarp/commit/aa48d5e444
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8226
Diffstat (limited to 'yarp/extension.c')
-rw-r--r--yarp/extension.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/yarp/extension.c b/yarp/extension.c
index 7ede50bb0f..36e9941d64 100644
--- a/yarp/extension.c
+++ b/yarp/extension.c
@@ -529,30 +529,16 @@ named_captures(VALUE self, VALUE source) {
// version.
static VALUE
unescape(VALUE source, yp_unescape_type_t unescape_type) {
- yp_string_t string;
- VALUE result;
+ yp_string_t result;
- yp_list_t error_list;
- yp_list_init(&error_list);
-
- const char *start = RSTRING_PTR(source);
- size_t length = RSTRING_LEN(source);
-
- yp_parser_t parser;
- yp_parser_init(&parser, start, length, "");
-
- yp_unescape_manipulate_string(&parser, start, length, &string, unescape_type, &error_list);
- if (yp_list_empty_p(&error_list)) {
- result = rb_str_new(yp_string_source(&string), yp_string_length(&string));
+ if (yp_unescape_string(RSTRING_PTR(source), RSTRING_LEN(source), unescape_type, &result)) {
+ VALUE str = rb_str_new(yp_string_source(&result), yp_string_length(&result));
+ yp_string_free(&result);
+ return str;
} else {
- result = Qnil;
+ yp_string_free(&result);
+ return Qnil;
}
-
- yp_string_free(&string);
- yp_list_free(&error_list);
- yp_parser_free(&parser);
-
- return result;
}
// Do not unescape anything in the given string. This is here to provide a