我需要一个库来对cp1251中的数据进行编码,以便与使用它的api一起使用。
我发现只有2个库用于此目的。该编码lib和文本的ICU库。第一个看起来更好,只是因为它可以静态链接到我的程序。
但是我什至无法编译!我正在使用堆栈,所以我encoding
在.cabal文件中添加了build-deps,然后堆栈求解器在extra-deps中使用encoding-0.8更新了我的堆栈yaml文件。
但是运行后stack build
我出现了一个错误
Data/Encoding/Preprocessor/XMLMapping.hs:11:8:
Could not find module ‘Text.XML.HaXml.Types’
Use -v to see a list of the files searched for.
Data/Encoding/Preprocessor/XMLMappingBuilder.hs:15:8:
Could not find module ‘Text.XML.HaXml.OneOfN’
Use -v to see a list of the files searched for.
Data/Encoding/Preprocessor/XMLMappingBuilder.hs:16:8:
Could not find module ‘Text.XML.HaXml.XmlContent’
Use -v to see a list of the files searched for.
我试图使用旧版本的HaXml和编码,但遇到了相同的错误。比如我试图用encoding-0.6.7
用HaXml-1.22.3
,读的changelog后https://hackage.haskell.org/package/encoding-0.7.0.2/changelog但得到了同样的错误。在hackage文档中,存在所有无法导入编码的模块。
我如何编译这个库?我在Linux Mint x64上使用堆栈1.0.4,lts-5.6和ghc-7.10.3
stack.yaml
flags: {}
extra-package-dbs: []
packages:
- '.'
extra-deps:
- encoding-0.8
- text-1.2.2.0
resolver: lts-5.6
阴谋:
name: hapidry
version: 0.1.1.0
synopsis: Initial project template from stack
description: Please see README.md
homepage: -
license: GPL-2
license-file: LICENSE
author: -
maintainer: -
copyright: GPL
category: network
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5
default-language: Haskell2010
executable hapidry-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, hapidry
, wreq
, ConfigFile
, aeson
, lens
, cryptohash
, binary
, mtl
, base16-bytestring
, bytestring
, containers
, text
, lens-aeson
, data-default
, optparse-applicative
, encoding
default-language: Haskell2010
test-suite hapidry-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, hapidry
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
source-repository head
type: git
location: -
最后,我编写了自己的编码功能。看起来可以接受的解决方法。另一个一字节编码的功能也可以用相同的方式实现。
toCP1251 :: Text -> B.ByteString
toCP1251 = B.pack . T.unpack . T.map replace where
replace l = case (Map.lookup l table) of
(Just x) -> x
(Nothing) -> l
table = Map.fromList $ zip rus cpCodes
cpCodes = map toEnum (168:184:[192 .. 255]) :: [Char]
rus = ['Ё', 'ё', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М',
'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы',
'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к',
'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ',
'ъ', 'ы', 'ь', 'э', 'ю', 'я'] :: [Char]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句