示例#1
0
        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);
        }
示例#2
0
 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;
     }
 }
示例#3
0
        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);
                }
            }
        }
示例#4
0
 public static MutableString/*!*/ ToS(MatchData/*!*/ self) {
     return self.GetValue();
 }
示例#5
0
 public static MutableString /*!*/ ToS(MatchData /*!*/ self)
 {
     return(self.GetValue());
 }