Skip to content

Commit 9b2c8e1

Browse files
committed
Improve Show instance on windows
1 parent d408cc9 commit 9b2c8e1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

System/OsPath/Encoding/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ ucs2le_encode
119119
-- Windows encoding (ripped off from base)
120120
--
121121

122+
cWcharsToChars_UCS2 :: [Word16] -> [Char]
123+
cWcharsToChars_UCS2 = map (chr . fromIntegral)
122124

123125

124126
-- On Windows, wchar_t is 16 bits wide and CWString uses the UTF-16 encoding.

System/OsString/Internal/Types.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ import qualified Language.Haskell.TH.Syntax as TH
5959
newtype WindowsString = WindowsString { getWindowsString :: BS.ShortByteString }
6060
deriving (Eq, Ord, Semigroup, Monoid, Typeable, Generic, NFData)
6161

62+
-- | Decodes as UCS-2.
6263
instance Show WindowsString where
63-
-- cWcharsToChars is total
64-
show = show . cWcharsToChars . BS16.unpack . getWindowsString
64+
-- cWcharsToChars_UCS2 is total
65+
show = show . cWcharsToChars_UCS2 . BS16.unpack . getWindowsString
6566

6667
-- | Just a short bidirectional synonym for 'WindowsString' constructor.
6768
pattern WS :: BS.ShortByteString -> WindowsString
@@ -84,6 +85,7 @@ instance Lift WindowsString where
8485
newtype PosixString = PosixString { getPosixString :: BS.ShortByteString }
8586
deriving (Eq, Ord, Semigroup, Monoid, Typeable, Generic, NFData)
8687

88+
-- | Prints the raw bytes without decoding.
8789
instance Show PosixString where
8890
show (PosixString ps) = show ps
8991

0 commit comments

Comments
 (0)