OpenAFP-Utils 1.4.1.1 → 1.4.1.2
raw patch · 3 files changed
+20/−13 lines, 3 filesdep +text-locale-encoding
Dependencies added: text-locale-encoding
Files
- ChangeLog +4/−0
- OpenAFP-Utils.cabal +2/−2
- afp-dump.hs +14/−11
ChangeLog view
@@ -1,3 +1,7 @@+# 1.4.1.2++* Restore "afp-dump -e" support using GHC's internal encoding.+ # 1.4.1.1 * Add afp-tledump utility.
OpenAFP-Utils.cabal view
@@ -1,5 +1,5 @@ Name: OpenAFP-Utils-Version: 1.4.1.1+Version: 1.4.1.2 License: PublicDomain License-file: LICENSE Author: Audrey Tang@@ -27,7 +27,7 @@ Executable afp-dump Main-is: afp-dump.hs- Build-depends: OpenAFP >= 1.4, base >= 4 && < 5, bytestring, containers, xhtml+ Build-depends: OpenAFP >= 1.4, base >= 4 && < 5, bytestring, containers, xhtml, text-locale-encoding Extensions: DeriveDataTypeable, PatternGuards Executable afp-page
afp-dump.hs view
@@ -5,6 +5,8 @@ import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Char8 as C+import Data.Text.Encoding.Locale (decodeLocale', encodeLocale')+import System.IO (noNewlineTranslation) -- The key here is inventing a ConcreteDataView for our data structure. -- See OpenAFP.Types.View for details.@@ -164,25 +166,26 @@ nstrLine = tr << td ! [colspan 2] << thespan << nstrHtml nstr texts :: [N1] -> [(String, ByteString)]-texts nstr = maybeToList $ msum [ maybe Nothing (Just . ((,) cp)) $ conv (codeName cp) | cp <- encs ]+texts nstr = maybeToList $ msum [ maybe Nothing (Just . ((,) cp)) $! conv (codeName cp) | cp <- encs ] where conv c@"ibm-937"- | (even $ length nstr) = convert' c "utf8" (packNStr $ toNStr (0x0E : nstr))+ | (even $ length nstr) = convert' c "UTF-8" (packNStr $ toNStr (0x0E : nstr)) | otherwise = Nothing- conv c = convert' c "utf8" (packNStr $ toNStr nstr)+ conv c = convert' c "UTF-8" (packNStr $ toNStr nstr) codeName c | isJust $ find (not . isDigit) c = c | otherwise = "ibm-" ++ c --- TODO: Rewrite with GHC IO Encoding-convertStrictly _ _ _ = Right ()--convert' :: String -> String -> ByteString -> Maybe ByteString-convert' from to str = case convertStrictly from to strLazy of- Left resLazy -> Just $ S.concat (L.toChunks resLazy)- _ -> Nothing+{-# NOINLINE convert' #-}+convert' from to str = case unsafePerformIO doConvert of+ Left ioerr -> Nothing+ Right str -> Just $! str where- strLazy = L.fromChunks [str]+ doConvert = tryIOError $ do+ encFrom <- mkTextEncoding from+ encTo <- mkTextEncoding to+ txt <- decodeLocale' encFrom noNewlineTranslation str+ encodeLocale' encTo noNewlineTranslation txt fieldsHtml :: [ViewField] -> [Html] fieldsHtml fs = [table << fsHtml] ++ membersHtml