File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ module System.OsPath
42
42
#endif
43
43
-- * Filepath construction
44
44
, PS. encodeUtf
45
+ , PS. unsafeEncodeUtf
45
46
, PS. encodeWith
46
47
, PS. encodeFS
47
48
#if defined(WINDOWS) || defined(POSIX)
@@ -117,6 +118,7 @@ import System.OsString.Windows as PS
117
118
, decodeFS
118
119
, pack
119
120
, encodeUtf
121
+ , unsafeEncodeUtf
120
122
, encodeWith
121
123
, encodeFS
122
124
, unpack
@@ -149,6 +151,7 @@ import System.OsString.Posix as PS
149
151
, decodeFS
150
152
, pack
151
153
, encodeUtf
154
+ , unsafeEncodeUtf
152
155
, encodeWith
153
156
, encodeFS
154
157
, unpack
@@ -165,6 +168,7 @@ import System.OsPath.Internal as PS
165
168
, decodeFS
166
169
, pack
167
170
, encodeUtf
171
+ , unsafeEncodeUtf
168
172
, encodeWith
169
173
, encodeFS
170
174
, unpack
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import GHC.IO.Encoding.UTF16 ( mkUTF16le )
34
34
import qualified System.OsPath.Posix as PF
35
35
import GHC.IO.Encoding.UTF8 ( mkUTF8 )
36
36
#endif
37
+ import GHC.Stack (HasCallStack )
37
38
38
39
39
40
@@ -42,10 +43,18 @@ import GHC.IO.Encoding.UTF8 ( mkUTF8 )
42
43
-- On windows this encodes as UTF16-LE (strictly), which is a pretty good guess.
43
44
-- On unix this encodes as UTF8 (strictly), which is a good guess.
44
45
--
45
- -- Throws a 'EncodingException' if encoding fails.
46
+ -- Throws an 'EncodingException' if encoding fails. If the input does not
47
+ -- contain surrogate chars, you can use 'unsafeEncodeUtf'.
46
48
encodeUtf :: MonadThrow m => FilePath -> m OsPath
47
49
encodeUtf = OS. encodeUtf
48
50
51
+ -- | Unsafe unicode friendly encoding.
52
+ --
53
+ -- Like 'encodeUtf', except it crashes when the input contains
54
+ -- surrogate chars. For sanitized input, this can be useful.
55
+ unsafeEncodeUtf :: HasCallStack => String -> OsString
56
+ unsafeEncodeUtf = OS. unsafeEncodeUtf
57
+
49
58
-- | Encode a 'FilePath' with the specified encoding.
50
59
encodeWith :: TextEncoding -- ^ unix text encoding
51
60
-> TextEncoding -- ^ windows text encoding
Original file line number Diff line number Diff line change 1
1
packages : ./
2
+
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ library
96
96
, deepseq
97
97
, exceptions
98
98
, template-haskell
99
- , os-string >= 2.0.0
99
+ , os-string >= 2.0.1
100
100
101
101
ghc-options : -Wall
102
102
@@ -116,7 +116,7 @@ test-suite filepath-tests
116
116
, base
117
117
, bytestring >= 0.11.3.0
118
118
, filepath
119
- , os-string >= 2.0.0
119
+ , os-string >= 2.0.1
120
120
, QuickCheck >= 2.7 && < 2.15
121
121
122
122
default-language : Haskell2010
@@ -138,7 +138,7 @@ test-suite filepath-equivalent-tests
138
138
, base
139
139
, bytestring >= 0.11.3.0
140
140
, filepath
141
- , os-string >= 2.0.0
141
+ , os-string >= 2.0.1
142
142
, QuickCheck >= 2.7 && < 2.15
143
143
144
144
test-suite abstract-filepath
@@ -157,7 +157,7 @@ test-suite abstract-filepath
157
157
, bytestring >= 0.11.3.0
158
158
, deepseq
159
159
, filepath
160
- , os-string >= 2.0.0
160
+ , os-string >= 2.0.1
161
161
, QuickCheck >= 2.7 && < 2.15
162
162
, quickcheck-classes-base ^>= 0.6.2
163
163
@@ -172,7 +172,7 @@ benchmark bench-filepath
172
172
, bytestring >= 0.11.3.0
173
173
, deepseq
174
174
, filepath
175
- , os-string >= 2.0.0
175
+ , os-string >= 2.0.1
176
176
, tasty-bench
177
177
178
178
ghc-options : -with-rtsopts=-A32m
You can’t perform that action at this time.
0 commit comments