Skip to content

Commit

Permalink
The data isn't always UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
fujimura committed Mar 14, 2024
1 parent 7719da9 commit df63ecb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
module Lib where

import Control.Monad
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
import System.IO
( BufferMode (NoBuffering),
Expand Down Expand Up @@ -39,9 +41,12 @@ substitute ::
FilePath -> -- File
IO ()
substitute re to file = do
content <- T.readFile file
let newContent :: T.Text = replaceAll to (content *=~ re)
T.writeFile file newContent
b <- BS.readFile file
case T.decodeUtf8' b of
Left _ -> return ()
Right content -> do
let newContent :: T.Text = replaceAll to (content *=~ re)
T.writeFile file newContent

substituteInteractive ::
RE -> -- From
Expand Down

0 comments on commit df63ecb

Please sign in to comment.