Пример #1
0
 private static int Memorize(BufferedTextReader sr, int nextToken, TextWriter sw)
 {
     if (nextToken == '"')
     {
         return(MemoizeSkipString(sr, sw));
     }
     else if (nextToken == '{')
     {
         nextToken = MemoizeGetNextToken(sr, sw);
         if (nextToken == '}')
         {
             return(MemoizeGetNextToken(sr, sw));
         }
         if (nextToken == '"')
         {
             nextToken = MemoizeSkipString(sr, sw);
         }
         else
         {
             throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
         }
         if (nextToken != ':')
         {
             throw new SerializationException("Expecting ':' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
         }
         nextToken = MemoizeGetNextToken(sr, sw);
         nextToken = Memorize(sr, nextToken, sw);
         while (nextToken == ',')
         {
             nextToken = MemoizeGetNextToken(sr, sw);
             if (nextToken == '"')
             {
                 nextToken = MemoizeSkipString(sr, sw);
             }
             else
             {
                 throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
             }
             if (nextToken != ':')
             {
                 throw new SerializationException("Expecting ':' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
             }
             nextToken = MemoizeGetNextToken(sr, sw);
             nextToken = Memorize(sr, nextToken, sw);
         }
         if (nextToken != '}')
         {
             throw new SerializationException("Expecting '}' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
         }
         return(MemoizeGetNextToken(sr, sw));
     }
     else if (nextToken == '[')
     {
         nextToken = MemoizeGetNextToken(sr, sw);
         nextToken = Memorize(sr, nextToken, sw);
         while (nextToken == ',')
         {
             nextToken = MemoizeGetNextToken(sr, sw);
             nextToken = Memorize(sr, nextToken, sw);
         }
         if (nextToken != ']')
         {
             throw new SerializationException("Expecting ']' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
         }
         return(MemoizeGetNextToken(sr, sw));
     }
     else
     {
         while (nextToken != ',' && nextToken != '}' && nextToken != ']' && nextToken != -1)
         {
             nextToken = sr.Read();
             sw.Write((char)nextToken);
         }
         return(MoveToNextToken(sr, nextToken));
     }
 }