miniBill/elm-utf-tools/1.0.0

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 -> Int

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

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

fromString : Endianness -> String -> Bytes

Turn a String into a the corresponding UTF-16 bytes.

toString : Endianness -> Bytes -> Maybe String

Turn UTF-16 bytes into a String.

fromList : List Int -> String

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

toList : String -> List Int

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

foldr : (Int -> acc -> acc) -> acc -> String -> acc

Like String.foldr, but working on utf16 bytes as opposed to Chars.