reworked functions to display Unicode correctly

This commit is contained in:
Stefan Friese 2024-05-20 23:28:14 +02:00
parent bdbb3bed3e
commit 778f2c6e7a
6 changed files with 28 additions and 8 deletions

View File

@ -6,13 +6,16 @@ module Encoding.Base58
import qualified Data.ByteString.Char8 as C import qualified Data.ByteString.Char8 as C
import Data.ByteString.UTF8 as BSU -- from utf8-string import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Haskoin.Address.Base58 as B58 import qualified Haskoin.Address.Base58 as B58
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Encoding 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 :: String -> String
dec58 input = 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 :: String -> String
enc58 = T.unpack . B58.encodeBase58 . BSU.fromString enc58 = T.unpack . B58.encodeBase58 . BSU.fromString

View File

@ -7,10 +7,13 @@ import qualified Codec.Binary.Base85 as B85
import Data.ByteString.UTF8 as BSU -- from utf8-string import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Data.ByteString.Char8 as C import qualified Data.ByteString.Char8 as C
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
dec85 :: String -> String dec85 :: String -> String
dec85 input = dec85 input =
case B85.decode (BSU.fromString input) of case B85.decode (BSU.fromString input) of
Right decodedStr -> C.unpack decodedStr Right decodedStr -> T.unpack (T.decodeUtf8 decodedStr)
Left _ -> "Error decoding Base85.\n" Left _ -> "Error decoding Base85.\n"
enc85 :: String -> String enc85 :: String -> String

View File

@ -7,10 +7,14 @@ import qualified Codec.Binary.QuotedPrintable as QP
import Data.ByteString.UTF8 as BSU -- from utf8-string import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Data.ByteString.Char8 as C 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 :: String -> String
decqp input = decqp input =
case QP.decode (BSU.fromString input) of case QP.decode (BSU.fromString input) of
Right decoded -> C.unpack decoded Right decoded -> T.unpack (T.decodeUtf8 decoded)
Left _ -> "Error decoding QP.\n" Left _ -> "Error decoding QP.\n"
encqp :: String -> String encqp :: String -> String

View File

@ -7,11 +7,15 @@ import qualified Codec.Binary.Uu as UU
import Data.ByteString.UTF8 as BSU -- from utf8-string import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Data.ByteString.Char8 as C 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 :: String -> String
-- decuu = C.unpack . U.fromRight . UU.decode . BSU.fromString -- decuu = C.unpack . U.fromRight . UU.decode . BSU.fromString
decuu input = decuu input =
case UU.decode (BSU.fromString input) of case UU.decode (BSU.fromString input) of
Right decoded -> C.unpack decoded Right decoded -> T.unpack (T.decodeUtf8 decoded)
Left _ -> "Error decoding UU.\n" Left _ -> "Error decoding UU.\n"
encuu :: String -> String encuu :: String -> String

View File

@ -6,11 +6,14 @@ module Encoding.Xx
import qualified Codec.Binary.Xx as XX import qualified Codec.Binary.Xx as XX
import Data.ByteString.UTF8 as BSU -- from utf8-string import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Data.ByteString.Char8 as C 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 :: String -> String
decxx input = decxx input =
case XX.decode (BSU.fromString input) of case XX.decode (BSU.fromString input) of
Right decoded -> C.unpack decoded Right decoded -> T.unpack (T.decodeUtf8 decoded)
Left _ -> "Error decoding XX.\n" Left _ -> "Error decoding XX.\n"
encxx :: String -> String encxx :: String -> String

View File

@ -8,13 +8,16 @@ import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Data.ByteString.Char8 as C import qualified Data.ByteString.Char8 as C
import qualified Codec.Binary.Yenc as Y 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 :: String -> String
-- decy = C.unpack . U.fromRight . Y.decode . BSU.fromString -- decy = C.unpack . U.fromRight . Y.decode . BSU.fromString
decy input = decy input =
case Y.decode (BSU.fromString input) of case Y.decode (BSU.fromString input) of
Right decoded -> C.unpack decoded Right decoded -> T.unpack (T.decodeUtf8 decoded)
Left _ -> "Error decoding Y.\n" Left _ -> "Error decoding Y.\n"
ency :: String -> String ency :: String -> String
ency = C.unpack . Y.encode . BSU.fromString ency = C.unpack . Y.encode . BSU.fromString