packages feed

word8 0.1.1 → 0.1.3

raw patch · 4 files changed

Files

Data/Char8.hs view
@@ -6,6 +6,10 @@ -- All utility functions are supposed to work as if -- those of 'Data.Char'. Exceptions are described in -- the function documentations.+--+-- Base library 4.7 (GHC 7.8) or earlier is based on Unicode 6.+-- Base library 4.8 (GHC 7.10) or later is based on Unicode 7.+-- 'isLower', 'isSymbol' and 'isPunctuation' behave differently.  module Data.Char8 (   -- * Character classification@@ -34,10 +38,20 @@          || c == _vt          || c == _nbsp +-- | This function returns 'True' for 170 and 186 in Unicode 6.+--   But it returns 'False' in Unicode 7. isLower :: Char -> Bool isLower c = isLower' c+         || c == _mu+#if !MIN_VERSION_base(4,8,0)          || c == _ordfeminine+         || c == _ordmasculine+#endif++isLowerCommon :: Char -> Bool+isLowerCommon c = isLower' c          || c == _mu+         || c == _ordfeminine          || c == _ordmasculine  isLower' :: Char -> Bool@@ -51,7 +65,7 @@          || _Oslash <= c && c <= _Thorn  isAlpha :: Char -> Bool-isAlpha c = isLower c || isUpper c+isAlpha c = isLowerCommon c || isUpper c  isAlphaNum :: Char -> Bool isAlphaNum c = isAlpha c || isNumber c@@ -74,7 +88,7 @@             || 'a' <= c && c <= 'f'  isLetter :: Char -> Bool-isLetter c = isLower c || isUpper c+isLetter c = isLowerCommon c || isUpper c  isMark :: Char -> Bool isMark _ = False@@ -88,11 +102,23 @@           || c == _1'2           || c == _3'4 +-- | This function returns 'False' for 167 and 182 in Unicode 6.+--   But it returns 'True' in Unicode 7. isPunctuation :: Char -> Bool+#if MIN_VERSION_base(4,8,0)+isPunctuation c = c `elem` ['\x21','\x22','\x23','\x25','\x26','\x27','\x28','\x29','\x2a','\x2c','\x2d','\x2e','\x2f','\x3a','\x3b','\x3f','\x40','\x5b','\x5c','\x5d','\x5f','\x7b','\x7d','\xa1','\xa7','\xab','\xb6','\xb7','\xbb','\xbf']+#else isPunctuation c = c `elem` ['\x21','\x22','\x23','\x25','\x26','\x27','\x28','\x29','\x2a','\x2c','\x2d','\x2e','\x2f','\x3a','\x3b','\x3f','\x40','\x5b','\x5c','\x5d','\x5f','\x7b','\x7d','\xa1','\xab','\xb7','\xbb','\xbf']+#endif +-- | This function returns 'True' for 167 and 182 in Unicode 6.+--   But it returns 'False' in Unicode 7. isSymbol :: Char -> Bool+#if MIN_VERSION_base(4,8,0)+isSymbol c = c `elem` ['\x24','\x2b','\x3c','\x3d','\x3e','\x5e','\x60','\x7c','\x7e','\xa2','\xa3','\xa4','\xa5','\xa6','\xa8','\xa9','\xac','\xae','\xaf','\xb0','\xb1','\xb4','\xb8','\xd7','\xf7']+#else isSymbol c = c `elem` ['\x24','\x2b','\x3c','\x3d','\x3e','\x5e','\x60','\x7c','\x7e','\xa2','\xa3','\xa4','\xa5','\xa6','\xa7','\xa8','\xa9','\xac','\xae','\xaf','\xb0','\xb1','\xb4','\xb6','\xb8','\xd7','\xf7']+#endif  isSeparator :: Char -> Bool isSeparator c = c == _space
Data/Word8.hs view
@@ -1,8 +1,14 @@+{-# LANGUAGE CPP #-}+ -- | Word8 library to be used with Data.ByteString. -- All function assumes that 'Word8' is encoded in Latin-1 (ISO-8859-1). -- All utility functions are supposed to work as if -- those of 'Data.Char'. Exceptions are described in -- the function documentations.+--+-- Base library 4.7 (GHC 7.8) or earlier is based on Unicode 6.+-- Base library 4.8 (GHC 7.10) or later is based on Unicode 7.+-- 'isLower', 'isSymbol' and 'isPunctuation' behave differently.  module Data.Word8 (   -- * Re-exporting@@ -34,6 +40,10 @@  import Data.Word (Word8) +#ifndef MIN_VERSION_base+#define MIN_VERSION_base(x,y,z) 1+#endif+ ----------------------------------------------------------------  isControl :: Word8 -> Bool@@ -49,10 +59,20 @@          || w == _vt          || w == _nbsp +-- | This function returns 'True' for 170 and 186 in Unicode 6.+--   But it returns 'False' in Unicode 7. isLower :: Word8 -> Bool isLower w = isLower' w+         || w == _mu+#if !MIN_VERSION_base(4,8,0)          || w == _ordfeminine+         || w == _ordmasculine+#endif++isLowerCommon :: Word8 -> Bool+isLowerCommon w = isLower' w          || w == _mu+         || w == _ordfeminine          || w == _ordmasculine  isLower' :: Word8 -> Bool@@ -66,7 +86,7 @@          || _Oslash <= w && w <= _Thorn  isAlpha :: Word8 -> Bool-isAlpha w = isLower w || isUpper w+isAlpha w = isLowerCommon w || isUpper w  isAlphaNum :: Word8 -> Bool isAlphaNum w = isAlpha w || isNumber w@@ -89,7 +109,7 @@             || _a <= w && w <= _f  isLetter :: Word8 -> Bool-isLetter w = isLower w || isUpper w+isLetter w = isLowerCommon w || isUpper w  isMark :: Word8 -> Bool isMark _ = False@@ -103,11 +123,23 @@           || w == _1'2           || w == _3'4 +-- | This function returns 'False' for 167 and 182 in Unicode 6.+--   But it returns 'True' in Unicode 7. isPunctuation :: Word8 -> Bool+#if MIN_VERSION_base(4,8,0)+isPunctuation w = w `elem` [0x21,0x22,0x23,0x25,0x26,0x27,0x28,0x29,0x2a,0x2c,0x2d,0x2e,0x2f,0x3a,0x3b,0x3f,0x40,0x5b,0x5c,0x5d,0x5f,0x7b,0x7d,0xa1,0xa7,0xab,0xb6,0xb7,0xbb,0xbf]+#else isPunctuation w = w `elem` [0x21,0x22,0x23,0x25,0x26,0x27,0x28,0x29,0x2a,0x2c,0x2d,0x2e,0x2f,0x3a,0x3b,0x3f,0x40,0x5b,0x5c,0x5d,0x5f,0x7b,0x7d,0xa1,0xab,0xb7,0xbb,0xbf]+#endif +-- | This function returns 'True' for 167 and 182 in Unicode 6.+--   But it returns 'False' in Unicode 7. isSymbol :: Word8 -> Bool+#if MIN_VERSION_base(4,8,0)+isSymbol w = w `elem` [0x24,0x2b,0x3c,0x3d,0x3e,0x5e,0x60,0x7c,0x7e,0xa2,0xa3,0xa4,0xa5,0xa6,0xa8,0xa9,0xac,0xae,0xaf,0xb0,0xb1,0xb4,0xb8,0xd7,0xf7]+#else isSymbol w = w `elem` [0x24,0x2b,0x3c,0x3d,0x3e,0x5e,0x60,0x7c,0x7e,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xac,0xae,0xaf,0xb0,0xb1,0xb4,0xb6,0xb8,0xd7,0xf7]+#endif  isSeparator :: Word8 -> Bool isSeparator w = w == _space
test/Char8Spec.hs view
@@ -2,107 +2,109 @@  import qualified Data.Char as C import Data.Char8+import Data.Word (Word8)+import Word8Spec (word8ToChar) import Test.Hspec import Test.Hspec.QuickCheck  spec :: Spec spec = do     describe "isControl" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isControl c == C.isControl c      describe "isSpace" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isSpace c == C.isSpace c      describe "isLower" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isLower c == C.isLower c      describe "isUpper" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isUpper c == C.isUpper c      describe "isAlpha" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isAlpha c == C.isAlpha c      describe "isAlphaNum" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isAlphaNum c == C.isAlphaNum c      describe "isPrint" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isPrint c == C.isPrint c      describe "isDigit" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isDigit c == C.isDigit c      describe "isOctDigit" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isOctDigit c == C.isOctDigit c      describe "isHexDigit" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isHexDigit c == C.isHexDigit c      describe "isLetter" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isLetter c == C.isLetter c      describe "isMark" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isMark c == C.isMark c      describe "isNumber" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isNumber c == C.isNumber c      describe "isPunctuation" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isPunctuation c == C.isPunctuation c      describe "isSymbol" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isSymbol c == C.isSymbol c      describe "isSeparator" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isSeparator c == C.isSeparator c      describe "isAscii" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isAscii c == C.isAscii c      describe "isLatin1" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isLatin1 c == C.isLatin1 c      describe "isAsciiUpper" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isAsciiUpper c == C.isAsciiUpper c      describe "isAsciiLower" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             isAsciiLower c == C.isAsciiLower c      describe "toUpper" $ do-        prop "behaves like model" $ prop_toUpper+        prop "behaves like model" $ ensure $ prop_toUpper      describe "toLower" $ do-        prop "behaves like model" $ \c ->+        prop "behaves like model" $ ensure $ \c ->             toLower c == C.toLower c      describe "toTitle" $ do-        prop "behaves like model" $ prop_toTitle+        prop "behaves like model" $ ensure $ prop_toTitle  prop_toUpper :: Char -> Bool prop_toUpper c   | c == _mu        = True   | c == _ydieresis = True   | otherwise       = toUpper c == C.toUpper c-    + prop_toTitle :: Char -> Bool prop_toTitle c   | c == _mu  = True@@ -114,3 +116,8 @@ _mu, _ydieresis :: Char _mu        = '\xb5' _ydieresis = '\xff'++----------------------------------------------------------------++ensure :: (Char -> Bool) -> Word8 -> Bool+ensure body w = body (word8ToChar w)
word8.cabal view
@@ -1,5 +1,5 @@ Name:                   word8-Version:                0.1.1+Version:                0.1.3 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3