コード例 #1
0
 private ReadResults ReadKey(out string result)
 {
     Reader.SkipWhitespace();
     if (!Reader.CanRead())
     {
         result = default;
         return(ReadResults.Failure(CommandError.ExpectedKey().WithContext(Reader)));
     }
     return(Reader.ReadString(out result));
 }
コード例 #2
0
        public ReadResults ReadCompound(out INbtTag result)
        {
            CompoundNbtTag compound;

            result = compound = new CompoundNbtTag();
            ReadResults readResults = Reader.Expect('{');

            if (!readResults.Successful)
            {
                return(readResults);
            }
            Reader.SkipWhitespace();
            while (Reader.CanRead() && Reader.Peek() != '}')
            {
                int start = Reader.GetCursor();
                readResults = ReadKey(out string key);
                if (!readResults.Successful)
                {
                    return(readResults);
                }
                if (string.IsNullOrEmpty(key))
                {
                    Reader.SetCursor(start);
                    return(ReadResults.Failure(CommandError.ExpectedKey().WithContext(Reader)));
                }
                readResults = Reader.Expect(':');
                if (!readResults.Successful)
                {
                    return(readResults);
                }
                readResults = ReadValue(out INbtTag value);
                if (!readResults.Successful)
                {
                    return(readResults);
                }
                compound.Add(key, value);
                if (!HasElementSeparator())
                {
                    break;
                }
                if (Reader.CanRead())
                {
                    continue;
                }
                return(ReadResults.Failure(CommandError.ExpectedKey().WithContext(Reader)));
            }
            return(Reader.Expect('}'));
        }