Exemple #1
0
        public static string GetSubstring(RubyScope /*!*/ scope, string /*!*/ self, [NotNull] RubyRegex /*!*/ regex, [DefaultProtocol] int occurrance)
        {
            if (regex.IsEmpty)
            {
                return(String.Empty);
            }

            MatchData match = RegexpOps.Match(scope, regex, MutableString.Create(self, RubyEncoding.UTF8));

            if (match == null || !RegexpOps.NormalizeGroupIndex(ref occurrance, match.GroupCount))
            {
                return(null);
            }

            MutableString result = match.GetGroupValue(occurrance);

            return(result != null?result.ToString() : null);
        }
Exemple #2
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);
        }
Exemple #3
0
 public static object Match(RubyScope /*!*/ scope, string /*!*/ self, [NotNull] RubyRegex /*!*/ regex)
 {
     return(RegexpOps.MatchIndex(scope, regex, MutableString.Create(self, RubyEncoding.UTF8)));
 }