HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefoundation-0.0.30Haskell2010

Foundation.String

Opaque packed String encoded in UTF8.

The type is an instance of IsString and IsList, which allow OverloadedStrings for string literal, and fromList to convert a [Char] (Prelude String) to a packed representation

{-# LANGUAGE OverloadedStrings #-}
s = "Hello World" :: String
s = fromList ("Hello World" :: Prelude.String) :: String

Each unicode code point is represented by a variable encoding of 1 to 4 bytes,

For more information about UTF8: https://en.wikipedia.org/wiki/UTF-8

  • 3 types
  • 14 values
  • Packagefoundation-0.0.30
  • Exports17
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceString.hs
newtypenewtype String
#

Opaque packed array of characters in the UTF8 encoding

Instances30IsList, Eq, Data, Ord, IsString, Semigroup, …
datadata Encoding
#

Various String Encoding that can be use to convert to and from bytes

Instances6Bounded, Enum, Eq, Data, Ord, Show

Convert a ByteArray to a string assuming a specific encoding.

It returns a 3-tuple of:

  • The string that has been succesfully converted without any error

  • An optional validation error

  • The remaining buffer that hasn't been processed (either as a result of an error, or because the encoded sequence is not fully available)

Considering a stream of data that is fetched chunk by chunk, it's valid to assume that some sequence might fall in a chunk boundary. When converting chunks, if the error is Nothing and the remaining buffer is not empty, then this buffer need to be prepended to the next chunk

Convert a UTF8 array of bytes to a String.

If there's any error in the stream, it will automatically insert replacement bytes to replace invalid sequences.

In the case of sequence that fall in the middle of 2 chunks, the remaining buffer is supposed to be preprended to the next chunk, and resume the parsing.

Convert a Byte Array representing UTF8 data directly to a string without checking for UTF8 validity

If the input contains invalid sequences, it will trigger runtime async errors when processing data.

In doubt, use fromBytes

valuetoBytes :: Encoding -> String -> UArray Word8
#

Convert a String to a bytearray in a specific encoding

if the encoding is UTF8, the underlying buffer is returned without extra allocation or any processing

In any other encoding, some allocation and processing are done to convert.

valuelines :: String -> [String]
#

Split lines in a string using newline as separation.

Note that carriage return preceding a newline are also strip for maximum compatibility between Windows and Unix system.

valueindices :: String -> String -> [Offset8]
#

Finds where are the insertion points when we search for a needle within an haystack.

valuetoBase64URL :: Bool -> String -> String
#

Transform string src to URL-safe base64 binary representation. The result will be either padded or unpadded, depending on the boolean padded argument.

Same as break but cut on a line feed with an optional carriage return.

This is the same operation as 'breakElem LF' dropping the last character of the string if it's a CR.

Also for efficiency reason (streaming), it returns if the last character was a CR character.