| Copyright | (c) 2019-2021 Vaclav Svejcar |
|---|---|
| License | BSD-3-Clause |
| Maintainer | vaclav.svejcar@gmail.com |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Headroom.Data.Text
Contents
Description
Module containing bunch of useful functions for working with text.
Documentation
Similar to commonPrefixes, but tries to find common prefix for all
lines in given text.
>>>commonLinesPrefix "-- first\n-- second\n-- third"Just "-- "
replaceFirst :: Text -> Text -> Text -> Text Source #
Similar to replace, but replaces only very first occurence of pattern.
>>>replaceFirst ":" "/" "a : b : c""a / b : c"
Working with text lines
Arguments
| :: (Text -> Text) | function to map over individual lines |
| -> Text | input text |
| -> Text | resulting text |
Maps given function over individual lines of the given text.
>>>mapLines ("T: " <>) "foo zz\nbar""T: foo zz\nT: bar"
Arguments
| :: Foldable t | |
| => (Text -> t Text) | function to map over inividual lines |
| -> Text | input text |
| -> Text | resulting text |
Similar to mapLines, but the mapping function returns Foldable, which
gives some more control over outcome. After mapping over all individual
lines, results are folded and concatenated, which allows for example
filtering out some lines.
>>>mapLinesF (\l -> if l == "bar" then Nothing else Just l) "foo\nbar""foo"
Similar to unlines, but does not automatically adds n at the end
of the text. Advantage is that when used together with toLines, it doesn't
ocassionaly change the newlines ad the end of input text:
>>>fromLines . toLines $ "foo\nbar""foo\nbar"
>>>fromLines . toLines $ "foo\nbar\n""foo\nbar\n"
Other examples:
>>>fromLines []""
>>>fromLines ["foo"]"foo"
>>>fromLines ["first", "second"]"first\nsecond"
>>>fromLines ["first", "second", ""]"first\nsecond\n"
Similar to lines, but does not drop trailing newlines from output.
Advantage is that when used together with fromLines, it doesn't ocassionaly
change the newlines ad the end of input text:
>>>fromLines . toLines $ "foo\nbar""foo\nbar"
>>>fromLines . toLines $ "foo\nbar\n""foo\nbar\n"
Other examples:
>>>toLines ""[]
>>>toLines "first\nsecond"["first","second"]
>>>toLines "first\nsecond\n"["first","second",""]