Skip to content

Commit 664b776

Browse files
committed
More renaming
1 parent 9b2c8e1 commit 664b776

File tree

16 files changed

+313
-296
lines changed

16 files changed

+313
-296
lines changed

Generate.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ main = do
4848
,"import qualified System.OsPath.Windows as AFP_W"
4949
,"import qualified System.OsPath.Posix as AFP_P"
5050
#endif
51-
,"instance IsString WindowsString where fromString = WS . either (error . show) id . encodeWith (mkUTF16le TransliterateCodingFailure)"
52-
,"instance IsString PosixString where fromString = PS . either (error . show) id . encodeWith (mkUTF8 TransliterateCodingFailure)"
51+
,"instance IsString WindowsString where fromString = WS . either (error . show) id . encodeWithTE (mkUTF16le TransliterateCodingFailure)"
52+
,"instance IsString PosixString where fromString = PS . either (error . show) id . encodeWithTE (mkUTF8 TransliterateCodingFailure)"
5353
,"#if defined(mingw32_HOST_OS) || defined(__MINGW32__)"
54-
,"instance IsString OsString where fromString = OsString . WS . either (error . show) id . encodeWith (mkUTF16le TransliterateCodingFailure)"
54+
,"instance IsString OsString where fromString = OsString . WS . either (error . show) id . encodeWithTE (mkUTF16le TransliterateCodingFailure)"
5555
,"#else"
56-
,"instance IsString OsString where fromString = OsString . PS . either (error . show) id . encodeWith (mkUTF8 TransliterateCodingFailure)"
56+
,"instance IsString OsString where fromString = OsString . PS . either (error . show) id . encodeWithTE (mkUTF8 TransliterateCodingFailure)"
5757
,"#endif"
5858
,"tests :: [(String, Property)]"
5959
,"tests ="] ++

System/FilePath/Internal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ import Data.List(stripPrefix, isSuffixOf, uncons)
127127
#define FILEPATH FilePath
128128
#else
129129
import Prelude (fromIntegral)
130-
import System.OsPath.Encoding ( encodeWith )
130+
import System.OsPath.Encoding ( encodeWithTE )
131131
import GHC.IO.Encoding.Failure ( CodingFailureMode(..) )
132132
import qualified Data.Char as C
133133
#ifdef WINDOWS
@@ -1180,10 +1180,10 @@ snoc str = \c -> str <> [c]
11801180
#else
11811181
#ifdef WINDOWS
11821182
fromString :: P.String -> STRING
1183-
fromString = P.either (P.error . P.show) P.id . encodeWith (mkUTF16le ErrorOnCodingFailure)
1183+
fromString = P.either (P.error . P.show) P.id . encodeWithTE (mkUTF16le ErrorOnCodingFailure)
11841184
#else
11851185
fromString :: P.String -> STRING
1186-
fromString = P.either (P.error . P.show) P.id . encodeWith (mkUTF8 ErrorOnCodingFailure)
1186+
fromString = P.either (P.error . P.show) P.id . encodeWithTE (mkUTF8 ErrorOnCodingFailure)
11871187
#endif
11881188

11891189
_a, _z, _A, _Z, _period, _quotedbl, _backslash, _slash, _question, _U, _N, _C, _colon, _semicolon, _US, _less, _greater, _bar, _asterisk, _nul, _space, _underscore :: CHAR

System/OsPath/Common.hs

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,21 @@ module System.OsPath
4040
, OsChar
4141
#endif
4242
-- * Filepath construction
43+
, PS.encodeUtf
44+
, PS.encodeWith
45+
, PS.encodeFS
4346
#if defined(WINDOWS) || defined(POSIX)
44-
, toPlatformStringUtf
45-
, toPlatformStringEnc
46-
, toPlatformStringFS
4747
, pstr
48-
, packPlatformString
4948
#else
50-
, toOsPathUtf
51-
, toOsPathEnc
52-
, toOsPathFS
5349
, osp
54-
, packOsPath
5550
#endif
51+
, PS.pack
5652

