diff --git a/ext/re2/re2.cc b/ext/re2/re2.cc index b38804a..7dddb9c 100644 --- a/ext/re2/re2.cc +++ b/ext/re2/re2.cc @@ -1464,7 +1464,6 @@ static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern, return ENCODED_STR_NEW(str_as_string.data(), str_as_string.size(), "UTF-8"); } - } /* @@ -1794,132 +1793,82 @@ void Init_re2(void) { re2_eSetUnsupportedError = rb_define_class_under(re2_cSet, "UnsupportedError", rb_const_get(rb_cObject, rb_intern("StandardError"))); - rb_define_alloc_func(re2_cRegexp, (VALUE (*)(VALUE))re2_regexp_allocate); - rb_define_alloc_func(re2_cMatchData, - (VALUE (*)(VALUE))re2_matchdata_allocate); - rb_define_alloc_func(re2_cScanner, - (VALUE (*)(VALUE))re2_scanner_allocate); - rb_define_alloc_func(re2_cSet, (VALUE (*)(VALUE))re2_set_allocate); - - rb_define_method(re2_cMatchData, "string", - RUBY_METHOD_FUNC(re2_matchdata_string), 0); - rb_define_method(re2_cMatchData, "regexp", - RUBY_METHOD_FUNC(re2_matchdata_regexp), 0); - rb_define_method(re2_cMatchData, "to_a", - RUBY_METHOD_FUNC(re2_matchdata_to_a), 0); - rb_define_method(re2_cMatchData, "size", - RUBY_METHOD_FUNC(re2_matchdata_size), 0); - rb_define_method(re2_cMatchData, "length", - RUBY_METHOD_FUNC(re2_matchdata_size), 0); - rb_define_method(re2_cMatchData, "begin", - RUBY_METHOD_FUNC(re2_matchdata_begin), 1); - rb_define_method(re2_cMatchData, "end", - RUBY_METHOD_FUNC(re2_matchdata_end), 1); - rb_define_method(re2_cMatchData, "[]", RUBY_METHOD_FUNC(re2_matchdata_aref), - -1); - rb_define_method(re2_cMatchData, "to_s", - RUBY_METHOD_FUNC(re2_matchdata_to_s), 0); - rb_define_method(re2_cMatchData, "inspect", - RUBY_METHOD_FUNC(re2_matchdata_inspect), 0); - rb_define_method(re2_cMatchData, "deconstruct", - RUBY_METHOD_FUNC(re2_matchdata_deconstruct), 0); + rb_define_alloc_func(re2_cRegexp, re2_regexp_allocate); + rb_define_alloc_func(re2_cMatchData, re2_matchdata_allocate); + rb_define_alloc_func(re2_cScanner, re2_scanner_allocate); + rb_define_alloc_func(re2_cSet, re2_set_allocate); + + rb_define_method(re2_cMatchData, "string", re2_matchdata_string, 0); + rb_define_method(re2_cMatchData, "regexp", re2_matchdata_regexp, 0); + rb_define_method(re2_cMatchData, "to_a", re2_matchdata_to_a, 0); + rb_define_method(re2_cMatchData, "size", re2_matchdata_size, 0); + rb_define_method(re2_cMatchData, "length", re2_matchdata_size, 0); + rb_define_method(re2_cMatchData, "begin", re2_matchdata_begin, 1); + rb_define_method(re2_cMatchData, "end", re2_matchdata_end, 1); + rb_define_method(re2_cMatchData, "[]", re2_matchdata_aref, -1); + rb_define_method(re2_cMatchData, "to_s", re2_matchdata_to_s, 0); + rb_define_method(re2_cMatchData, "inspect", re2_matchdata_inspect, 0); + rb_define_method(re2_cMatchData, "deconstruct", re2_matchdata_deconstruct, 0); rb_define_method(re2_cMatchData, "deconstruct_keys", - RUBY_METHOD_FUNC(re2_matchdata_deconstruct_keys), 1); - - rb_define_method(re2_cScanner, "string", - RUBY_METHOD_FUNC(re2_scanner_string), 0); - rb_define_method(re2_cScanner, "eof?", - RUBY_METHOD_FUNC(re2_scanner_eof), 0); - rb_define_method(re2_cScanner, "regexp", - RUBY_METHOD_FUNC(re2_scanner_regexp), 0); - rb_define_method(re2_cScanner, "scan", - RUBY_METHOD_FUNC(re2_scanner_scan), 0); - rb_define_method(re2_cScanner, "rewind", - RUBY_METHOD_FUNC(re2_scanner_rewind), 0); - - rb_define_method(re2_cRegexp, "initialize", - RUBY_METHOD_FUNC(re2_regexp_initialize), -1); - rb_define_method(re2_cRegexp, "ok?", RUBY_METHOD_FUNC(re2_regexp_ok), 0); - rb_define_method(re2_cRegexp, "error", RUBY_METHOD_FUNC(re2_regexp_error), - 0); - rb_define_method(re2_cRegexp, "error_arg", - RUBY_METHOD_FUNC(re2_regexp_error_arg), 0); - rb_define_method(re2_cRegexp, "program_size", - RUBY_METHOD_FUNC(re2_regexp_program_size), 0); - rb_define_method(re2_cRegexp, "options", - RUBY_METHOD_FUNC(re2_regexp_options), 0); + re2_matchdata_deconstruct_keys, 1); + + rb_define_method(re2_cScanner, "string", re2_scanner_string, 0); + rb_define_method(re2_cScanner, "eof?", re2_scanner_eof, 0); + rb_define_method(re2_cScanner, "regexp", re2_scanner_regexp, 0); + rb_define_method(re2_cScanner, "scan", re2_scanner_scan, 0); + rb_define_method(re2_cScanner, "rewind", re2_scanner_rewind, 0); + + rb_define_method(re2_cRegexp, "initialize", re2_regexp_initialize, -1); + rb_define_method(re2_cRegexp, "ok?", re2_regexp_ok, 0); + rb_define_method(re2_cRegexp, "error", re2_regexp_error, 0); + rb_define_method(re2_cRegexp, "error_arg", re2_regexp_error_arg, 0); + rb_define_method(re2_cRegexp, "program_size", re2_regexp_program_size, 0); + rb_define_method(re2_cRegexp, "options", re2_regexp_options, 0); rb_define_method(re2_cRegexp, "number_of_capturing_groups", - RUBY_METHOD_FUNC(re2_regexp_number_of_capturing_groups), 0); + re2_regexp_number_of_capturing_groups, 0); rb_define_method(re2_cRegexp, "named_capturing_groups", - RUBY_METHOD_FUNC(re2_regexp_named_capturing_groups), 0); - rb_define_method(re2_cRegexp, "match", RUBY_METHOD_FUNC(re2_regexp_match), - -1); - rb_define_method(re2_cRegexp, "match?", - RUBY_METHOD_FUNC(re2_regexp_match_p), 1); - rb_define_method(re2_cRegexp, "=~", - RUBY_METHOD_FUNC(re2_regexp_match_p), 1); - rb_define_method(re2_cRegexp, "===", - RUBY_METHOD_FUNC(re2_regexp_match_p), 1); - rb_define_method(re2_cRegexp, "scan", - RUBY_METHOD_FUNC(re2_regexp_scan), 1); - rb_define_method(re2_cRegexp, "to_s", RUBY_METHOD_FUNC(re2_regexp_to_s), 0); - rb_define_method(re2_cRegexp, "to_str", RUBY_METHOD_FUNC(re2_regexp_to_s), - 0); - rb_define_method(re2_cRegexp, "pattern", RUBY_METHOD_FUNC(re2_regexp_to_s), - 0); - rb_define_method(re2_cRegexp, "source", RUBY_METHOD_FUNC(re2_regexp_to_s), - 0); - rb_define_method(re2_cRegexp, "inspect", - RUBY_METHOD_FUNC(re2_regexp_inspect), 0); - rb_define_method(re2_cRegexp, "utf8?", RUBY_METHOD_FUNC(re2_regexp_utf8), + re2_regexp_named_capturing_groups, 0); + rb_define_method(re2_cRegexp, "match", re2_regexp_match, -1); + rb_define_method(re2_cRegexp, "match?", re2_regexp_match_p, 1); + rb_define_method(re2_cRegexp, "=~", re2_regexp_match_p, 1); + rb_define_method(re2_cRegexp, "===", re2_regexp_match_p, 1); + rb_define_method(re2_cRegexp, "scan", re2_regexp_scan, 1); + rb_define_method(re2_cRegexp, "to_s", re2_regexp_to_s, 0); + rb_define_method(re2_cRegexp, "to_str", re2_regexp_to_s, 0); + rb_define_method(re2_cRegexp, "pattern", re2_regexp_to_s, 0); + rb_define_method(re2_cRegexp, "source", re2_regexp_to_s, 0); + rb_define_method(re2_cRegexp, "inspect", re2_regexp_inspect, 0); + rb_define_method(re2_cRegexp, "utf8?", re2_regexp_utf8, 0); + rb_define_method(re2_cRegexp, "posix_syntax?", re2_regexp_posix_syntax, 0); + rb_define_method(re2_cRegexp, "longest_match?", re2_regexp_longest_match, 0); + rb_define_method(re2_cRegexp, "log_errors?", re2_regexp_log_errors, 0); + rb_define_method(re2_cRegexp, "max_mem", re2_regexp_max_mem, 0); + rb_define_method(re2_cRegexp, "literal?", re2_regexp_literal, 0); + rb_define_method(re2_cRegexp, "never_nl?", re2_regexp_never_nl, 0); + rb_define_method(re2_cRegexp, "case_sensitive?", re2_regexp_case_sensitive, 0); - rb_define_method(re2_cRegexp, "posix_syntax?", - RUBY_METHOD_FUNC(re2_regexp_posix_syntax), 0); - rb_define_method(re2_cRegexp, "longest_match?", - RUBY_METHOD_FUNC(re2_regexp_longest_match), 0); - rb_define_method(re2_cRegexp, "log_errors?", - RUBY_METHOD_FUNC(re2_regexp_log_errors), 0); - rb_define_method(re2_cRegexp, "max_mem", - RUBY_METHOD_FUNC(re2_regexp_max_mem), 0); - rb_define_method(re2_cRegexp, "literal?", - RUBY_METHOD_FUNC(re2_regexp_literal), 0); - rb_define_method(re2_cRegexp, "never_nl?", - RUBY_METHOD_FUNC(re2_regexp_never_nl), 0); - rb_define_method(re2_cRegexp, "case_sensitive?", - RUBY_METHOD_FUNC(re2_regexp_case_sensitive), 0); rb_define_method(re2_cRegexp, "case_insensitive?", - RUBY_METHOD_FUNC(re2_regexp_case_insensitive), 0); - rb_define_method(re2_cRegexp, "casefold?", - RUBY_METHOD_FUNC(re2_regexp_case_insensitive), 0); - rb_define_method(re2_cRegexp, "perl_classes?", - RUBY_METHOD_FUNC(re2_regexp_perl_classes), 0); - rb_define_method(re2_cRegexp, "word_boundary?", - RUBY_METHOD_FUNC(re2_regexp_word_boundary), 0); - rb_define_method(re2_cRegexp, "one_line?", - RUBY_METHOD_FUNC(re2_regexp_one_line), 0); + re2_regexp_case_insensitive, 0); + rb_define_method(re2_cRegexp, "casefold?", re2_regexp_case_insensitive, 0); + rb_define_method(re2_cRegexp, "perl_classes?", re2_regexp_perl_classes, 0); + rb_define_method(re2_cRegexp, "word_boundary?", re2_regexp_word_boundary, 0); + rb_define_method(re2_cRegexp, "one_line?", re2_regexp_one_line, 0); rb_define_singleton_method(re2_cSet, "match_raises_errors?", - RUBY_METHOD_FUNC(re2_set_match_raises_errors_p), 0); - rb_define_method(re2_cSet, "initialize", - RUBY_METHOD_FUNC(re2_set_initialize), -1); - rb_define_method(re2_cSet, "add", RUBY_METHOD_FUNC(re2_set_add), 1); - rb_define_method(re2_cSet, "compile", RUBY_METHOD_FUNC(re2_set_compile), 0); - rb_define_method(re2_cSet, "match", RUBY_METHOD_FUNC(re2_set_match), -1); - - rb_define_module_function(re2_mRE2, "Replace", - RUBY_METHOD_FUNC(re2_Replace), 3); - rb_define_module_function(re2_mRE2, "GlobalReplace", - RUBY_METHOD_FUNC(re2_GlobalReplace), 3); - rb_define_module_function(re2_mRE2, "QuoteMeta", - RUBY_METHOD_FUNC(re2_QuoteMeta), 1); - rb_define_singleton_method(re2_cRegexp, "escape", - RUBY_METHOD_FUNC(re2_QuoteMeta), 1); - rb_define_singleton_method(re2_cRegexp, "quote", - RUBY_METHOD_FUNC(re2_QuoteMeta), 1); - rb_define_singleton_method(re2_cRegexp, "compile", - RUBY_METHOD_FUNC(rb_class_new_instance), -1); - - rb_define_global_function("RE2", RUBY_METHOD_FUNC(re2_re2), -1); + re2_set_match_raises_errors_p, 0); + rb_define_method(re2_cSet, "initialize", re2_set_initialize, -1); + rb_define_method(re2_cSet, "add", re2_set_add, 1); + rb_define_method(re2_cSet, "compile", re2_set_compile, 0); + rb_define_method(re2_cSet, "match", re2_set_match, -1); + + rb_define_module_function(re2_mRE2, "Replace", re2_Replace, 3); + rb_define_module_function(re2_mRE2, "GlobalReplace", re2_GlobalReplace, 3); + rb_define_module_function(re2_mRE2, "QuoteMeta", re2_QuoteMeta, 1); + rb_define_singleton_method(re2_cRegexp, "escape", re2_QuoteMeta, 1); + rb_define_singleton_method(re2_cRegexp, "quote", re2_QuoteMeta, 1); + rb_define_singleton_method(re2_cRegexp, "compile", rb_class_new_instance, -1); + + rb_define_global_function("RE2", re2_re2, -1); /* Create the symbols used in options. */ id_utf8 = rb_intern("utf8");