MarcosLopezC / LightJson

A simple JSON library for C#.
MIT License
60 stars 21 forks source link

Support read Hex #39

Closed oneonce closed 6 years ago

oneonce commented 7 years ago

JsonReader.cs

    private void ReadHexNum(StringBuilder builder)
    {
        while (this.scanner.CanRead && char.IsLetterOrDigit(this.scanner.Peek()))
        {
            builder.Append(this.scanner.Read());
        }
    }

private JsonValue ReadNumber() { .... if (this.scanner.CanRead && char.ToLowerInvariant(this.scanner.Peek()) == 'e') { ... }

if (this.scanner.CanRead && char.ToLowerInvariant(this.scanner.Peek()) == 'x')
{
    char ch = this.scanner.Read();
    builder.Clear();
    ReadHexNum(builder);

    if (8 >= builder.Length)
    {
        return Convert.ToUInt32(builder.ToString(), 16);
    }
    else if (16 >= builder.Length)
    {
        return Convert.ToUInt64(builder.ToString(), 16);
    }
    else // Convert to JsonArray? or not support?
    {
        //JsonArray ja = new JsonArray();
    }
}

... }

MarcosLopezC commented 7 years ago

@oneonce What is this?

oneonce commented 7 years ago

I suggest "LightJson" should support read Hexadecimal number from document/string;

MarcosLopezC commented 6 years ago

I think this is something better left for the client code to do.