added errorhandling for base62 encoding
This commit is contained in:
parent
6972d08ff7
commit
fd6b5dfd16
15
Main.hs
15
Main.hs
|
@ -213,14 +213,23 @@ dec62 input =
|
|||
-- maybe "Error decoding Base62.\n" show (B62.decode128 (Bytes.fromByteString (BSU.fromString input)))
|
||||
|
||||
stringToInt :: String -> Maybe Integer
|
||||
stringToInt str = readMaybe str
|
||||
stringToInt = readMaybe
|
||||
|
||||
enc62 :: String -> String
|
||||
-- enc62 :: String -> String
|
||||
-- enc62 = C.unpack . BSU.fromString. Latin1.toString . (Bytes.fromByteArray . ( B62.encode64 . (intToWord64 . decimalStringToInt)))
|
||||
-- enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . (Bytes.fromByteArray . ( B62.encode64 . (intToWord64 . decimalStringToInt)))
|
||||
-- enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . (Bytes.fromByteArray . (B62.encode128 . (fromIntegral . ( BSU.fromString . fromJust StringToInt))))
|
||||
enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . Bytes.fromByteArray . B62.encode64 . fromIntegral . fromJust . stringToInt
|
||||
|
||||
-- working correct:
|
||||
-- enc62 :: String -> String
|
||||
-- enc62 = T.unpack . T.decodeUtf8 . BSU.fromString . Latin1.toString . Bytes.fromByteArray . B62.encode64 . fromIntegral . fromJust . stringToInt
|
||||
|
||||
enc62 :: String -> String
|
||||
enc62 input =
|
||||
let intValue = fromMaybe (error "Error: Unable to convert input string to integer") (stringToInt input)
|
||||
encoded = B62.encode64 (fromIntegral intValue)
|
||||
encodedText = T.decodeUtf8 (BSU.fromString (Latin1.toString (Bytes.fromByteArray encoded)))
|
||||
in T.unpack encodedText
|
||||
-- enc62 :: Text -> Text
|
||||
-- enc62 text = B62.text128 (fromIntegral (T.length text))
|
||||
|
||||
|
|
Loading…
Reference in New Issue