コード例 #1
0
ファイル: Glob.cs プロジェクト: ltwlf/IronSP
        private static string[] UngroupGlobs(string /*!*/ pattern, bool noEscape)
        {
            GlobUngrouper ungrouper = new GlobUngrouper(pattern.Length);

            bool inEscape = false;

            foreach (char c in pattern)
            {
                if (inEscape)
                {
                    if (c != ',' && c != '{' && c != '}')
                    {
                        ungrouper.AddChar('\\');
                    }
                    ungrouper.AddChar(c);
                    inEscape = false;
                    continue;
                }
                else if (c == '\\' && !noEscape)
                {
                    inEscape = true;
                    continue;
                }

                switch (c)
                {
                case '{':
                    ungrouper.StartLevel();
                    break;

                case ',':
                    if (ungrouper.Level < 1)
                    {
                        ungrouper.AddChar(c);
                    }
                    else
                    {
                        ungrouper.AddGroup();
                    }
                    break;

                case '}':
                    if (ungrouper.Level < 1)
                    {
                        // Unbalanced closing bracket matches nothing
                        return(ArrayUtils.EmptyStrings);
                    }
                    ungrouper.FinishLevel();
                    break;

                default:
                    ungrouper.AddChar(c);
                    break;
                }
            }
            return(ungrouper.Flatten());
        }
コード例 #2
0
        /// <summary>
        /// {a,b}c => [ac, bc]
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        internal static string[] ExpandGroup(string pattern, GlobMatcherOptions options = DefaultOptions)
        {
            GlobUngrouper ungrouper     = new GlobUngrouper();
            bool          escaping      = false;
            bool          disableEscape = !options.HasFlag(GlobMatcherOptions.AllowEscape);

            foreach (char c in pattern)
            {
                if (escaping)
                {
                    if (c != ',' && c != '{' && c != '}')
                    {
                        ungrouper.AddChar('\\');
                    }
                    ungrouper.AddChar(c);
                    escaping = false;
                    continue;
                }
                else if (c == '\\' && !disableEscape)
                {
                    escaping = true;
                    continue;
                }
                switch (c)
                {
                case '{':
                    ungrouper.StartLevel();
                    break;

                case ',':
                    if (ungrouper.Level < 1)
                    {
                        ungrouper.AddChar(c);
                    }
                    else
                    {
                        ungrouper.AddGroup();
                    }
                    break;

                case '}':
                    if (ungrouper.Level < 1)
                    {
                        // Unbalanced closing bracket matches nothing
                        return(EmptyString);
                    }
                    ungrouper.FinishLevel();
                    break;

                default:
                    ungrouper.AddChar(c);
                    break;
                }
            }
            return(ungrouper.Flatten());
        }
コード例 #3
0
ファイル: Glob.cs プロジェクト: MicroHealthLLC/mCleaner
        private static string[] UngroupGlobs(string pattern, bool noEscape)
        {
            var ungrouper = new GlobUngrouper();

            bool inEscape = false;
            foreach (char c in pattern)
            {
                if (inEscape)
                {
                    if (c != ',' && c != '{' && c != '}')
                    {
                        ungrouper.AddChar('\\');
                    }
                    ungrouper.AddChar(c);
                    inEscape = false;
                    continue;
                }
                if (c == '\\' && !noEscape)
                {
                    inEscape = true;
                    continue;
                }

                switch (c)
                {
                    case '{':
                        ungrouper.StartLevel();
                        break;

                    case ',':
                        if (ungrouper.Level < 1)
                        {
                            ungrouper.AddChar(c);
                        }
                        else
                        {
                            ungrouper.AddGroup();
                        }
                        break;

                    case '}':
                        if (ungrouper.Level < 1)
                        {
                            // Unbalanced closing bracket matches nothing
                            return new string[] { };
                        }
                        ungrouper.FinishLevel();
                        break;

                    default:
                        ungrouper.AddChar(c);
                        break;
                }
            }
            return ungrouper.Flatten();
        }
