opethe1st / GoJson

Practising my golang skills
3 stars 0 forks source link

Could rewrite as #10

Closed opethe1st closed 5 years ago

opethe1st commented 5 years ago

https://github.com/opethe1st/GoJson/blob/943435f24b71ab954f52d910ed0931816e51ead5/load.go#L185-L201

opethe1st commented 5 years ago
func loadSequence(iter *iterator) []interface{} { 
    seq := make([]interface{}, 0)
    consume(iter, '[') 
        if  iter.Current() == ']' {
                return seq
        }
    var item interface{} 
    for iter.HasNext() { 
        item = load(iter) 
        seq = append(seq, item) 
        consumeWhiteSpace(iter) 
        if iter.Current() == ']' { 
            break 
        } else {
                consume(iter, ',')
                }

if iter.Current() return nil when offset is bigger than or equal to the length of the string

opethe1st commented 5 years ago

Figured this out too. iter.Current() can return 0 which is the null character that should never be in a valid string so it works nicely

opethe1st commented 5 years ago

Also rewrote this so I check the ']' condition at the beginning

opethe1st commented 5 years ago

fixed in https://github.com/opethe1st/GoJson/pull/13