Beispiel #1
0
    /*
     * This static call constructs a RegexTree from a regular expression
     * pattern string and an option string.
     *
     * The method creates, drives, and drops a parser instance.
     */
    internal static RegexTree Parse(string re, RegexOptions op)
    {
        var culture = op.HasAnyFlags(RegexOptions.CultureInvariant)
            ? CultureInfo.InvariantCulture
            : CultureInfo.CurrentCulture;
        var p = new RegexParser(culture)
        {
            _options = op
        };

        p.SetPattern(re);
        p.Reset(op);
        var root = p.ScanRegex();

        return(new RegexTree(root, op));
    }
Beispiel #2
0
    public static string ExpandCharClass(string charClass)
    {
        var regexParser = new RegexParser(CultureInfo.CurrentCulture);

        regexParser.SetPattern(charClass);
        var           regexCharClass = regexParser.ScanCharClass(false);
        int           count          = regexCharClass.RangeCount();
        List <string> ranges         = new List <string>();

        // range 0 can be skipped
        for (int i = 1; i < count; i++)
        {
            var range = regexCharClass.GetRangeAt(i);
            ranges.Add(ExpandRange(range));
        }
        return(String.Concat(ranges));
    }