zwilias / elm-utf-tools / String.UTF16

For some reason want to reason about strings as if they were UTF-16 sequences?

Technically, that's what they are, but Elm allows treating them as Unicode codepoints, which is super-convenient. Occasionally, however, you may find yourself in need of some old fashioned UTF-16 bytes, so here you go!

length : String -> Basics.Int

Count the number of UTF-16 bytes in a String.

Note that this should always equal String.length in Elm.

toBytes : String -> List Basics.Int

Turn a String into a list of UTF-16 bytes.

toString : List Basics.Int -> String

Turn a list of UTF-16 bytes into a String.

foldl : (Basics.Int -> acc -> acc) -> acc -> String -> acc