File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -218,15 +218,24 @@ unsafeEncodeUtf = either (error . displayException) id . encodeWith utf16le
218
218
unsafeEncodeUtf = either (error . displayException) id . encodeWith utf8
219
219
#endif
220
220
221
+ #ifdef WINDOWS
221
222
-- | Encode a 'String' with the specified encoding.
222
- encodeWith :: TextEncoding
223
+ --
224
+ -- Note: We expect a "wide char" encoding (e.g. UCS-2 or UTF-16). Anything
225
+ -- that works with @Word16@ boundaries. Picking an incompatible encoding may crash
226
+ -- filepath operations.
227
+ encodeWith :: TextEncoding -- ^ text encoding (wide char)
223
228
-> String
224
229
-> Either EncodingException PLATFORM_STRING
225
230
encodeWith enc str = unsafePerformIO $ do
226
- #ifdef WINDOWS
227
231
r <- try @ SomeException $ GHC. withCStringLen enc str $ \ cstr -> WindowsString <$> BS8. packCStringLen cstr
228
232
evaluate $ force $ first (flip EncodingError Nothing . displayException) r
229
233
#else
234
+ -- | Encode a 'String' with the specified encoding.
235
+ encodeWith :: TextEncoding
236
+ -> String
237
+ -> Either EncodingException PLATFORM_STRING
238
+ encodeWith enc str = unsafePerformIO $ do
230
239
r <- try @ SomeException $ GHC. withCStringLen enc str $ \ cstr -> PosixString <$> BSP. packCStringLen cstr
231
240
evaluate $ force $ first (flip EncodingError Nothing . displayException) r
232
241
#endif
Original file line number Diff line number Diff line change @@ -55,9 +55,13 @@ encodeUtf = fmap OsString . PF.encodeUtf
55
55
unsafeEncodeUtf :: HasCallStack => String -> OsString
56
56
unsafeEncodeUtf = OsString . PF. unsafeEncodeUtf
57
57
58
- -- | Encode an 'OsString' given the platform specific encodings.
58
+ -- | Encode a 'FilePath' with the specified encoding.
59
+ --
60
+ -- Note: on windows, we expect a "wide char" encoding (e.g. UCS-2 or UTF-16). Anything
61
+ -- that works with @Word16@ boundaries. Picking an incompatible encoding may crash
62
+ -- filepath operations.
59
63
encodeWith :: TextEncoding -- ^ unix text encoding
60
- -> TextEncoding -- ^ windows text encoding
64
+ -> TextEncoding -- ^ windows text encoding (wide char)
61
65
-> String
62
66
-> Either EncodingException OsString
63
67
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
You can’t perform that action at this time.
0 commit comments