-- 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.0.0.1 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 -> String -> String -- | 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 -> String -> String -- | 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 -> String -> String -- | 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 :: String' -> String -> Replace -- | A string we're looking for [replaceFrom] :: Replace -> String' -- | A string we're replacing it with [replaceTo] :: Replace -> String -- | 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 String' String -- | Construct a ReplaceMap 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 String -> Trie -> Trie' [trieRoot] :: Trie' -> Maybe String [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 -> String -- | Non-empty string. newtype String' String' :: (NonEmpty Char) -> String' -- | Convert an ordinary String to a non-empty String'. -- -- 🌶️ Warning: string'fromString "" = ⊥ string'fromString :: String -> String' -- | The first character of a non-empty string. string'head :: String' -> Char -- | All characters of a non-empty string except the first. string'tail :: String' -> String instance GHC.Show.Show Text.Replace.Trie' instance GHC.Classes.Eq Text.Replace.Trie' instance GHC.Show.Show Text.Replace.Replace instance GHC.Classes.Eq Text.Replace.Replace instance GHC.Classes.Ord Text.Replace.String' instance GHC.Classes.Eq Text.Replace.String' instance GHC.Show.Show Text.Replace.String' instance Data.String.IsString Text.Replace.String'