@@ -60,14 +60,21 @@ classify :: ClassifyMap -> [Char] -> KClass
60classify table =
60classify table =
61 let standardClassifier = compile table
61 let standardClassifier = compile table
62 in \s -> case s of
62 in \s -> case s of
63− (c:_) | ord c >= 0xC2 && utf8Length (ord c) > length s -> Prefix -- beginning of an utf8 sequence
64− (c:_) | ord c >= 0xC2 -> classifyUtf8 s -- As soon as
63+ c:cs | ord c >= 0xC2 -> classifyUtf8 c cs
65− _ -> standardClassifier s
64+ _ -> standardClassifier s
67−classifyUtf8 :: [Char] -> KClass
66+classifyUtf8 :: Char -> [Char] -> KClass
68−classifyUtf8 s = case decode ((map (fromIntegral . ord) s) :: [Word8]) of
67+classifyUtf8 c cs =
68+ let n = utf8Length (ord c)
69+ (codepoint,rest) = splitAt n (c:cs)
71+ codepoint8 :: [Word8]
72+ codepoint8 = map (fromIntegral . ord) codepoint
74+ in case decode codepoint8 of
75+ _ | n < length codepoint -> Prefix
69− Just (unicodeChar, _) -> Valid (EvKey (KChar unicodeChar) []) []
76+ Just (unicodeChar, _) -> Valid (EvKey (KChar unicodeChar) []) rest
70− _ -> Invalid -- something bad happened; just ignore and continue.
77+ Nothing -> Invalid -- something bad happened; just ignore and continue.
72utf8Length :: (Num t, Ord a, Num a) => a -> t
79utf8Length :: (Num t, Ord a, Num a) => a -> t
73utf8Length c
80utf8Length c