Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Preliminary changes for UTF-8 support.
Browse files Browse the repository at this point in the history
This patch includes everything from the patch by mcmtroffaes
in #42 except the compUTF8 option itself, which is commented
out pending release of a version of pcre-regex-builtin that supports
it.

When a supporting version is released, we can remove the comment
here, conditionally on the version of pcre-regex-builtin.

See #42.
  • Loading branch information
jgm committed May 12, 2014
1 parent 2240f6f commit 38c082f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Text/Highlighting/Kate/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ module Text.Highlighting.Kate.Common where
#ifdef _PCRE_LIGHT
import Text.Regex.PCRE.Light.Char8
#else
import Data.ByteString.UTF8 (fromString, toString)
import System.IO.Unsafe (unsafePerformIO)
import Text.Regex.PCRE.String
import Text.Regex.PCRE.ByteString
#endif
import Text.Highlighting.Kate.Types
import Text.ParserCombinators.Parsec hiding (State)
Expand Down Expand Up @@ -186,11 +187,10 @@ compileRegex caseSensitive regexpStr =
let opts = [anchored] ++ [caseless | not caseSensitive]
in compile ('.' : convertOctal regexpStr) opts
#else
let opts = compAnchored + if caseSensitive
then 0
else compCaseless
let opts = compAnchored + {- compUTF8 + -}
if caseSensitive then 0 else compCaseless
in case unsafePerformIO $ compile opts (execNotEmpty)
('.' : convertOctal regexpStr) of
(fromString ('.' : convertOctal regexpStr)) of
Left _ -> error $ "Error compiling regex: " ++ show regexpStr
Right r -> r
#endif
Expand All @@ -199,8 +199,9 @@ matchRegex :: Regex -> String -> KateParser (Maybe [String])
#ifdef _PCRE_LIGHT
matchRegex r s = return $ match r s [exec_notempty]
#else
matchRegex r s = case unsafePerformIO (regexec r s) of
Right (Just (_, mat, _ , capts)) -> return $ Just (mat : capts)
matchRegex r s = case unsafePerformIO (regexec r (fromString s)) of
Right (Just (_, mat, _ , capts)) -> return $
Just $ map toString (mat : capts)
Right Nothing -> return Nothing
Left matchError -> fail $ show matchError
#endif
Expand Down
2 changes: 1 addition & 1 deletion highlighting-kate.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Library
cpp-options: -D_PCRE_LIGHT
else
Build-depends: regex-pcre-builtin
Build-Depends: parsec, mtl, blaze-html >= 0.4.2 && < 0.8
Build-Depends: parsec, mtl, blaze-html >= 0.4.2 && < 0.8, utf8-string
Exposed-Modules: Text.Highlighting.Kate
Text.Highlighting.Kate.Syntax
Text.Highlighting.Kate.Types
Expand Down

0 comments on commit 38c082f

Please sign in to comment.