shortcut-links-0.5.0.0: Link shortcuts for use in text markup

Copyright(c) 2015-2019 Aelve
(c) 2019-2020 Kowainik
LicenseMPL-2.0
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellSafe
LanguageHaskell2010

ShortcutLinks.Utils

Description

Useful functions when writing your own link rules.

Synopsis

Documentation

replaceSpaces :: Char -> Text -> Text Source #

Replace spaces in text with chosen character (useful when processing queries containing spaces – they are often turned into “+” or “_”).

>>> replaceSpaces '_' "hi   there"
"hi___there"

titleFirst :: Text -> Text Source #

Convert the 1st character of a string to upper case.

This function is dumber than it could've been; when the 1st character doesn't have a single-character uppercase form (like “ß”), it is left intact instead of being converted (“Ss” in the case of “ß”). This is good, however; for instance, if the “proper” capitalisation rule was applied to e.g. Wikipedia links, a link to the article on “ß” would've been rendered as “Ss”, which is a redirect to “Schutzstaffel”.

tryStripPrefixCI :: Text -> Text -> Text Source #

Strip given prefix from a string, or do nothing if the string doesn't have given prefix.

This function is case-insensitive.

>>> tryStripPrefixCI "FOO" "FooBAR"
"BAR"
>>> tryStripPrefixCI "foo" "quux"
"quux"

stripPrefixCI :: Text -> Text -> Maybe Text Source #

Strip given prefix from a string.

This function is case-insensitive.

>>> stripPrefixCI "FOO" "FooBAR"
Just "BAR"
>>> stripPrefixCI "foo" "quux"
Nothing

orElse :: (Eq a, Monoid a) => a -> a -> a Source #

Choose the 2nd value if the 1st is empty (equal to mempty).

format :: FormatType r => Text -> r Source #

A printf-like function which fully supports Text as an input and output format and which uses {} instead of % to indicate placeholders. If you use it, don't forget to enable OverloadedStrings.

This is a lightweight alternative to something like the text-format package, and it's closer to printf and simpler to use.