Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Commit f531a4e

Browse files
committed
Remove path manipulation functions
These will be published in a separate module.
1 parent f1e5070 commit f531a4e

4 files changed

Lines changed: 0 additions & 354 deletions

File tree

README.md

Lines changed: 0 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -258,239 +258,6 @@ Returns:
258258

259259
- The result(s) of the call to `callback`
260260

261-
### Path Manipulation Functions
262-
263-
This library includes wrappers around the following functions from
264-
the [filepath] library for the current platform (POSIX or
265-
Windows). All examples below are for [POSIX systems].
266-
267-
#### drop_extension
268-
269-
`drop_extension (filepath)`
270-
271-
Remove last extension, and the `.` preceding it.
272-
273-
```lua
274-
drop_extension("/directory/path.ext") == "/directory/path"
275-
```
276-
277-
Parameters:
278-
279-
`filepath`
280-
: path (string)
281-
282-
Returns:
283-
284-
- The modified filepath without extension (string).
285-
286-
This function wraps [System.FilePath.dropExtension].
287-
288-
#### has_extension
289-
290-
`has_extensions (filepath)`
291-
292-
Does the given filename have an extension?
293-
294-
```lua
295-
has_extension("/directory/path.ext") == true
296-
has_extension("/directory/path") == false
297-
```
298-
299-
Parameters:
300-
301-
`filepath`
302-
: path (string)
303-
304-
Returns:
305-
306-
- `true` iff `filepath` has an extension, `false` otherwise
307-
(boolean).
308-
309-
This function wraps [System.FilePath.hasExtension].
310-
311-
#### is_absolute
312-
313-
`is_absolute (filepath)`
314-
315-
Is a path absolute? (same as `not is_relative(filepath)`)
316-
317-
Parameters:
318-
319-
`filepath`
320-
: path (string)
321-
322-
Returns:
323-
324-
- `true` iff `filepath` is an absolute path, `false` otherwise
325-
(boolean).
326-
327-
This function wraps [System.FilePath.isAbsolute].
328-
329-
#### is_relative
330-
331-
`ìs_relative (filepath)`
332-
333-
Is a path relative, or is it fixed to the root?
334-
335-
```lua
336-
is_relative("test/path") == true
337-
is_relative("/test") == false
338-
is_relative("/") == false
339-
```
340-
341-
Parameters:
342-
343-
`filepath`
344-
: path (string)
345-
346-
Returns:
347-
348-
- `true` iff `filepath` is a relative path, `false` otherwise
349-
(boolean).
350-
351-
This function wraps [System.FilePath.isRelative].
352-
353-
#### join_path
354-
355-
`join_path (filepaths)`
356-
357-
Join path elements back together by the directory separator.
358-
359-
```lua
360-
join_path({"/","directory/","file.ext"}) == "/directory/file.ext"
361-
```
362-
363-
Parameters:
364-
365-
`filepaths`
366-
: list of path strings
367-
368-
Returns:
369-
370-
- The joined path (string).
371-
372-
This function wraps [System.FilePath.joinPath].
373-
374-
#### normalise
375-
376-
`normalise (filepath)`
377-
378-
Normalise a path. See examples [here][System.FilePath.normalize].
379-
<!-- TODO explain so it becomes understandable without a link -->
380-
381-
Parameters:
382-
383-
`filepath`
384-
: path (string)
385-
386-
Returns:
387-
388-
- The normalised path (string).
389-
390-
This function wraps [System.FilePath.normalise].
391-
392-
#### split_directories
393-
394-
`split_directories (filepath)`
395-
396-
Split a path by the directory separator.
397-
398-
```lua
399-
split_directories("/directory/file.ext") == {"/","directory","file.ext"}
400-
split_directories("test/file") == {"test","file"}
401-
split_directories("/test/file") == {"/","test","file"}
402-
```
403-
404-
Parameters:
405-
406-
`filepath`
407-
: path (string)
408-
409-
Returns:
410-
411-
- A list of all directory paths (list of strings).
412-
413-
This function wraps [System.FilePath.splitDirectories].
414-
415-
#### take_directory
416-
417-
`take_directory (filepath)`
418-
419-
Get the directory name, move up one level.
420-
421-
```lua
422-
take_directory("/foo/bar/baz") == "/foo/bar"
423-
take_directory("/foo/bar/baz/") == "/foo/bar/baz"
424-
```
425-
426-
Parameters:
427-
428-
`filepath`
429-
: path (string)
430-
431-
Returns:
432-
433-
- The filepath up to the last directory separator (string).
434-
435-
This function wraps [System.FilePath.takeDirectory].
436-
437-
#### take_extensions
438-
439-
`take_extensions (filepath)`
440-
441-
Get all extensions.
442-
443-
```lua
444-
take_extensions("/directory/path.ext") == ".ext"
445-
take_extensions("file.tar.gz") == ".tar.gz"
446-
```
447-
448-
Parameters:
449-
450-
`filepath`
451-
: path (string)
452-
453-
Returns:
454-
455-
- String of all extensions (string).
456-
457-
This function wraps [System.FilePath.takeExtensions].
458-
459-
#### take_filename
460-
461-
`take_filename (filepath)`
462-
463-
Get the file name.
464-
465-
```lua
466-
take_filename("/directory/file.ext") == "file.ext"
467-
take_filename("test/") == ""
468-
```
469-
470-
Parameters:
471-
472-
`filepath`
473-
: path (string)
474-
475-
Returns:
476-
477-
- The file name (string).
478-
479-
This function wraps [System.FilePath.takeFileName].
480-
481-
482-
[filepath]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath.html
483-
[POSIX systems]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html
484-
[System.FilePath.dropExtension]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:dropExtension
485-
[System.FilePath.hasExtension]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:hasExtension
486-
[System.FilePath.isAbsolute]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:isAbsolute
487-
[System.FilePath.isRelative]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:isRelative
488-
[System.FilePath.joinPath]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:joinPath
489-
[System.FilePath.normalise]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:normalise
490-
[System.FilePath.splitDirectories]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:splitDirectories.
491-
[System.FilePath.takeDirectory]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:takeDirectory
492-
[System.FilePath.takeExtensions]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:takeExtensions.
493-
[System.FilePath.takeFileName]: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/System-FilePath-Posix.html#v:takeFileName.
494261

