Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implements sequential string replacements based on the Aho-Corasick algorithm.
Synopsis
- data Replacer = Replacer {}
- build :: CaseSensitivity -> [(Needle, Replacement)] -> Replacer
- compose :: Replacer -> Replacer -> Maybe Replacer
- run :: Replacer -> Text -> Text
- runWithLimit :: Replacer -> CodeUnitIndex -> Text -> Maybe Text
- type Needle = Text
- type Replacement = Text
- data Payload = Payload {
- needlePriority :: !Priority
- needleLength :: !CodeUnitIndex
- needleReplacement :: !Replacement
State machine
A state machine used for efficient replacements with many different needles.
Instances
Eq Replacer Source # | |
Show Replacer Source # | |
Generic Replacer Source # | |
Hashable Replacer Source # | |
Defined in Data.Text.AhoCorasick.Replacer | |
ToJSON Replacer Source # | |
Defined in Data.Text.AhoCorasick.Replacer | |
FromJSON Replacer Source # | |
NFData Replacer Source # | |
Defined in Data.Text.AhoCorasick.Replacer | |
type Rep Replacer Source # | |
Defined in Data.Text.AhoCorasick.Replacer type Rep Replacer = D1 (MetaData "Replacer" "Data.Text.AhoCorasick.Replacer" "alfred-margaret-1.1.1.0-C7p4DoDIXY7azqNtjX433" False) (C1 (MetaCons "Replacer" PrefixI True) (S1 (MetaSel (Just "replacerCaseSensitivity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CaseSensitivity) :*: S1 (MetaSel (Just "replacerSearcher") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Searcher Payload)))) |
build :: CaseSensitivity -> [(Needle, Replacement)] -> Replacer Source #
Build an Aho-Corasick automaton that can be used for performing fast sequential replaces.
Case-insensitive matching performs per-letter language-agnostic case folding. Therefore, it will work in most cases, but not in languages where case folding depends on the context of the character in question.
We need to revisit this algorithm when we want to implement full Unicode support.
compose :: Replacer -> Replacer -> Maybe Replacer Source #
Return the composition replacer2
after replacer1
, if they have the same
case sensitivity. If the case sensitivity differs, Nothing is returned.
runWithLimit :: Replacer -> CodeUnitIndex -> Text -> Maybe Text Source #
type Replacement = Text Source #
Descriptive type alias for replacements.
Payload | |
|
Instances
Eq Payload Source # | |
Show Payload Source # | |
Generic Payload Source # | |
Hashable Payload Source # | |
Defined in Data.Text.AhoCorasick.Replacer | |
ToJSON Payload Source # | |
Defined in Data.Text.AhoCorasick.Replacer | |
FromJSON Payload Source # | |
NFData Payload Source # | |
Defined in Data.Text.AhoCorasick.Replacer | |
type Rep Payload Source # | |
Defined in Data.Text.AhoCorasick.Replacer |