Hi! I’m trying to use elm/parser to parse fixed length strings. This is what I have come up with so far:
cString : Int -> Parser String
cString length =
getChompedString <|
loop 0 (helper length)
helper : Int -> Int -> Parser (Step Int Int)
helper length count =
if length == count then
succeed () |> map (\_ -> Done count)
else
succeed (Loop (count + 1))
|. chompIf (\_ -> True)
Is there a better way? If the name “cString” didn’t give at away already, I’m abusing elm/parser to parse a binary file. The file contents sit in a String, where I have made sure every Char code is below 256. So far it works very well.