public BaconArgs parseArgs(string args)
                {
                    if (!cache.ContainsKey(args))
                    {
                        BaconArgs Result = new BaconArgs();
                        Result.Raw = args;
                        bool          isEscape             = false;
                        bool          isEncapsulatedString = false;
                        StringBuilder slug = new StringBuilder();
                        for (int i = 0; i < args.Length; i++)
                        {
                            char glyp = args[i];
                            if (isEscape)
                            {
                                slug.Append(glyp);
                                isEscape = false;
                            }
                            else if (glyp.Equals('\\'))
                            {
                                isEscape = true;
                            }
                            else if (isEncapsulatedString && !glyp.Equals('"'))
                            {
                                slug.Append(glyp);
                            }
                            else if (glyp.Equals('"'))
                            {
                                isEncapsulatedString = !isEncapsulatedString;
                            }
                            else if (glyp.Equals(' '))
                            {
                                if (slug.ToString().Equals("--"))
                                {
                                    Result.add(args.Substring(i).TrimStart());
                                    slug.Clear();
                                    break;
                                }
                                else
                                {
                                    Result.add(slug.ToString());
                                    slug.Clear();
                                }
                            }
                            else
                            {
                                slug.Append(glyp);
                            }
                        }
                        if (slug.Length > 0)
                        {
                            Result.add(slug.ToString());
                        }
                        cache.Add(args, Result);
                    }

                    return(cache[args]);
                }
Пример #2
0
 public class Parser { static Dictionary <string, BaconArgs> h = new Dictionary <string, BaconArgs>(); public BaconArgs parseArgs(string a)
                       {
                           if (!h.ContainsKey(a))
                           {
                               var b = new BaconArgs(); var c = false; var d = false; e = new StringBuilder(); for (int f = 0; f < a.Length; f++)
                               {
                                   var g = a[f]; if (c)
                                   {
                                       e.Append(g); c = false;
                                   }
                                   else if (g.Equals('\\'))
                                   {
                                       c = true;
                                   }
                                   else if (d && !g.Equals('"'))
                                   {
                                       e.Append(g);
                                   }
                                   else if (g.Equals('"'))
                                   {
                                       d = !d;
                                   }
                                   else if (g.Equals(' '))
                                   {
                                       if (e.ToString().Equals("--"))
                                       {
                                           b.add(a.Substring(f).TrimStart()); e.Clear(); break;
                                       }
                                       else
                                       {
                                           b.add(e.ToString()); e.Clear();
                                       }
                                   }
                                   else
                                   {
                                       e.Append(g);
                                   }
                               }
                               if (e.Length > 0)
                               {
                                   b.add(e.ToString());
                               }
                               h.Add(a, b);
                           }
                           return(h[a]);
                       }
Пример #3
0
 public BaconArgs parseArgs(string a)
 {
     if (!h.ContainsKey(a)) { var b = new BaconArgs(); var c = false; var d = false; var e = new StringBuilder(); for (int f = 0; f < a.Length; f++) { var g = a[f]; if (c) { e.Append(g); c = false; } else if (g.Equals('\\')) c = true; else if (d && !g.Equals('"')) e.Append(g); else if (g.Equals('"')) d = !d; else if (g.Equals(' ')) { b.add(e.ToString()); e.Clear(); } else e.Append(g); } if (e.Length > 0) b.add(e.ToString()); h.Add(a, b); } return h[a];
 }