基本上我有一个用于复制文件的CLI实用程序。
{-# LANGUAGE OverloadedStrings #-}
...
import Turtle
...
{- Command line parser -}
-- | Represents command line options.
data Settings = Settings
{ sVerbose :: Bool
...
, sSrc :: FilePath
, sDst :: FilePath
}
...
跟踪代码:
...
-- | Extracts String From FilePath (unsafe and unofficial).
-- No double quotes allowed in paths.
strp :: FilePath -> String
strp path =
let parts = splitOn "\"" (show path)
in parts !! 1
...
putStrLn "Наблюдаем юникод"
putStrLn $ strp (sSrc args)
putStrLn $ strp src
...
工作代码:
...
src <- realpath (sSrc args)
...
sSrc
的控制台输入实际上是.
控制台输出:
Наблюдаем юникод
./
/home/alexey/common/Downloads/UpDown/Books/Audio/_Nonfiction_/Moral Combat \8211 Good and Evil in World War II [Unabridged]/
1/26 /home/alexey/dir-dst/Moral Combat \\8211 Good and Evil in World War II [Unabridged]/01-Moral Combat \\8211 Part 01.mp3
\8211
是某种破折号。转义路径由realpath
.
生成。我不知道原因。它是特定的i / o库吗?是编译选项吗?到目前为止唯一不能逃脱unicode字符的是putStrLn
。
我希望原始路径完好。
UPD:
Make it easy to extract a file path as Text from a FilePath
黑客现在看起来更漂亮:
import qualified Filesystem.Path.CurrentOS as FPS
import Data.Either.Extra
...
-- | Extracts String From FilePath
-- (good until deprecated system-filepath removed).
strp :: FilePath -> String
strp path = T.unpack $ fromRight "" (FPS.toText path)
它暂时有效。尽管如此,我仍然喜欢强制逃避的想法。 show
和print
通常非常有用,并且通常通过转义无用。没办法把它关掉?
答案 0 :(得分:0)
子字符串show
由let parts = splitOn "\"" (show path)
(realpath
)而不是show
生成。可能你应该删除对{{1}}的调用,尽管它并不是100%清楚你想要的跟踪代码。