Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- data Newline = OtherNl !Char !Text
- pattern Unix :: Newline
- pattern Windows :: Newline
- pattern ClassicMac :: Newline
- pattern PrePosixQnx :: Newline
- pattern RiscOsSpool :: Newline
- pattern IbmMainframe :: Newline
- breakLine :: [Newline] -> Text -> (Text, Maybe (Newline, Text))
- linesUnix :: Text -> [Text]
- linesBy :: [Newline] -> Text -> [(Text, Maybe Newline)]
- unlinesBy :: (IsString str, Monoid str, Foldable f) => Newline -> f str -> str
- pattern NlText :: Text -> Newline
- toText :: Newline -> Text
- fromText :: Text -> Maybe Newline
- toString :: Newline -> String
Newline Type
Specification for a newline character sequence
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
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.