Converts a Ruby regexp pattern to a CLR pattern
Example #1
0
        private Regex /*!*/ TransformPattern(RubyEncoding encoding, RubyRegexOptions kc)
        {
            // We can reuse cached CLR regex if it was created for the same k-coding:
            if (_cachedRegex != null && kc == _cachedKCode)
            {
                return(_cachedRegex);
            }

            string pattern;

            if (kc != 0 || encoding == RubyEncoding.Binary)
            {
                pattern = _pattern.ToString(encoding.Encoding);
            }
            else
            {
                pattern = _pattern.ConvertToString();
            }

            Regex result;

            try {
                result = new Regex(RegexpTransformer.Transform(pattern, _options, out _hasGAnchor), ToClrOptions(_options));
            } catch (Exception e) {
                throw new RegexpError(e.Message);
            }

            _cachedKCode = kc;
            _cachedRegex = result;
            return(result);
        }
Example #2
0
 internal static string Transform(string/*!*/ rubyPattern, RubyRegexOptions options) {
     if (rubyPattern == "\\Af(?=[[:xdigit:]]{2}+\\z)") {
         // pp.rb uses this pattern. The real fix requires cracking the entire regexp and so is left for later
         return "\\Af(?=(?:[[:xdigit:]]{2})+\\z)";
     }
     RegexpTransformer transformer = new RegexpTransformer(rubyPattern);
     return transformer.Transform();
 }
 internal static string Transform(string/*!*/ rubyPattern, RubyRegexOptions options, out bool hasGAnchor) {
     if (rubyPattern == "\\Af(?=[[:xdigit:]]{2}+\\z)") {
         // pp.rb uses this pattern. The real fix requires cracking the entire regexp and so is left for later
         hasGAnchor = false;
         return "\\Af(?=(?:[[:xdigit:]]{2})+\\z)";
     }
     RegexpTransformer transformer = new RegexpTransformer(rubyPattern);
     var result = transformer.Transform();
     hasGAnchor = transformer._hasGAnchor;
     return result;
 }
Example #4
0
 internal static string Transform(string/*!*/ rubyPattern, RubyRegexOptions options, out bool hasGAnchor) {
     // TODO: surrogates (REXML uses this pattern)
     if (rubyPattern == "^[\t\n\r -\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF]*$") {
         hasGAnchor = false;
         return "^(?:[\t\n\r -\uD7FF\uE000-\uFFFD]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$";
     }
     
     RegexpTransformer transformer = new RegexpTransformer(rubyPattern);
     var result = transformer.Transform();
     hasGAnchor = transformer._hasGAnchor;
     return result;
 }
Example #5
0
        internal static string Transform(string /*!*/ rubyPattern, RubyRegexOptions options, out bool hasGAnchor)
        {
            if (rubyPattern == "\\Af(?=[[:xdigit:]]{2}+\\z)")
            {
                // pp.rb uses this pattern. The real fix requires cracking the entire regexp and so is left for later
                hasGAnchor = false;
                return("\\Af(?=(?:[[:xdigit:]]{2})+\\z)");
            }
            RegexpTransformer transformer = new RegexpTransformer(rubyPattern);
            var result = transformer.Transform();

            hasGAnchor = transformer._hasGAnchor;
            return(result);
        }