495262
License
496263
-------

hslua-module-system.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ library
3636
, containers >= 0.5 && < 0.7
3737
, directory >= 1.3 && < 1.4
3838
, exceptions >= 0.8 && < 0.11
39-
, filepath >= 1.4 && < 1.5
4039
, hslua >= 1.0.3 && < 1.2
4140
, temporary >= 1.2 && < 1.4
4241
default-extensions: LambdaCase

src/Foreign/Lua/Module/System.hs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ module Foreign.Lua.Module.System (
3333
, with_env
3434
, with_tmpdir
3535
, with_wd
36-
37-
-- * Path manipulations
38-
, drop_extensions
39-
, has_extension
40-
, is_absolute
41-
, is_relative
42-
, join_path
43-
, normalise
44-
, split_directories
45-
, take_directory
46-
, take_extensions
47-
, take_filename
4836
)
4937
where
5038

@@ -62,7 +50,6 @@ import qualified System.Directory as Directory
6250
import qualified System.Environment as Env
6351
import qualified System.Info as Info
6452
import qualified System.IO.Temp as Temp
65-
import qualified System.FilePath as Fp
6653

6754
--
6855
-- Module
@@ -88,17 +75,6 @@ pushModule = do
8875
Lua.addfunction "with_env" with_env
8976
Lua.addfunction "with_tmpdir" with_tmpdir
9077
Lua.addfunction "with_wd" with_wd
91-
-- * Path manipulations
92-
Lua.addfunction "take_directory" take_directory
93-
Lua.addfunction "take_filename" take_filename
94-
Lua.addfunction "take_extensions" take_extensions
95-
Lua.addfunction "split_directories" split_directories
96-
Lua.addfunction "has_extension" has_extension
97-
Lua.addfunction "drop_extensions" drop_extensions
98-
Lua.addfunction "join_path" join_path
99-
Lua.addfunction "is_relative" is_relative
100-
Lua.addfunction "is_absolute" is_absolute
101-
Lua.addfunction "normalise" normalise
10278
return 1
10379