5753
-- * Filepath deconstruction
58-
#if defined(WINDOWS) || defined(POSIX)
59-
, fromPlatformStringUtf
60-
, fromPlatformStringEnc
61-
, fromPlatformStringFS
62-
, unpackPlatformString
63-
#else
64-
, fromOsPathUtf
65-
, fromOsPathEnc
66-
, fromOsPathFS
67-
, unpackOsPath
68-
#endif
54+
, PS.decodeUtf
55+
, PS.decodeWith
56+
, PS.decodeFS
57+
, PS.unpack
6958

7059
-- * Word construction
7160
, unsafeFromChar
@@ -119,53 +108,53 @@ where
119108

120109
#ifdef WINDOWS
121110
import System.OsPath.Types
122-
import System.OsString.Windows
111+
import System.OsString.Windows as PS
123112
( unsafeFromChar
124113
, toChar
125-
, fromPlatformStringUtf
126-
, fromPlatformStringEnc
127-
, fromPlatformStringFS
128-
, packPlatformString
114+
, decodeUtf
115+
, decodeWith
116+
, decodeFS
117+
, pack
129118
, pstr
130-
, toPlatformStringUtf
131-
, toPlatformStringEnc
132-
, toPlatformStringFS
133-
, unpackPlatformString
119+
, encodeUtf
120+
, encodeWith
121+
, encodeFS
122+
, unpack
134123
)
135124
import Data.Bifunctor ( bimap )
136125
import qualified System.OsPath.Windows.Internal as C
137126

138127
#elif defined(POSIX)
139128

140129
import System.OsPath.Types
141-
import System.OsString.Posix
130+
import System.OsString.Posix as PS
142131
( unsafeFromChar
143132
, toChar
144-
, fromPlatformStringUtf
145-
, fromPlatformStringEnc
146-
, fromPlatformStringFS
147-
, packPlatformString
133+
, decodeUtf
134+
, decodeWith
135+
, decodeFS
136+
, pack
148137
, pstr
149-
, toPlatformStringUtf
150-
, toPlatformStringEnc
151-
, toPlatformStringFS
152-
, unpackPlatformString
138+
, encodeUtf
139+
, encodeWith
140+
, encodeFS
141+
, unpack
153142
)
154143
import Data.Bifunctor ( bimap )
155144
import qualified System.OsPath.Posix.Internal as C
156145

157146
#else
158147

159-
import System.OsPath.Internal
148+
import System.OsPath.Internal as PS
160149
( osp
161-
, fromOsPathUtf
162-
, fromOsPathEnc
163-
, fromOsPathFS
164-
, packOsPath
165-
, toOsPathUtf
166-
, toOsPathEnc
167-
, toOsPathFS
168-
, unpackOsPath
150+
, decodeUtf
151+
, decodeWith
152+
, decodeFS
153+
, pack
154+
, encodeUtf
155+
, encodeWith
156+
, encodeFS
157+
, unpack
169158
)
170159
import System.OsPath.Types
171160
( OsPath )

System/OsPath/Encoding.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module System.OsPath.Encoding
1313
, ucs2le_encode
1414

1515
-- * base encoding
16-
, encodeWith
17-
, decodeWith
16+
, encodeWithTE
17+
, decodeWithTE
1818
, encodeWithBasePosix
1919
, decodeWithBasePosix
2020
, encodeWithBaseWindows

System/OsPath/Encoding/Internal.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ peekFilePathLenPosix fp = getFileSystemEncoding >>= \enc -> GHC.peekCStringLen e
187187
--
188188

189189
-- | Decode with the given 'TextEncoding'.
190-
decodeWith :: TextEncoding -> BS8.ShortByteString -> Either EncodingException String
191-
decodeWith enc ba = unsafePerformIO $ do
190+
decodeWithTE :: TextEncoding -> BS8.ShortByteString -> Either EncodingException String
191+
decodeWithTE enc ba = unsafePerformIO $ do
192192
r <- try @SomeException $ BS8.useAsCStringLen ba $ \fp -> GHC.peekCStringLen enc fp
193193
evaluate $ force $ first (flip EncodingError Nothing . displayException) r
194194

