Commits

Bryan O'Sullivan committed b850a53

Tidy up the Utf8 module

Comments (0)

Files changed (1)

Data/Text/Utf8.hs

 {-# LANGUAGE MagicHash #-}
-module Data.Text.Utf8 where
+module Data.Text.Utf8
+    (
+      ord2
+    , ord3
+    , ord4
+    , chr2
+    , chr3
+    , chr4
+    , validate1
+    , validate2
+    , validate3
+    , validate4
+    ) where
 
-import Data.Char(ord)
-import Data.Bits
+import Data.Char (ord)
+import Data.Bits (shiftR, (.&.))
+import GHC.Exts
+import GHC.Word (Word8(..))
 
-import GHC.Exts
-import GHC.Prim
-import GHC.Word
-
-between       :: Word8 -> Word8 -> Word8 -> Bool
+between :: Word8 -> Word8 -> Word8 -> Bool
 between x y z = x >= y && x <= z
 {-# INLINE between #-}
 
 {-# INLINE validate2 #-}
 
 validate3          :: Word8 -> Word8 -> Word8 -> Bool
+{-# INLINE validate3 #-}
 validate3 x1 x2 x3 = validate3_1 x1 x2 x3 ||
                      validate3_2 x1 x2 x3 ||
                      validate3_3 x1 x2 x3 ||
                      validate3_4 x1 x2 x3
-{-# INLINE validate3 #-}
+  where
+    validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
+                           between x2 0xA0 0xBF &&
+                           between x3 0x80 0xBF
+    validate3_2 x1 x2 x3 = between x1 0xE1 0xEC &&
+                           between x2 0x80 0xBF &&
+                           between x3 0x80 0xBF
+    validate3_3 x1 x2 x3 = x1 == 0xED &&
+                           between x2 0x80 0x9F &&
+                           between x3 0x80 0xBF
+    validate3_4 x1 x2 x3 = between x1 0xEE 0xEF &&
+                           between x2 0x80 0xBF &&
+                           between x3 0x80 0xBF
 
 validate4             :: Word8 -> Word8 -> Word8 -> Word8 -> Bool
+{-# INLINE validate4 #-}
 validate4 x1 x2 x3 x4 = validate4_1 x1 x2 x3 x4 ||
                         validate4_2 x1 x2 x3 x4 ||
                         validate4_3 x1 x2 x3 x4
-{-# INLINE validate4 #-}
-
-
-
-validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
-                       between x2 0xA0 0xBF &&
-                       between x3 0x80 0xBF
-{-# INLINE validate3_1 #-}
-
-validate3_2 x1 x2 x3 = between x1 0xE1 0xEC &&
-                       between x2 0x80 0xBF &&
-                       between x3 0x80 0xBF
-{-# INLINE validate3_2 #-}
-
-validate3_3 x1 x2 x3 = x1 == 0xED &&
-                       between x2 0x80 0x9F &&
-                       between x3 0x80 0xBF
-{-# INLINE validate3_3 #-}
-
-validate3_4 x1 x2 x3 = between x1 0xEE 0xEF &&
-                       between x2 0x80 0xBF &&
-                       between x2 0x80 0xBF
-{-# INLINE validate3_4 #-}
-
-
-validate4_1 x1 x2 x3 x4 = x1 == 0xF0 &&
-                          between x2 0x90 0xBF &&
-                          between x3 0x80 0xBF &&
-                          between x4 0x80 0xBF
-{-# INLINE validate4_1 #-}
-
-validate4_2 x1 x2 x3 x4 = between x1 0xF1 0xF3 &&
-                          between x2 0x80 0xBF &&
-                          between x3 0x80 0xBF &&
-                          between x4 0x80 0xBF
-{-# INLINE validate4_2 #-}
-
-validate4_3 x1 x2 x3 x4 = x1 == 0xF4 &&
-                          between x2 0x80 0x8F &&
-                          between x3 0x80 0xBF &&
-                          between x4 0x80 0xBF
-{-# INLINE validate4_3 #-}
+  where 
+    validate4_1 x1 x2 x3 x4 = x1 == 0xF0 &&
+                              between x2 0x90 0xBF &&
+                              between x3 0x80 0xBF &&
+                              between x4 0x80 0xBF
+    validate4_2 x1 x2 x3 x4 = between x1 0xF1 0xF3 &&
+                              between x2 0x80 0xBF &&
+                              between x3 0x80 0xBF &&
+                              between x4 0x80 0xBF
+    validate4_3 x1 x2 x3 x4 = x1 == 0xF4 &&
+                              between x2 0x80 0x8F &&
+                              between x3 0x80 0xBF &&
+                              between x4 0x80 0xBF