-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Simple text replacements from a list of search/replace pairs
--
-- A library and a command-line application for simple string
-- replacements in text files.
--
-- The search for strings to replace is performed left-to-right,
-- preferring longer matches to shorter ones.
@package text-replace
@version 0.1.0.3
module Text.Replace
-- | Apply a list of replacement rules to a string
--
-- The search for strings to replace is performed left-to-right,
-- preferring longer matches to shorter ones.
--
-- Internally, the list will be converted to a ReplaceMap using
-- listToMap. If the list contains more than one replacement for
-- the same search string, the last mapping is used, and earlier mappings
-- are ignored.
--
-- If you are going to be applying the same list of rules to multiple
-- input strings, you should first convert the list to a Trie
-- using listToTrie and then use replaceWithTrie instead.
replaceWithList :: Foldable f => f Replace -> Text -> Text
-- | Apply a map of replacement rules to a string
--
-- The search for strings to replace is performed left-to-right,
-- preferring longer matches to shorter ones.
--
-- If you are going to be applying the same list of rules to multiple
-- input strings, you should first convert the Map to a
-- Trie using mapToTrie and then use replaceWithTrie
-- instead.
replaceWithMap :: ReplaceMap -> Text -> Text
-- | Apply a trie of replacement rules to a string
--
-- The search for strings to replace is performed left-to-right,
-- preferring longer matches to shorter ones.
--
-- To construct a Trie, you may use listToTrie or
-- mapToTrie.
replaceWithTrie :: Trie -> Text -> Text
-- | A replacement rule
--
-- Replace "abc" "xyz" means "When you encounter the string
-- abc in the input text, replace it with
-- xyz."
--
-- The first argument must be a non-empty string, because there is no
-- sensible way to interpret "replace all occurrences of the empty
-- string."
data Replace
Replace :: Text' -> Text -> Replace
-- | A string we're looking for
[replaceFrom] :: Replace -> Text'
-- | A string we're replacing it with
[replaceTo] :: Replace -> Text
-- | A map where the keys are strings we're looking for and the values are
-- strings with which we're replacing a key that we find
--
-- You may use listToMap to construct a ReplaceMap from a
-- list of replacement rules, and you may use mapToAscList to
-- convert back to a list.
type ReplaceMap = Map Text' Text
-- | Construct a replacement map from a list of replacement rules
--
-- If the list contains more than one replacement for the same search
-- string, the last mapping is used, and earlier mappings are ignored.
listToMap :: Foldable f => f Replace -> ReplaceMap
-- | Convert a replacement map to a list of replacement rules
--
-- The rules in the list will be sorted according to their
-- replaceFrom field in ascending order.
mapToAscList :: ReplaceMap -> [Replace]
-- | A representation of a ReplaceMap designed for efficient lookups
-- when we perform the replacements in replaceWithTrie
--
-- You may construct a Trie using listToTrie or
-- mapToTrie.
type Trie = Map Char Trie'
-- | A variant of Trie which may contain a value at the root of the
-- tree
data Trie'
Trie' :: Maybe Text -> Trie -> Trie'
[trieRoot] :: Trie' -> Maybe Text
[trieBranches] :: Trie' -> Trie
-- | Convert a list of replacement rules to a trie, which is used to
-- efficiently implement replaceWithTrie
--
-- If the list contains more than one replacement for the same search
-- string, the last mapping is used, and earlier mappings are ignored.
listToTrie :: Foldable f => f Replace -> Trie
-- | Convert a list of replacement rules to a Trie, where the rules
-- must be sorted in ascending order by the replaceFrom field
--
-- 🌶️ Warning: this precondition is not checked. If you are not sure, it
-- is safer to use listToTrie instead.
ascListToTrie :: Foldable f => f Replace -> Trie
-- | Convert a replacement map to a trie, which is used to efficiently
-- implement replaceWithTrie
mapToTrie :: ReplaceMap -> Trie
-- | Draws a text diagram of a trie; useful for debugging
drawTrie :: Trie -> Text
-- | Non-empty text
data Text'
Text' :: Char -> Text -> Text'
-- | The first character of a non-empty string
[text'head] :: Text' -> Char
-- | All characters of a non-empty string except the first
[text'tail] :: Text' -> Text
-- | Convert an ordinary String to a non-empty Text'
--
-- 🌶️ Warning: text'fromString "" = ⊥
text'fromString :: String -> Text'
-- | Convert an ordinary Text to a non-empty Text'
--
-- 🌶️ Warning: text'fromText "" = ⊥
text'fromText :: Text -> Text'
instance GHC.Classes.Ord Text.Replace.Text'
instance GHC.Classes.Eq Text.Replace.Text'
instance GHC.Show.Show Text.Replace.Replace
instance GHC.Classes.Eq Text.Replace.Replace
instance GHC.Show.Show Text.Replace.Trie'
instance GHC.Classes.Eq Text.Replace.Trie'
instance GHC.Show.Show Text.Replace.Text'
instance Data.String.IsString Text.Replace.Text'