Пример #1
0
        private static string readstring(PushbackTextReader r)
        {
            int first = r.Read();

            if (first == -1)
            {
                throw new ArgumentException(BADEND + ", at line " + r.Line);
            }
            if (breakstring(first))
            {
                throw new ArgumentException(BADCHAR + ((char)first) + "', at line " + r.Line);
            }

            StringBuilder sb = new StringBuilder();

            if (first != '\'' && first != '"')
            {
                r.Unread(first);
                first = 0;
            }

            int c;

            while (true)
            {
                c = r.Read();
                if (c == '\\')
                {
                    c = r.Read();
                    if (c == -1)
                    {
                        throw new ArgumentException(BADEND + ", at line " + r.Line);
                    }
                }
                else if (first != 0 && c == first)
                {
                    break;
                }
                else if (first == 0)
                {
                    if (isWhite(c) || c == -1)
                    {
                        break;
                    }
                    if (breakstring(c))
                    {
                        r.Unread(c);
                        break;
                    }
                }
                else if (c == -1)
                {
                    throw new ArgumentException(BADEND + ", at line " + r.Line);
                }
                sb.Append((char)c);
            }
            return(sb.ToString());
        }
Пример #2
0
        private static int next(PushbackTextReader r)
        {
            int c = nextConsumed(r);

            r.Unread(c);
            return(c);
        }