コード例 #4
0
ファイル: GlobMatcher.cs プロジェクト: yodamaster/docfx
 /// <summary>
 /// {a,b}c => [ac, bc]
 /// </summary>
 /// <param name="pattern"></param>
 /// <returns></returns>
 internal static string[] ExpandGroup(string pattern, GlobMatcherOptions options = DefaultOptions)
 {
     GlobUngrouper ungrouper = new GlobUngrouper();
     bool escaping = false;
     bool disableEscape = !options.HasFlag(GlobMatcherOptions.AllowEscape);
     foreach (char c in pattern)
     {
         if (escaping)
         {
             if (c != ',' && c != '{' && c != '}')
             {
                 ungrouper.AddChar('\\');
             }
             ungrouper.AddChar(c);
             escaping = false;
             continue;
         }
         else if (c == '\\' && !disableEscape)
         {
             escaping = true;
             continue;
         }
         switch (c)
         {
             case '{':
                 ungrouper.StartLevel();
                 break;
             case ',':
                 if (ungrouper.Level < 1)
                 {
                     ungrouper.AddChar(c);
                 }
                 else
                 {
                     ungrouper.AddGroup();
                 }
                 break;
             case '}':
                 if (ungrouper.Level < 1)
                 {
                     // Unbalanced closing bracket matches nothing
                     return EmptyString;
                 }
                 ungrouper.FinishLevel();
                 break;
             default:
                 ungrouper.AddChar(c);
                 break;
         }
     }
     return ungrouper.Flatten();
 }
コード例 #5
0
ファイル: FileSystem.Glob.cs プロジェクト: tiaohai/Phalanger
        private static string[] UngroupGlobs(string/*!*/ pattern, bool noEscape, bool brace)
        {
            GlobUngrouper ungrouper = new GlobUngrouper(pattern.Length);

            bool inEscape = false;
            foreach (char c in pattern)
            {
                if (inEscape)
                {
                    if (c != ',' && c != '{' && c != '}')
                    {
                        ungrouper.AddChar('\\');
                    }
                    ungrouper.AddChar(c);
                    inEscape = false;
                    continue;
                }
                else if (c == '\\' && !noEscape)
                {
                    inEscape = true;
                    continue;
                }

                switch (c)
                {
                    case '{':
                        if (!brace)
                            return ArrayUtils.EmptyStrings;

                        ungrouper.StartLevel();
                        break;

                    case ',':
                        if (ungrouper.Level < 1)
                        {
                            ungrouper.AddChar(c);
                        }
                        else
                        {
                            ungrouper.AddGroup();
                        }
                        break;

                    case '}':
                        if (ungrouper.Level < 1)
                        {
                            // Unbalanced closing bracket matches nothing
                            return ArrayUtils.EmptyStrings;
                        }
                        ungrouper.FinishLevel();
                        break;

                    default:
                        ungrouper.AddChar(c);
                        break;
                }
            }
            return ungrouper.Flatten();
        }
コード例 #6
0
ファイル: FileSystem.Glob.cs プロジェクト: kendallb/peachpie
        static ValueList <string> UngroupGlobs(string /*!*/ pattern, bool noEscape, bool brace)
        {
            var ungrouper = new GlobUngrouper(pattern.Length);
            var inEscape  = false;

            for (int i = 0; i < pattern.Length; i++)
            {
                var c = pattern[i];

                if (inEscape)
                {
                    inEscape = false;
                    if (c != ',' && c != '{' && c != '}')
                    {
                        ungrouper.AddChar('\\');
                    }
                    ungrouper.AddChar(c);
                }
                else if (c == '\\' && !noEscape)
                {
                    inEscape = true;
                }
                else
                {
                    switch (c)
                    {
                    case '{':
                        if (!brace)
                        {
                            return(ValueList <string> .Empty);
                        }

                        ungrouper.StartLevel();
                        break;

                    case ',':
                        if (ungrouper.Level < 1)
                        {
                            ungrouper.AddChar(c);
                        }
                        else
                        {
                            ungrouper.AddGroup();
                        }
                        break;

                    case '}':
                        if (ungrouper.Level < 1)
                        {
                            // Unbalanced closing bracket matches nothing
                            return(ValueList <string> .Empty);
                        }
                        ungrouper.FinishLevel();
                        break;

                    default:
                        ungrouper.AddChar(c);
                        break;
                    }
                }
            }
            return(ungrouper.Flatten());
        }