ProtocolBuffers.TokenReader.ReadNext C# (CSharp) Method

ReadNext() public method

public ReadNext ( ) : string
return string
        public string ReadNext()
        {
            string c;	//Character

            //Skip whitespace characters
            while (true) {
                c = GetChar ();
                if (whitespace.Contains (c))
                    continue;
                break;
            }

            //Determine token type
            if (singletoken.Contains (c))
                return c.ToString ();

            //Follow token
            string token = c;
            bool parseString = false;
            bool parseComment = false;

            if (token == "/")
                parseComment = true;
            if (token == "\"") {
                parseString = true;
                token = "";
            }

            while (true) {
                c = GetChar ();
                if (parseComment) {
                    if (c == "\r" || c == "\n")
                        return token;
                } else if (parseString) {
                    if (c == "\"")
                        return token;
                } else if (whitespace.Contains (c) || singletoken.Contains (c)) {
                    offset -= 1;
                    return token;
                }

                token += c;
            }
        }

Usage Example

Exemplo n.º 1
0
        static MessageEnum ParseEnum(TokenReader tr, Message parent)
        {
            MessageEnum me = new MessageEnum (parent);
            me.Comments = lastComment;
            lastComment = null;
            me.ProtoName = tr.ReadNext ();

            if (tr.ReadNext () != "{")
                throw new ProtoFormatException ("Expected: {");

            while (true) {
                string name = tr.ReadNext ();

                if (ParseComment (name))
                    continue;

                if (name == "}")
                    return me;

                //Ignore options
                if (name == "option") {
                    ParseOption (tr, null);
                    lastComment = null;
                    continue;
                }

                if (tr.ReadNext () != "=")
                    throw new ProtoFormatException ("Expected: =");

                int id = int.Parse (tr.ReadNext ());

                me.Enums.Add (name, id);
                if (lastComment != null)
                    me.EnumsComments.Add (name, lastComment);
                lastComment = null;

                if (tr.ReadNext () != ";")
                    throw new ProtoFormatException ("Expected: ;");
            }
        }
All Usage Examples Of ProtocolBuffers.TokenReader::ReadNext