Module: RE2
- Defined in:
- ext/re2/re2.cc,
lib/re2/string.rb,
lib/re2/scanner.rb
Defined Under Namespace
Modules: String Classes: MatchData, Regexp, Scanner
Class Method Summary collapse
-
.GlobalReplace(str, pattern, rewrite) ⇒ String
Return a copy of
str
withpattern
replaced byrewrite
. -
.QuoteMeta(unquoted) ⇒ String
Returns a version of str with all potentially meaningful regexp characters escaped.
-
.Replace(str, pattern, rewrite) ⇒ String
Returns a copy of
str
with the first occurrencepattern
replaced withrewrite
.
Class Method Details
.GlobalReplace(str, pattern, rewrite) ⇒ String
Return a copy of str
with pattern
replaced by rewrite
.
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
# File 'ext/re2/re2.cc', line 1325
static VALUE re2_GlobalReplace(VALUE self, VALUE str, VALUE pattern,
VALUE rewrite) {
UNUSED(self);
/* Convert all the inputs to be pumped into RE2::GlobalReplace. */
re2_pattern *p;
string str_as_string(StringValuePtr(str));
/* Do the replacement. */
if (rb_obj_is_kind_of(pattern, re2_cRegexp)) {
Data_Get_Struct(pattern, re2_pattern, p);
RE2::GlobalReplace(&str_as_string, *p->pattern, StringValuePtr(rewrite));
return ENCODED_STR_NEW(str_as_string.data(), str_as_string.size(),
p->pattern->options().encoding() == RE2::Options::EncodingUTF8 ? "UTF-8" : "ISO-8859-1");
} else {
RE2::GlobalReplace(&str_as_string, StringValuePtr(pattern),
StringValuePtr(rewrite));
return ENCODED_STR_NEW2(str_as_string.data(), str_as_string.size(),
pattern);
}
}
|
.QuoteMeta(unquoted) ⇒ String
Returns a version of str with all potentially meaningful regexp characters escaped. The returned string, used as a regular expression, will exactly match the original string.
1359 1360 1361 1362 1363 |
# File 'ext/re2/re2.cc', line 1359
static VALUE re2_QuoteMeta(VALUE self, VALUE unquoted) {
UNUSED(self);
string quoted_string = RE2::QuoteMeta(StringValuePtr(unquoted));
return rb_str_new(quoted_string.data(), quoted_string.size());
}
|
.Replace(str, pattern, rewrite) ⇒ String
Returns a copy of str
with the first occurrence pattern
replaced with rewrite
.
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
# File 'ext/re2/re2.cc', line 1288
static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
VALUE rewrite) {
UNUSED(self);
re2_pattern *p;
/* Convert all the inputs to be pumped into RE2::Replace. */
string str_as_string(StringValuePtr(str));
/* Do the replacement. */
if (rb_obj_is_kind_of(pattern, re2_cRegexp)) {
Data_Get_Struct(pattern, re2_pattern, p);
RE2::Replace(&str_as_string, *p->pattern, StringValuePtr(rewrite));
return ENCODED_STR_NEW(str_as_string.data(), str_as_string.size(),
p->pattern->options().encoding() == RE2::Options::EncodingUTF8 ? "UTF-8" : "ISO-8859-1");
} else {
RE2::Replace(&str_as_string, StringValuePtr(pattern),
StringValuePtr(rewrite));
return ENCODED_STR_NEW2(str_as_string.data(), str_as_string.size(),
pattern);
}
}
|