packages feed

hyphenation 0.4 → 0.4.1

raw patch · 3 files changed

+39/−1 lines, 3 filesdep +bytestringdep +file-embedPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring, file-embed

API changes (from Hackage documentation)

Files

CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.4.1+-----+* Added support for embedding all of the pattern files into the library as resources by using `cabal install hyphenation -fembed`. This is not the default as it inflates the library size by ~3MB and forces all users to pay for all the hyphenation patterns, but it can be useful for users who aim to build standalone applications.+ 0.4 --- * Removed Farsi. We had no pattern files.
hyphenation.cabal view
@@ -1,6 +1,6 @@ name:          hyphenation category:      Text-version:       0.4+version:       0.4.1 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -38,11 +38,24 @@   type: git   location: git://github.com/ekmett/hyphenation.git +Flag Embed+  Description: Embed data in library binary+               (Warning: This increases the executable size by about 3Mbs unless+                         unneeded language data files are manually removed from+                         the "data" directory before compiling)+  Default:     False+ library   build-depends:     base                 >= 4       && < 5,     containers           >= 0.3.0.0 && < 0.6,     unordered-containers >= 0.2.1   && < 0.3++  if flag(embed)+    build-depends:+      file-embed           >= 0.0.7   && < 0.1,+      bytestring           >= 0.9.4   && < 0.11+    CC-OPtions: "-DEMBED"    exposed-modules:    Text.Hyphenation
src/Text/Hyphenation/Language.hs view
@@ -2,6 +2,9 @@ #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif+#if EMBED+{-# LANGUAGE TemplateHaskell #-}+#endif ----------------------------------------------------------------------------- -- | -- Module      :  Text.Hyphenation.Language@@ -40,8 +43,17 @@ import Text.Hyphenation.Pattern import Text.Hyphenation.Exception import System.IO.Unsafe+#if !EMBED import Paths_hyphenation+#else+import Data.FileEmbed+import Control.Arrow (second)+import Data.ByteString.Char8 (unpack) +hyphenatorFiles :: [(FilePath, String)]+hyphenatorFiles = map (second unpack) $(embedDir "data")+#endif+ chrLine :: String -> [(Int, Char)] chrLine (x:xs) = map (\y -> (fromEnum y, x)) xs chrLine [] = []@@ -51,6 +63,7 @@ -- (e.g. @hyphenateLanguage \"en-us\"@ opens @\"\/Users\/ekmett\/.cabal\/share\/hyphenation-0.2\/ghc-7.4.1\/hyph-en-us.hyp.txt\"@ -- among others when run on the author's local machine) loadHyphenator :: String -> IO Hyphenator+#if !EMBED loadHyphenator language = do   hyp <- getDataFileName ("hyph-" ++ language ++ ".hyp.txt") >>= readFile   pat <- getDataFileName ("hyph-" ++ language ++ ".pat.txt") >>= readFile@@ -58,6 +71,14 @@   let chrMap = IM.fromList (lines chr >>= chrLine)       tryLookup x = fromMaybe x $ IM.lookup (fromEnum x) chrMap   return $ Hyphenator tryLookup (parsePatterns pat) (parseExceptions hyp) defaultLeftMin defaultRightMin+#else+loadHyphenator language = return $ Hyphenator tryLookup (parsePatterns pat) (parseExceptions hyp) defaultLeftMin defaultRightMin+  where Just hyp = lookup ("hyph-" ++ language ++ ".hyp.txt") hyphenatorFiles+        Just pat = lookup ("hyph-" ++ language ++ ".pat.txt") hyphenatorFiles+        Just chr = lookup ("hyph-" ++ language ++ ".chr.txt") hyphenatorFiles+        chrMap = IM.fromList (lines chr >>= chrLine)+        tryLookup x = fromMaybe x $ IM.lookup (fromEnum x) chrMap+#endif  -- | A strongly typed set of available languages you can use for hyphenation. data Language