Naive string decoding

This commit is contained in:
Ayaz Hafiz 2022-08-01 09:56:48 -05:00
parent d1880cae76
commit 03463a2a5e
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58

View File

@ -316,8 +316,24 @@ decodeBool = Decode.custom \bytes, @Json {} ->
else
{ result: Err TooShort, rest: bytes }
# FIXME
decodeString = Decode.custom \bytes, @Json {} -> { result: Err TooShort, rest: bytes }
decodeString = Decode.custom \bytes, @Json {} ->
{ before, others: afterStartingQuote } = List.split bytes 1
if
before == [asciiByte '"']
then
# TODO: handle escape sequences
{ taken: strSequence, rest } = takeWhile afterStartingQuote \n -> n != asciiByte '"'
when Str.fromUtf8 strSequence is
Ok s ->
{ others: afterEndingQuote } = List.split rest 1
{ result: Ok s, rest: afterEndingQuote }
Err _ -> { result: Err TooShort, rest }
else
{ result: Err TooShort, rest: bytes }
# FIXME
decodeList = \decodeElem -> Decode.custom \bytes, @Json {} ->