country 0.1.4 → 0.1.5
raw patch · 5 files changed
+30/−10 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- country.cabal +3/−3
- src/Country.hs +1/−2
- src/Country/Unexposed/Names.hs +14/−3
- src/Country/Unexposed/Trie.hs +6/−1
- src/Country/Unexposed/TrieByte.hs +6/−1
country.cabal view
@@ -1,5 +1,5 @@ name: country-version: 0.1.4+version: 0.1.5 synopsis: Country data type and functions description: The `country` library provides a data type for dealing with@@ -40,14 +40,14 @@ Country.Unexposed.TrieByte Country.Unexposed.Alias build-depends:- base >= 4.7 && < 4.11+ base >= 4.9 && < 4.12 , text >= 1.2 && < 1.3 , bytestring >= 0.10 && < 0.11 , primitive >= 0.6.1 && < 0.7 , unordered-containers >= 0.2 && < 0.3 , ghc-prim >= 0.5 && < 0.6 , hashable >= 1.2 && < 1.3- , aeson >= 0.11 && < 1.3+ , aeson >= 0.11 && < 1.4 , scientific >= 0.3 && < 0.4 , attoparsec >= 0.13 && < 0.14 default-language: Haskell2010
src/Country.hs view
@@ -31,8 +31,7 @@ import Data.Text (Text) import Data.ByteString (ByteString) import Data.Word (Word16)-import Data.Primitive (indexArray,writeByteArray,indexByteArray,unsafeFreezeByteArray,newByteArray)-import Data.Primitive.Array (Array(..))+import Data.Primitive (writeByteArray,indexByteArray,unsafeFreezeByteArray,newByteArray) import Data.Primitive.ByteArray (ByteArray(..)) import GHC.Prim (sizeofByteArray#,sizeofArray#) import GHC.Int (Int(..))
src/Country/Unexposed/Names.hs view
@@ -3,6 +3,7 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE TypeInType #-} {-# OPTIONS_HADDOCK not-home #-} @@ -39,7 +40,7 @@ import Foreign.Storable (Storable) import Data.Text (Text) import Data.Word-import Data.Char (toLower,isAlpha)+import Data.Char (toLower,isAlpha,toUpper) import Country.Unexposed.Encode.English (countryNameQuads) import Data.Primitive (Array,indexArray,newArray,unsafeFreezeArray,writeArray, writeByteArray,indexByteArray,unsafeFreezeByteArray,newByteArray,sizeOf)@@ -65,7 +66,7 @@ {-# NOINLINE englishIdentifierNamesText #-} toIdentifier :: Text -> Text-toIdentifier t = case (T.uncons . T.filter isAlpha . T.toTitle) t of+toIdentifier t = case (T.uncons . T.filter isAlpha . slowToTitle) t of Nothing -> T.empty Just (b,bs) -> T.cons (toLower b) bs @@ -85,9 +86,19 @@ let baseMap = HM.union alphaTwoHashMap alphaThreeHashMap hm1 = L.foldl' (\hm (countryNum,name) -> HM.insert name (Country countryNum) hm) baseMap aliases hm2 = L.foldl' (\hm (countryNum,name,_,_) -> HM.insert name (Country countryNum) hm) hm1 countryNameQuads- hm3 = HM.foldlWithKey' (\hm name cty -> HM.insert (T.toLower name) cty $ HM.insert (T.toTitle name) cty $ hm) hm2 hm2+ hm3 = HM.foldlWithKey' (\hm name cty -> HM.insert (T.toLower name) cty $ HM.insert (slowToTitle name) cty $ hm) hm2 hm2 in hm3 {-# NOINLINE decodeMap #-}++-- This is only needed to support the reflex-platform fork of text. Fortunately,+-- in all the places this is needed, it is only called to build CAFs.+slowToTitle :: Text -> Text+slowToTitle = T.intercalate (T.singleton ' ') . map upperFirst . T.splitOn (T.singleton ' ')++upperFirst :: Text -> Text+upperFirst t = case T.uncons t of+ Nothing -> T.empty+ Just (c,cs) -> T.cons (toUpper c) cs decodeMapUtf8 :: HashMap ByteString Country decodeMapUtf8 = HM.foldlWithKey' (\hm k v -> HM.insert (encodeUtf8 k) v hm) HM.empty decodeMap
src/Country/Unexposed/Trie.hs view
@@ -7,10 +7,12 @@ import Data.HashMap.Strict (HashMap) import Data.Word (Word16) import Data.Text (Text)+import Data.Semigroup (Semigroup) import Control.Applicative ((<|>)) import qualified Data.Text as T import qualified Data.HashMap.Strict as HM import qualified Data.Attoparsec.Text as AT+import qualified Data.Semigroup as SG -- | If the value is not the max Word16 (65535), there -- is a match. This means that 65535 cannot be used, which @@ -36,9 +38,12 @@ Just (char,nameNext) -> Trie placeholder (HM.singleton char (go nameNext)) Nothing -> Trie code HM.empty +instance Semigroup Trie where+ (<>) = mappend+ instance Monoid Trie where mempty = empty- mappend = append+ mappend = (SG.<>) trieFromList :: [(Text,Word16)] -> Trie trieFromList = foldMap (uncurry singleton)
src/Country/Unexposed/TrieByte.hs view
@@ -7,10 +7,12 @@ import Data.HashMap.Strict (HashMap) import Data.Word (Word16,Word8) import Data.ByteString (ByteString)+import Data.Semigroup (Semigroup) import Control.Applicative ((<|>)) import qualified Data.ByteString as B import qualified Data.HashMap.Strict as HM import qualified Data.Attoparsec.ByteString as AB+import qualified Data.Semigroup as SG -- | If the value is not the max Word16 (65535), there -- is a match. This means that 65535 cannot be used, which @@ -36,9 +38,12 @@ Just (char,nameNext) -> TrieByte placeholder (HM.singleton char (go nameNext)) Nothing -> TrieByte code HM.empty +instance Semigroup TrieByte where+ (<>) = append+ instance Monoid TrieByte where mempty = empty- mappend = append+ mappend = (SG.<>) trieByteFromList :: [(ByteString,Word16)] -> TrieByte trieByteFromList = foldMap (uncurry singleton)