10480
-- | Add the @system@ module under the given name to the table of
@@ -229,47 +205,3 @@ with_tmpdir parentDir tmpl callback =
229205
-- all args given. Second value must be converted to a string.
230206
tmpl' <- Lua.peek (fromAnyValue tmpl)
231207
Temp.withTempDirectory parentDir tmpl' (invokeWithFilePath callback')
232-
233-
--
234-
-- Path manipulations
235-
--
236-
237-
-- | See @System.FilePath.dropExtension@
238-
drop_extensions :: FilePath -> Lua String
239-
drop_extensions fp = return (Fp.dropExtensions fp)
240-
241-
-- | See @System.FilePath.hasExtension@
242-
has_extension :: FilePath -> Lua Bool
243-
has_extension fp = return (Fp.hasExtension fp)
244-
245-
-- | See @System.FilePath.isAbsolute@
246-
is_absolute :: FilePath -> Lua Bool
247-
is_absolute fp = return (Fp.isAbsolute fp)
248-
249-
-- | See @System.FilePath.isRelative@
250-
is_relative :: FilePath -> Lua Bool
251-
is_relative fp = return (Fp.isRelative fp)
252-
253-
-- | See @System.FilePath.joinPath@
254-
join_path :: [FilePath] -> Lua FilePath
255-
join_path fps = return (Fp.joinPath fps)
256-
257-
-- | See @System.FilePath.normalise@
258-
normalise :: FilePath -> Lua FilePath
259-
normalise fp = return (Fp.normalise fp)
260-
261-
-- | See @System.FilePath.splitDirectories@
262-
split_directories :: FilePath -> Lua [FilePath]
263-
split_directories fp = return (Fp.splitDirectories fp)
264-
265-
-- | See @System.FilePath.takeDirectory@
266-
take_directory :: FilePath -> Lua FilePath
267-
take_directory fp = return (Fp.takeDirectory fp)
268-
269-
-- | See @System.FilePath.takeExtensions@
270-
take_extensions :: FilePath -> Lua String
271-
take_extensions fp = return (Fp.takeExtensions fp)
272-
273-
-- | See @System.FilePath.takeFilename@
274-
take_filename :: FilePath -> Lua FilePath
275-
take_filename fp = return (Fp.takeFileName fp)

test/test-system.lua

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -196,56 +196,4 @@ return {
196196
end)
197197
end),
198198
},
199-
200-
group 'path-manipulations' {
201-
test('take_directory', function ()
202-
local r = system.take_directory("/a/b/c/d.ext.png")
203-
assert.are_equal(r, '/a/b/c')
204-
end),
205-
test('take_filename', function ()
206-
local r = system.take_filename("/a/b/c/d.ext.png")
207-
assert.are_equal(r, "d.ext.png")
208-
end),
209-
test('take_extensions', function ()
210-
local r = system.take_extensions("/a/b/c/d.ext.png")
211-
assert.are_equal(r, ".ext.png")
212-
end),
213-
test('drop_extensions', function ()
214-
local r = system.drop_extensions("/a/b/c/d.ext.png")
215-
assert.are_equal(r, "/a/b/c/d")
216-
end),
217-
test('has_extension', function ()
218-
local r = system.has_extension("/a/b/c/d.ext.png")
219-
assert.is_truthy(r)
220-
r = system.has_extension("/a/b/c/d")
221-
assert.is_falsy(r)
222-
end),
223-
test('split_directories', function ()
224-
local r = system.split_directories("/a/b/c/d.ext.png")
225-
local ref = {"/", "a", "b", "c", "d.ext.png"}
226-
for index, value in ipairs(r) do
227-
assert.are_equal(value, ref[index])
228-
end
229-
end),
230-
test('join_path', function ()
231-
local r = system.join_path({"/", "a", "b", "c", "d.ext.png"})
232-
assert.are_equal(r, "/a/b/c/d.ext.png")
233-
end),
234-
test('is_relative', function ()
235-
local r = system.is_relative("/a/b/c/d.ext.png")
236-
assert.is_falsy(r)
237-
r = system.is_relative("a/b/c/d.ext.png")
238-
assert.is_truthy(r)
239-
end),
240-
test('is_absolute', function ()
241-
local r = system.is_absolute("/a/b/c/d.ext.png")
242-
assert.is_truthy(r)
243-
r = system.is_absolute("a/b/c/d.ext.png")
244-
assert.is_falsy(r)
245-
end),
246-
test('normalise', function ()
247-
local r = system.normalise("//a/b//././c////d.ext.png")
248-
assert.are_equal(r, "/a/b/c/d.ext.png")
249-
end)
250-
}
251199
}

0 commit comments

Comments
 (0)