purescript-strings icon indicating copy to clipboard operation
purescript-strings copied to clipboard

Add a `isWellFormed` function?

Open chtenb opened this issue 4 years ago • 2 comments

Could we provide a function that checks if a string is wellformed w.r.t. its encoding? In the JS backend this would be a check if there are lone surrogates present, in other backends this may be a different check. This would allow one to check if a string is well formed, after which one doesn't have to deal with invalid encoded string situations.

chtenb avatar Feb 21 '22 21:02 chtenb

Maybe a better API would return either the already-well-formed string or a new string derived by an implementation-defined transformation process (such as using replacement characters) on the input to ensure it is well-formed.

toWellFormed :: String -> Either String String

michaelficarra avatar Jun 29 '22 16:06 michaelficarra

Also see https://github.com/purescript/purescript/issues/3662#issuecomment-1065599015

michaelficarra avatar Jun 29 '22 20:06 michaelficarra