purescript-0.11.2: PureScript Programming Language Compiler

Safe HaskellNone




data PSString Source #

Strings in PureScript are sequences of UTF-16 code units, which do not necessarily represent UTF-16 encoded text. For example, it is permissible for a string to contain *lone surrogates,* i.e. characters in the range U+D800 to U+DFFF which do not appear as a part of a surrogate pair.

The Show instance for PSString produces a string literal which would represent the same data were it inserted into a PureScript source file.

Because JSON parsers vary wildly in terms of how they deal with lone surrogates in JSON strings, the ToJSON instance for PSString produces JSON strings where that would be safe (i.e. when there are no lone surrogates), and arrays of UTF-16 code units (integers) otherwise.

decodeString :: PSString -> Maybe Text Source #

Attempt to decode a PSString as UTF-16 text. This will fail (returning Nothing) if the argument contains lone surrogates.

decodeStringEither :: PSString -> [Either Word16 Char] Source #

Decode a PSString as UTF-16. Lone surrogates in the input are represented in the output with the Left constructor; characters which were successfully decoded are represented with the Right constructor.

decodeStringWithReplacement :: PSString -> String Source #

Decode a PSString as UTF-16 text. Lone surrogates will be replaced with U+FFFD REPLACEMENT CHARACTER

prettyPrintString :: PSString -> Text Source #

Pretty print a PSString, using Haskell/PureScript escape sequences. This is identical to the Show instance except that we get a Text out instead of a String.

prettyPrintStringJS :: PSString -> Text Source #

Pretty print a PSString, using JavaScript escape sequences. Intended for use in compiled JS output.