diff options
-rw-r--r-- | bencoding.cabal | 4 | ||||
-rw-r--r-- | src/Data/BEncode.hs | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/bencoding.cabal b/bencoding.cabal index cfad921..b01d188 100644 --- a/bencoding.cabal +++ b/bencoding.cabal | |||
@@ -21,14 +21,18 @@ source-repository head | |||
21 | library | 21 | library |
22 | exposed-modules: Data.BEncode | 22 | exposed-modules: Data.BEncode |
23 | other-modules: | 23 | other-modules: |
24 | |||
25 | -- WARN package text is used only for instance declaration | ||
24 | build-depends: base == 4.5.* | 26 | build-depends: base == 4.5.* |
25 | , containers >= 0.4.0 | 27 | , containers >= 0.4.0 |
26 | , bytestring >= 0.10.2.0 | 28 | , bytestring >= 0.10.2.0 |
27 | , attoparsec >= 0.10.4.0 | 29 | , attoparsec >= 0.10.4.0 |
30 | , text >= 0.11.2.3 | ||
28 | , ansi-wl-pprint | 31 | , ansi-wl-pprint |
29 | 32 | ||
30 | hs-source-dirs: src | 33 | hs-source-dirs: src |
31 | 34 | ||
35 | extensions: PatternGuards | ||
32 | ghc-options: -Wall -fno-warn-unused-do-bind | 36 | ghc-options: -Wall -fno-warn-unused-do-bind |
33 | -- -Werror | 37 | -- -Werror |
34 | 38 | ||
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index 7539ede..357f63f 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs | |||
@@ -42,6 +42,8 @@ import qualified Data.ByteString.Lazy as Lazy | |||
42 | import Data.ByteString.Internal as B (c2w, w2c) | 42 | import Data.ByteString.Internal as B (c2w, w2c) |
43 | import qualified Data.ByteString.Builder as B | 43 | import qualified Data.ByteString.Builder as B |
44 | import qualified Data.ByteString.Builder.Prim as BP () | 44 | import qualified Data.ByteString.Builder.Prim as BP () |
45 | import Data.Text (Text) | ||
46 | import qualified Data.Text.Encoding as T | ||
45 | import Text.PrettyPrint.ANSI.Leijen (Pretty, Doc, pretty, (<+>), (</>)) | 47 | import Text.PrettyPrint.ANSI.Leijen (Pretty, Doc, pretty, (<+>), (</>)) |
46 | import qualified Text.PrettyPrint.ANSI.Leijen as PP | 48 | import qualified Text.PrettyPrint.ANSI.Leijen as PP |
47 | 49 | ||
@@ -117,6 +119,15 @@ instance BEncodable ByteString where | |||
117 | fromBEncode _ = decodingError "string" | 119 | fromBEncode _ = decodingError "string" |
118 | {-# INLINE fromBEncode #-} | 120 | {-# INLINE fromBEncode #-} |
119 | 121 | ||
122 | |||
123 | instance BEncodable Text where | ||
124 | toBEncode = toBEncode . T.encodeUtf8 | ||
125 | {-# INLINE toBEncode #-} | ||
126 | |||
127 | fromBEncode b = T.decodeUtf8 <$> fromBEncode b | ||
128 | {-# INLINE fromBEncode #-} | ||
129 | |||
130 | |||
120 | {- | 131 | {- |
121 | instance BEncodable String where | 132 | instance BEncodable String where |
122 | toBEncode = BString . BC.pack | 133 | toBEncode = BString . BC.pack |