Ejemplo n.º 1
0
        private static JsonValue ParseJsonValue(JsonTokenizer tokenizer, JsonToken top)
        {
            return(top.Type switch {
                JsonTokenType.LBrace => (JsonValue)ParseJsonObject(tokenizer, top),
                JsonTokenType.LBracket => ParseJsonArray(tokenizer, top),
                JsonTokenType.LiteralTrue => new JsonBool(true),
                JsonTokenType.LiteralFalse => new JsonBool(false),
                JsonTokenType.LiteralNull => new JsonNull(),
                JsonTokenType.String => new JsonString(EscapeSequenceConverter.Decode(top.Value)),
                JsonTokenType.Number => new JsonNumber(top.Value.ToString()),

                /*
                 * case JsonTokenType.RBracket:
                 * case JsonTokenType.RBrace:
                 * case JsonTokenType.Colon:
                 * case JsonTokenType.Comma:
                 * case JsonTokenType.NotAToken:
                 * case anything else:
                 */
                _ => throw new Exception(),
            });
 public void DecodeBase()
 {
     Assert.Equal("\b\r\t\n\0\f\"\\", EscapeSequenceConverter.Decode(@"\b\r\t\n\0\f\""\\"));
     Assert.Equal("\\\\b\\r\\t\\n\\0\\f\\\"", EscapeSequenceConverter.Decode(@"\\\\b\\r\\t\\n\\0\\f\\"""));
 }
 public void EncodeUnicode()
 {
     Assert.Equal(@"\b\r\t\n\0\f\""\\", EscapeSequenceConverter.EncodeToAscii("\b\r\t\n\0\f\"\\"));
     Assert.Equal(@"\\\\b\\r\\t\\n\\0\\f\\\""\u0435\u0442\u043e", EscapeSequenceConverter.EncodeToAscii("\\\\b\\r\\t\\n\\0\\f\\\"ето"));
 }
 public void EncodeBase()
 {
     Assert.Equal(@"\b\r\t\n\0\f\""\\", EscapeSequenceConverter.Encode("\b\r\t\n\0\f\"\\"));
     Assert.Equal(@"\\\\b\\r\\t\\n\\0\\f\\\""ето", EscapeSequenceConverter.Encode("\\\\b\\r\\t\\n\\0\\f\\\"ето"));
 }
 public void DecodeResume()
 {
     Assert.Equal("ara\r\\g\\", EscapeSequenceConverter.Decode(@"ara\r\g\"));
     Assert.Equal("\\ufool\\u433", EscapeSequenceConverter.Decode(@"\ufool\u433"));
 }
 public void DecodeUnicode()
 {
     Assert.Equal("スgokuかわいい", EscapeSequenceConverter.Decode(@"\u30b9gok\u0075かわい\u3044"));
 }
Ejemplo n.º 7
0
 internal override void Stringify(JsonStringifyOption config, IndentedWriter iw)
 {
     iw.Write('\"');
     iw.Write(config.HasFlag(JsonStringifyOption.AsciiOnly) ? EscapeSequenceConverter.EncodeToAscii(Value) : EscapeSequenceConverter.Encode(Value));
     iw.Write('\"');
 }