public static string GetSubstring(RubyScope /*!*/ scope, string /*!*/ self, [NotNull] RubyRegex /*!*/ regex) { if (regex.IsEmpty) { return(String.Empty); } // TODO (opt): don't create a new mutable string: MatchData match = RegexpOps.Match(scope, regex, MutableString.Create(self, RubyEncoding.UTF8)); if (match == null) { return(null); } var result = match.GetValue(); return(result != null?result.ToString() : null); }
private static object MatchToScanResult(RubyScope/*!*/ scope, MutableString/*!*/ self, RubyRegex/*!*/ regex, MatchData/*!*/ match) { if (match.GroupCount == 1) { return match.GetValue().TaintBy(regex, scope); } else { var result = new RubyArray(match.GroupCount - 1); for (int i = 1; i < match.GroupCount; i++) { MutableString value = match.GetGroupValue(i); result.Add(value != null ? value.TaintBy(regex, scope) : value); } return result; } }
private static void AppendReplacementExpression(ConversionStorage<MutableString> toS, BinaryOpStorage hashDefault, MutableString/*!*/ input, MatchData/*!*/ match, MutableString/*!*/ result, Union<IDictionary<object, object>, MutableString>/*!*/ replacement) { if (replacement.Second != null) { AppendReplacementExpression(input, match, result, replacement.Second); } else { Debug.Assert(toS != null && hashDefault != null); object replacementObj = HashOps.GetElement(hashDefault, replacement.First, match.GetValue()); if (replacementObj != null) { var replacementStr = Protocols.ConvertToString(toS, replacementObj); result.Append(replacementStr).TaintBy(replacementStr); } } }
public static MutableString/*!*/ ToS(MatchData/*!*/ self) { return self.GetValue(); }
public static MutableString /*!*/ ToS(MatchData /*!*/ self) { return(self.GetValue()); }