From 778f2c6e7a563b98ae7e29522cc60905e3555630 Mon Sep 17 00:00:00 2001 From: Stefan Friese Date: Mon, 20 May 2024 23:28:14 +0200 Subject: [PATCH] reworked functions to display Unicode correctly --- src/Encoding/Base58.hs | 7 +++++-- src/Encoding/Base85.hs | 5 ++++- src/Encoding/QuotedPrintable.hs | 6 +++++- src/Encoding/UnixToUnix.hs | 6 +++++- src/Encoding/Xx.hs | 5 ++++- src/Encoding/Yenc.hs | 7 +++++-- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Encoding/Base58.hs b/src/Encoding/Base58.hs index fb836d2..ffe99bf 100644 --- a/src/Encoding/Base58.hs +++ b/src/Encoding/Base58.hs @@ -6,13 +6,16 @@ module Encoding.Base58 import qualified Data.ByteString.Char8 as C import Data.ByteString.UTF8 as BSU -- from utf8-string import qualified Haskoin.Address.Base58 as B58 + import qualified Data.Text as T import qualified Data.Text.Encoding as T -import qualified Data.Text.IO as T +-- import qualified Data.Text.IO as T dec58 :: String -> String dec58 input = - maybe "Error decoding Base58.\n" C.unpack (B58.decodeBase58 (T.pack input)) + case B58.decodeBase58 (T.pack input) of + Just decodedStr -> T.unpack (T.decodeUtf8 decodedStr) + Nothing -> "Error decoding Base58.\n" enc58 :: String -> String enc58 = T.unpack . B58.encodeBase58 . BSU.fromString diff --git a/src/Encoding/Base85.hs b/src/Encoding/Base85.hs index e902761..282d55d 100644 --- a/src/Encoding/Base85.hs +++ b/src/Encoding/Base85.hs @@ -7,10 +7,13 @@ import qualified Codec.Binary.Base85 as B85 import Data.ByteString.UTF8 as BSU -- from utf8-string import qualified Data.ByteString.Char8 as C +import qualified Data.Text as T +import qualified Data.Text.Encoding as T + dec85 :: String -> String dec85 input = case B85.decode (BSU.fromString input) of - Right decodedStr -> C.unpack decodedStr + Right decodedStr -> T.unpack (T.decodeUtf8 decodedStr) Left _ -> "Error decoding Base85.\n" enc85 :: String -> String diff --git a/src/Encoding/QuotedPrintable.hs b/src/Encoding/QuotedPrintable.hs index de6fbbd..f8fe96e 100644 --- a/src/Encoding/QuotedPrintable.hs +++ b/src/Encoding/QuotedPrintable.hs @@ -7,10 +7,14 @@ import qualified Codec.Binary.QuotedPrintable as QP import Data.ByteString.UTF8 as BSU -- from utf8-string import qualified Data.ByteString.Char8 as C +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +-- import qualified Data.Text.IO as T + decqp :: String -> String decqp input = case QP.decode (BSU.fromString input) of - Right decoded -> C.unpack decoded + Right decoded -> T.unpack (T.decodeUtf8 decoded) Left _ -> "Error decoding QP.\n" encqp :: String -> String diff --git a/src/Encoding/UnixToUnix.hs b/src/Encoding/UnixToUnix.hs index 25120e0..dd0a090 100644 --- a/src/Encoding/UnixToUnix.hs +++ b/src/Encoding/UnixToUnix.hs @@ -7,11 +7,15 @@ import qualified Codec.Binary.Uu as UU import Data.ByteString.UTF8 as BSU -- from utf8-string import qualified Data.ByteString.Char8 as C +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import qualified Data.Text.IO as T + decuu :: String -> String -- decuu = C.unpack . U.fromRight . UU.decode . BSU.fromString decuu input = case UU.decode (BSU.fromString input) of - Right decoded -> C.unpack decoded + Right decoded -> T.unpack (T.decodeUtf8 decoded) Left _ -> "Error decoding UU.\n" encuu :: String -> String diff --git a/src/Encoding/Xx.hs b/src/Encoding/Xx.hs index d2cd36a..cd010c7 100644 --- a/src/Encoding/Xx.hs +++ b/src/Encoding/Xx.hs @@ -6,11 +6,14 @@ module Encoding.Xx import qualified Codec.Binary.Xx as XX import Data.ByteString.UTF8 as BSU -- from utf8-string import qualified Data.ByteString.Char8 as C +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import qualified Data.Text.IO as T decxx :: String -> String decxx input = case XX.decode (BSU.fromString input) of - Right decoded -> C.unpack decoded + Right decoded -> T.unpack (T.decodeUtf8 decoded) Left _ -> "Error decoding XX.\n" encxx :: String -> String diff --git a/src/Encoding/Yenc.hs b/src/Encoding/Yenc.hs index fc4a330..9dbef39 100644 --- a/src/Encoding/Yenc.hs +++ b/src/Encoding/Yenc.hs @@ -8,13 +8,16 @@ import Data.ByteString.UTF8 as BSU -- from utf8-string import qualified Data.ByteString.Char8 as C import qualified Codec.Binary.Yenc as Y +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import qualified Data.Text.IO as T + decy :: String -> String -- decy = C.unpack . U.fromRight . Y.decode . BSU.fromString decy input = case Y.decode (BSU.fromString input) of - Right decoded -> C.unpack decoded + Right decoded -> T.unpack (T.decodeUtf8 decoded) Left _ -> "Error decoding Y.\n" - ency :: String -> String ency = C.unpack . Y.encode . BSU.fromString