コード例 #1
0
ファイル: TestCOM.cs プロジェクト: optimus-code/Q2Sharp
        public static void Main(string[] args)
        {
            string test = "testrene = \\\"ein mal eins\\\"; a=3 ";

            Com.ParseHelp ph = new ParseHelp(test);
            while (!ph.IsEof())
            {
                System.Diagnostics.Debug.WriteLine("[" + Com.Parse(ph) + "]");
            }
            System.Diagnostics.Debug.WriteLine("OK!");
            test = " testrene = \\\"ein mal eins\\\"; a=3";
            ph   = new ParseHelp(test);
            while (!ph.IsEof())
            {
                System.Diagnostics.Debug.WriteLine("[" + Com.Parse(ph) + "]");
            }
            System.Diagnostics.Debug.WriteLine("OK!");
        }
コード例 #2
0
ファイル: Com.cs プロジェクト: optimus-code/Q2Sharp
        public static String Parse(ParseHelp hlp)
        {
            Int32 c;
            var   len = 0;

            if (hlp.data == null)
            {
                return("");
            }

            while (true)
            {
                hlp.Skipwhites();
                if (hlp.IsEof())
                {
                    hlp.data = null;
                    return("");
                }

                if (hlp.Getchar() == '/')
                {
                    if (hlp.Nextchar() == '/')
                    {
                        hlp.Skiptoeol();
                        continue;
                    }
                    else
                    {
                        hlp.Prevchar();
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            if (hlp.Getchar() == '\\')
            {
                hlp.Nextchar();
                while (true)
                {
                    c = hlp.Getchar();
                    hlp.Nextchar();
                    if (c == '\\' || c == 0)
                    {
                        return(new String(com_token, 0, len));
                    }

                    if (len < Defines.MAX_TOKEN_CHARS)
                    {
                        com_token[len] = ( Char )c;
                        len++;
                    }
                }
            }

            c = hlp.Getchar();
            do
            {
                if (len < Defines.MAX_TOKEN_CHARS)
                {
                    com_token[len] = ( Char )c;
                    len++;
                }

                c = hlp.Nextchar();
            }while (c > 32);
            if (len == Defines.MAX_TOKEN_CHARS)
            {
                Com.Printf("Token exceeded " + Defines.MAX_TOKEN_CHARS + " chars, discarded.\\n");
                len = 0;
            }

            return(new String(com_token, 0, len));
        }