Skip to content

Commit ac0456e

Browse files
committed
Expose/Implement multiple functions in the FileSystem.Path module
1 parent d330733 commit ac0456e

2 files changed

Lines changed: 78 additions & 13 deletions

File tree

core/src/Streamly/FileSystem/Path.hs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ module Streamly.FileSystem.Path
101101
-- * Type
102102
Path
103103

104-
-- * Conversions
105-
, IsPath (..)
106-
, adapt
107-
108104
-- * Construction
105+
, fromChunk
109106
, fromString
110107

111108
-- * Statically Verified String Literals
@@ -117,15 +114,51 @@ module Streamly.FileSystem.Path
117114
, pathE
118115

119116
-- * Elimination
117+
, toChunk
118+
, toChars
120119
, toString
120+
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
121+
, asCString
122+
#else
123+
, asCWString
124+
#endif
121125

122-
-- * Operations
123-
-- , dropTrailingSeparators
124-
, isRooted
125-
, isBranch
126+
-- * Separators
127+
, dropTrailingSeparators
128+
, hasTrailingSeparator
129+
, addTrailingSeparator
126130

127-
-- * Combinators
131+
-- * Joining
132+
, unsafeExtend
128133
, extend
134+
, extendByString
135+
136+
-- * Splitting
137+
, splitRoot
138+
, splitPath
139+
, splitPath_
140+
, splitFile
141+
142+
-- * Extension
143+
, splitExtension
144+
, dropExtension
145+
-- , addExtension
146+
-- , replaceExtension
147+
148+
-- ** Path View
149+
, takeFileName
150+
, takeDirectory
151+
, takeExtension
152+
, takeBaseName
153+
154+
-- * Equality
155+
, EqCfg
156+
, eqPath
157+
#ifndef IS_WINDOWS
158+
, ignoreTrailingSeparators
159+
, ignoreCase
160+
, allowRelativeEquality
161+
#endif
129162
)
130163
where
131164

core/src/Streamly/Internal/FileSystem/PosixPath.hs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ module Streamly.Internal.FileSystem.OS_PATH
131131
, isBranch
132132

133133
-- * Joining
134-
, addString
134+
, extendByString
135135
-- , concat
136136
, unsafeExtend
137137
#ifndef IS_WINDOWS
@@ -153,9 +153,17 @@ module Streamly.Internal.FileSystem.OS_PATH
153153
, splitFirst
154154
, splitLast
155155

156+
-- ** Extension
156157
, splitExtension
157158
, dropExtension
158159
, addExtension
160+
, replaceExtension
161+
162+
-- ** Path View
163+
, takeFileName
164+
, takeDirectory
165+
, takeExtension
166+
, takeBaseName
159167

160168
-- * Equality
161169
, EqCfg
@@ -413,9 +421,12 @@ fromString = fromChars . Stream.fromList
413421
-- Throws an error if the resulting path is not a valid path as per
414422
-- 'isValidPath'.
415423
--
416-
-- /Unimplemented/
417-
addString :: OS_PATH -> [Char] -> OS_PATH
418-
addString (OS_PATH _a) = undefined
424+
extendByString :: OS_PATH -> [Char] -> OS_PATH
425+
extendByString (OS_PATH a) b =
426+
OS_PATH $
427+
Common.append Common.OS_NAME
428+
(Common.toString Unicode.UNICODE_DECODER) a (rawFromString b)
429+
419430

420431
------------------------------------------------------------------------------
421432
-- Statically Verified Strings
@@ -1013,6 +1024,10 @@ splitExtension (OS_PATH a) =
10131024
fmap (bimap OS_PATH OS_PATH) $ Common.splitExtension Common.OS_NAME a
10141025
#endif
10151026

1027+
-- | Take the extension of a file if it has one.
1028+
takeExtension :: OS_PATH -> Maybe OS_PATH
1029+
takeExtension = fmap snd . splitExtension
1030+
10161031
-- | Drop the extension of a file if it has one.
10171032
dropExtension :: OS_PATH -> OS_PATH
10181033
dropExtension orig@(OS_PATH a) =
@@ -1028,6 +1043,23 @@ dropExtension orig@(OS_PATH a) =
10281043
addExtension :: OS_PATH -> OS_PATH -> OS_PATH
10291044
addExtension (OS_PATH _a) = undefined
10301045

1046+
-- /Unimplemented/
1047+
replaceExtension :: OS_PATH -> OS_PATH -> OS_PATH
1048+
replaceExtension (OS_PATH _a) = undefined
1049+
1050+
------------------------------------------------------------------------------
1051+
-- Path View
1052+
------------------------------------------------------------------------------
1053+
1054+
takeFileName :: OS_PATH -> Maybe OS_PATH
1055+
takeFileName = fmap snd . splitFile
1056+
1057+
takeBaseName :: OS_PATH -> Maybe OS_PATH
1058+
takeBaseName = fmap dropExtension . takeFileName
1059+
1060+
takeDirectory :: OS_PATH -> Maybe OS_PATH
1061+
takeDirectory x = splitFile x >>= fst
1062+
10311063
------------------------------------------------------------------------------
10321064
-- Path equality
10331065
------------------------------------------------------------------------------

0 commit comments

Comments
 (0)