regex-do-2.5: PCRE wrapper

Safe HaskellNone
LanguageHaskell2010

Text.Regex.Do.Pcre.Utf8.Replace

Description

see also Text.Regex.Do.Pcre.Ascii.Replace

Pattern & Body are wrapped in Utf8_ encoding tag. This tag adds clarity, prevents calling Ascii functions by mistake.

toByteString' converts String to Utf8_ ByteString

Documentation

class Replace all enc a repl where Source

Methods

replace :: all (Pattern (enc a)) -> repl (enc a) -> Body (enc a) -> a Source

Instances

Replace All Utf8_ String Replacement Source 
Replace All Utf8_ ByteString Replacement Source 
Replace All Utf8_ ByteString GroupReplacer Source
>>> replacer::GroupReplacer (Utf8_ ByteString)
        replacer = defaultReplacer 1 tweak1
         where tweak1 bs1 = toByteString' $
                               if bs1 == toByteString' "左" then
                                     "ー右ー"
                                      else "?"
>>> runFn1 `shouldBe` toByteString "100メートルー右ー折後、左"
       where runFn1 =
                let rx1 = Pattern $ toByteString' "(?<=ル)(左)"
                    body1 = Body $ toByteString' "100メートル左折後、左"
                in replace (All rx1) replacer body1        
Replace Once Utf8_ String Replacement Source 
Replace Once Utf8_ ByteString Replacement Source 
Replace Once Utf8_ ByteString GroupReplacer Source