GHC.Data.ShortText

ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Data.ShortText

Contents

- ShortText
  - Conversion to and from String
  - Operations

Description

An Unicode string for internal GHC use. Meant to replace String in places where being a lazy linked is not very useful and a more memory efficient data structure is desirable.

Synopsis

- newtype ShortText = ShortText {
  - contents :: ShortByteString
  }
- singleton :: Char -> ShortText
- pack :: String -> ShortText
- unpack :: ShortText -> String
- codepointLength :: ShortText -> Int
- byteLength :: ShortText -> Int
- null :: ShortText -> Bool
- splitFilePath :: ShortText -> [ShortText]
- head :: ShortText -> Char
- stripPrefix :: ShortText -> ShortText -> Maybe ShortText

# ShortText

newtype ShortText #

A `ShortText` is a modified UTF-8 encoded string meant for short strings like file paths, module descriptions, etc.

Constructors

ShortText |
Fields contents :: ShortByteString

#### Instances

Instances details

Binary ShortText # |
Instance details Defined in GHC.Data.ShortText Methods put :: ShortText -> Put # get :: Get ShortText # putList :: [ShortText] -> Put #
NFData ShortText # |
Instance details Defined in GHC.Data.ShortText Methods rnf :: ShortText -> () #
Monoid ShortText # |
Instance details Defined in GHC.Data.ShortText Methods mempty :: ShortText # mappend :: ShortText -> ShortText -> ShortText # mconcat :: [ShortText] -> ShortText #
Semigroup ShortText # |
Instance details Defined in GHC.Data.ShortText Methods (<>) :: ShortText -> ShortText -> ShortText # sconcat :: NonEmpty ShortText -> ShortText # stimes :: Integral b => b -> ShortText -> ShortText #
IsString ShortText # |
Instance details Defined in GHC.Data.ShortText Methods fromString :: String -> ShortText #
Show ShortText # |
Instance details Defined in GHC.Data.ShortText Methods showsPrec :: Int -> ShortText -> ShowS # show :: ShortText -> String # showList :: [ShortText] -> ShowS #
Eq ShortText # |
Instance details Defined in GHC.Data.ShortText Methods (==) :: ShortText -> ShortText -> Bool # (/=) :: ShortText -> ShortText -> Bool #
Ord ShortText # |
Instance details Defined in GHC.Data.ShortText Methods compare :: ShortText -> ShortText -> Ordering # (<) :: ShortText -> ShortText -> Bool # (<=) :: ShortText -> ShortText -> Bool # (>) :: ShortText -> ShortText -> Bool # (>=) :: ShortText -> ShortText -> Bool # max :: ShortText -> ShortText -> ShortText # min :: ShortText -> ShortText -> ShortText #

## Conversion to and from String

singleton :: Char -> ShortText #

Create a singleton

pack :: String -> ShortText #

O(n) Convert a `String` into a `ShortText`.

unpack :: ShortText -> String #

O(n) Convert a `ShortText` into a `String`.

## Operations

codepointLength :: ShortText -> Int #

O(n) Returns the length of the `ShortText` in characters.

byteLength :: ShortText -> Int #

O(1) Returns the length of the `ShortText` in bytes.

null :: ShortText -> Bool #

O(1) Test whether the `ShortText` is the empty string.

splitFilePath :: ShortText -> [ShortText] #

O(n) Split a `ShortText` representing a file path into its components by separating on the file separator characters for this platform.

head :: ShortText -> Char #

O(1) Returns the first UTF-8 codepoint in the `ShortText`. Depending on the string in question, this may or may not be the actual first character in the string due to Unicode non-printable characters.

stripPrefix :: ShortText -> ShortText -> Maybe ShortText #

O(n) The `stripPrefix` function takes two `ShortText`s and returns `Just` the remainder of the second iff the first is its prefix, and otherwise Nothing.