newline-0.0.1.0: newline specifications as values
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.Newline

Description

Specify newline character sequences and algorithms generic over them.

Note that this module only understands simple character strings as newlines, whereas some encodings have complex algorithmically-defined newlines. Of course, most users will be interested in only Unix- or Windows-style newline.

Information for the pattern synonyms of this module comes from https://en.wikipedia.org/wiki/Newline

Synopsis

Newline Type

data Newline Source #

Specification for a newline character sequence

Constructors

OtherNl !Char !Text 

Instances

Instances details
Show Newline Source # 
Instance details

Defined in Text.Newline

Eq Newline Source # 
Instance details

Defined in Text.Newline

Methods

(==) :: Newline -> Newline -> Bool #

(/=) :: Newline -> Newline -> Bool #

Common Newlines

pattern Unix :: Newline Source #

For Unix and Unix-like systems. It's by far the most common (and easy-to-recognize) newline, so when in doubt, don't generate anything else.

pattern Windows :: Newline Source #

For DOS and DOS-like systems, including Microsoft Windows. Still common, and in being so, is a pain.

pattern ClassicMac :: Newline Source #

For a variety of older machines, such as Commodore 8-bit machines, ZX Spectrum, TRS-80, Apple II series, the classic Mac OS, and the MIT Lisp Machine.

pattern PrePosixQnx :: Newline Source #

For QNX version <4

pattern RiscOsSpool :: Newline Source #

For RISC OS spoolet text output.

Reportedly also used for Acorn BBC, but that machine is also listed as using `"r"`. The manual (http:/stardot.org.ukmirrorswww.bbcdocs.comfilebaseessentialsBBC%20Microcomputer%20Advanced%20User%20Guide.pdf) does back up this assertion, though.

pattern IbmMainframe :: Newline Source #

EBCDIC systems — mainly IBM mainframe systems, including zOS (OS390) and IBM i (OS/400) — use NL (New Line, 0x15)[8] as the character combining the functions of line feed and carriage return. The equivalent Unicode character (0x85) is called NEL (Next Line).

Citation: IBM System/360 Reference Data Card, Publication GX20-1703, IBM Data Processing Division, White Plains, NY

Text Operations

Split Lines

breakLine :: [Newline] -> Text -> (Text, Maybe (Newline, Text)) Source #

Split one line from the input. Also returns the newline that was matched and any following text. If no newline was matched, then all the input is placed in the first return value.

Join Lines

linesUnix :: Text -> [Text] Source #

Equivalent to 'linesBy [Unix]'.

linesBy :: [Newline] -> Text -> [(Text, Maybe Newline)] Source #

Split text into lines where any of the given Newline values are considered as a newline. Returns not just the text of each line, but also the matched newline itself. Returns Nothing for the Newline for a line that was ended by the end of input.

unlinesBy :: (IsString str, Monoid str, Foldable f) => Newline -> f str -> str Source #

Join lines by inserting newlines between them.

Mirrors unlines, but allows different line endings.

Conversion

pattern NlText :: Text -> Newline Source #

Construct/deconstruct Newline as a whole Text. The constructor is partial: it is undefined constructed with an empty string.

toText :: Newline -> Text Source #

Convert a newline specification to the text it matches.

fromText :: Text -> Maybe Newline Source #

Convert text into a newline specification that matches it.

toString :: Newline -> String Source #

As toText, but targeting the String type.