Beispiel #1
0
        private void parse(String s, String delimCh, String quoteCh, bool inclQuoteCh)
        {
            this.s      = s;
            this.dCh    = delimCh;
            this.qCh    = quoteCh;
            this.tokens = new List();
            bool inLiteral = false;
            char quoteChar = '\0';

            for (int i = 0; i < s.Length; i++)
            {
                char ch = s[i];
                if (ch == quoteChar)
                {
                    inLiteral = false;
                    quoteChar = '\0';
                    if (inclQuoteCh)
                    {
                        addTokChar(ch);
                    }
                }
                else if ((quoteChar == 0) && (this.qCh.IndexOf(ch) != -1))
                {
                    quoteChar = ch;
                    inLiteral = true;
                    if (inclQuoteCh)
                    {
                        addTokChar(ch);
                    }
                }
                else if (this.dCh.IndexOf(ch) != -1)
                {
                    if (i > 0)
                    {
                        if (inLiteral)
                        {
                            addTokChar(ch);
                        }
                        else
                        {
                            this.tokens.addElement(getTokString());
                            this.tokPos = 0;
                        }
                    }
                }
                else if (ch == '\\')
                {
                    if ((i < s.Length - 1) && (((!inLiteral) && (this.dCh.IndexOf(s[i + 1]) >= 0)) || (this.qCh.IndexOf(s[i + 1]) >= 0)))
                    {
                        addTokChar(s[++i]);
                    }
                    else
                    {
                        addTokChar(ch);
                    }
                }
                else
                {
                    addTokChar(ch);
                }
            }
            if (this.tokPos > 0)
            {
                this.tokens.addElement(getTokString());
            }
            this.enumvar = tokens.elements();
        }
Beispiel #2
0
 private void parse(String s, String delimCh, String quoteCh, bool inclQuoteCh)
 {
     this.s = s;
     this.dCh = delimCh;
     this.qCh = quoteCh;
     this.tokens = new List();
     bool inLiteral = false;
     char quoteChar = '\0';
     for (int i = 0; i < s.Length; i++)
     {
         char ch = s[i];
         if (ch == quoteChar)
         {
             inLiteral = false;
             quoteChar = '\0';
             if (inclQuoteCh)
             {
                 addTokChar(ch);
             }
         }
         else if ((quoteChar == 0) && (this.qCh.IndexOf(ch) != -1))
         {
             quoteChar = ch;
             inLiteral = true;
             if (inclQuoteCh)
             {
                 addTokChar(ch);
             }
         }
         else if (this.dCh.IndexOf(ch) != -1)
         {
             if (i > 0)
             {
                 if (inLiteral)
                 {
                     addTokChar(ch);
                 }
                 else
                 {
                     this.tokens.addElement(getTokString());
                     this.tokPos = 0;
                 }
             }
         }
         else if (ch == '\\')
         {
             if ((i < s.Length - 1) && (((!inLiteral) && (this.dCh.IndexOf(s[i + 1]) >= 0)) || (this.qCh.IndexOf(s[i + 1]) >= 0)))
             {
                 addTokChar(s[++i]);
             }
             else
             {
                 addTokChar(ch);
             }
         }
         else
         {
             addTokChar(ch);
         }
     }
     if (this.tokPos > 0)
     {
         this.tokens.addElement(getTokString());
     }
     this.enumvar = tokens.elements();
 }