195195
-- | Encode with the given 'TextEncoding'.
196-
encodeWith :: TextEncoding -> String -> Either EncodingException BS8.ShortByteString
197-
encodeWith enc str = unsafePerformIO $ do
196+
encodeWithTE :: TextEncoding -> String -> Either EncodingException BS8.ShortByteString
197+
encodeWithTE enc str = unsafePerformIO $ do
198198
r <- try @SomeException $ GHC.withCStringLen enc str $ \cstr -> BS8.packCStringLen cstr
199199
evaluate $ force $ first (flip EncodingError Nothing . displayException) r
200200

System/OsPath/Internal.hs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module System.OsPath.Internal where
77
import {-# SOURCE #-} System.OsPath
88
( isValid )
99
import System.OsPath.Types
10-
import System.OsString.Internal
10+
import System.OsString.Internal hiding ( fromBytes )
1111
import qualified System.OsString.Internal as OS
1212

1313
import Control.Monad.Catch
@@ -31,17 +31,17 @@ import System.OsPath.Encoding ( EncodingException(..) )
3131
-- On unix this encodes as UTF8 (strictly), which is a good guess.
3232
--
3333
-- Throws a 'EncodingException' if encoding fails.
34-
toOsPathUtf :: MonadThrow m => String -> m OsPath
35-
toOsPathUtf = toOsStringUtf
34+
encodeUtf :: MonadThrow m => FilePath -> m OsPath
35+
encodeUtf = OS.encodeUtf
3636

37-
-- | Like 'toOsPathUtf', except allows to provide encodings.
38-
toOsPathEnc :: TextEncoding -- ^ unix text encoding
39-
-> TextEncoding -- ^ windows text encoding
40-
-> String
41-
-> Either EncodingException OsPath
42-
toOsPathEnc = toOsStringEnc
37+
-- | Encode a 'FilePath' with the specified encoding.
38+
encodeWith :: TextEncoding -- ^ unix text encoding
39+
-> TextEncoding -- ^ windows text encoding
40+
-> FilePath
41+
-> Either EncodingException OsPath
42+
encodeWith = OS.encodeWith
4343

44-
-- | Like 'toOsPathUtf', except this mimics the behavior of the base library when doing filesystem
44+
-- | Like 'encodeUtf', except this mimics the behavior of the base library when doing filesystem
4545
-- operations, which is:
4646
--
4747
-- 1. on unix, uses shady PEP 383 style encoding (based on the current locale,
@@ -52,8 +52,8 @@ toOsPathEnc = toOsStringEnc
5252
-- Looking up the locale requires IO. If you're not worried about calls
5353
-- to 'setFileSystemEncoding', then 'unsafePerformIO' may be feasible (make sure
5454
-- to deeply evaluate the result to catch exceptions).
55-
toOsPathFS :: String -> IO OsPath
56-
toOsPathFS = toOsStringFS
55+
encodeFS :: FilePath -> IO OsPath
56+
encodeFS = OS.encodeFS
5757

5858

5959
-- | Partial unicode friendly decoding.
@@ -62,17 +62,17 @@ toOsPathFS = toOsStringFS
6262
-- On unix this decodes as UTF8 (strictly), which is a good guess.
6363
--
6464
-- Throws a 'EncodingException' if decoding fails.
65-
fromOsPathUtf :: MonadThrow m => OsPath -> m String
66-
fromOsPathUtf = fromOsStringUtf
65+
decodeUtf :: MonadThrow m => OsPath -> m FilePath
66+
decodeUtf = OS.decodeUtf
6767

68-
-- | Like 'fromOsPathUtf', except allows to provide encodings.
69-
fromOsPathEnc :: TextEncoding -- ^ unix text encoding
70-
-> TextEncoding -- ^ windows text encoding
71-
-> OsPath
72-
-> Either EncodingException String
73-
fromOsPathEnc = fromOsStringEnc
68+
-- | Decode an 'OsPath' with the specified encoding.
69+
decodeWith :: TextEncoding -- ^ unix text encoding
70+
-> TextEncoding -- ^ windows text encoding
71+
-> OsPath
72+
-> Either EncodingException FilePath
73+
decodeWith = OS.decodeWith
7474

75-
-- | Like 'fromOsPathUtf', except this mimics the behavior of the base library when doing filesystem
75+
-- | Like 'decodeUtf', except this mimics the behavior of the base library when doing filesystem
7676
-- operations, which is:
7777
--
7878
-- 1. on unix, uses shady PEP 383 style encoding (based on the current locale,
@@ -83,24 +83,24 @@ fromOsPathEnc = fromOsStringEnc
8383
-- Looking up the locale requires IO. If you're not worried about calls
8484
-- to 'setFileSystemEncoding', then 'unsafePerformIO' may be feasible (make sure
8585
-- to deeply evaluate the result to catch exceptions).
86-
fromOsPathFS :: OsPath -> IO String
87-
fromOsPathFS = fromOsStringFS
86+
decodeFS :: OsPath -> IO FilePath
87+
decodeFS = OS.decodeFS
8888

8989

9090
-- | Constructs an @OsPath@ from a ByteString.
9191
--
9292
-- On windows, this ensures valid UCS-2LE, on unix it is passed unchanged/unchecked.
9393
--
9494
-- Throws 'EncodingException' on invalid UCS-2LE on windows (although unlikely).
95-
bytesToOsPath :: MonadThrow m
96-
=> ByteString
97-
-> m OsPath
98-
bytesToOsPath = OS.bytesToOsString
95+
fromBytes :: MonadThrow m
96+
=> ByteString
97+
-> m OsPath
98+
fromBytes = OS.fromBytes
9999

100100

101101
mkOsPath :: ByteString -> Q Exp
102102
mkOsPath bs =
103-
case bytesToOsPath bs of
103+
case fromBytes bs of
104104
Just afp' ->
105105
if isValid afp'
106106
then lift afp'
@@ -115,15 +115,15 @@ osp = qq mkOsPath
115115

116116

117117
-- | Unpack an 'OsPath' to a list of 'OsChar'.
118-
unpackOsPath :: OsPath -> [OsChar]
119-
unpackOsPath = unpackOsString
118+
unpack :: OsPath -> [OsChar]
119+
unpack = OS.unpack
120120

121121

122122
-- | Pack a list of 'OsChar' to an 'OsPath'.
123123
--
124124
-- Note that using this in conjunction with 'unsafeFromChar' to
125125
-- convert from @[Char]@ to 'OsPath' is probably not what
126126
-- you want, because it will truncate unicode code points.
127-
packOsPath :: [OsChar] -> OsPath
128-
packOsPath = packOsString
127+
pack :: [OsChar] -> OsPath
128+
pack = OS.pack
129129

System/OsString.hs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ module System.OsString
1919
-- * String types
2020
OsString
2121

22-
-- * String construction
23-
, toOsStringUtf
24-
, toOsStringEnc
25-
, toOsStringFS
22+
-- * OsString construction
23+
, encodeUtf
24+
, encodeWith
25+
, encodeFS
2626
, osstr
27-
, packOsString
27+
, pack
2828

29-
-- * String deconstruction
30-
, fromOsStringUtf
31-
, fromOsStringEnc
32-
, fromOsStringFS
33-
, unpackOsString
29+
-- * OsString deconstruction
30+
, decodeUtf
31+
, decodeWith
32+
, decodeFS
33+
, unpack
3434

3535
-- * Word types
3636
, OsChar
@@ -46,15 +46,15 @@ where
4646
import System.OsString.Internal
4747
( unsafeFromChar
4848
, toChar
49-
, fromOsStringUtf
50-
, fromOsStringEnc
51-
, fromOsStringFS
49+
, encodeUtf
50+
, encodeWith
51+
, encodeFS
5252
, osstr
53-
, packOsString
54-
, toOsStringUtf
55-
, toOsStringEnc
56-
, toOsStringFS
57-
, unpackOsString
53+
, pack
54+
, decodeUtf
55+
, decodeWith
56+
, decodeFS
57+
, unpack
5858
)
5959
import System.OsString.Internal.Types
6060
( OsString, OsChar )

0 commit comments

Comments
 (0)