Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
c734c582d4 | |||
03aab46ab5 | |||
4bf3e1c7c1 | |||
2d62dee4d0 | |||
3eb542bdfd | |||
5b87d0bf9a | |||
c822d2142e | |||
b80015bc4d | |||
b343ce830b |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Veit Heller
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@@ -5,7 +5,7 @@ is a simple file path library for Carp.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load "https://veitheller.de/git/carpentry/path@0.0.1")
|
(load "git@git.veitheller.de:carpentry/path.git@0.0.4")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
@@ -16,7 +16,7 @@ has some functions to work with the `PATH` environment variable.
|
|||||||
|
|
||||||
It assumes either Windows or POSIX-style separators.
|
It assumes either Windows or POSIX-style separators.
|
||||||
|
|
||||||
Look at [the documentation](https://veitheller.de/path) for more information.
|
Look at [the documentation](https://carpentry.dev/path) for more information.
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
|
886
docs/Path.html
886
docs/Path.html
@@ -9,8 +9,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<a href="http://github.com/carp-lang/Carp">
|
<a href="">
|
||||||
<img src="logo.png">
|
<img src="">
|
||||||
</a>
|
</a>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
path
|
path
|
||||||
@@ -25,13 +25,14 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h1>
|
<div class="module">
|
||||||
Path
|
<h1>
|
||||||
</h1>
|
Path
|
||||||
<div class="module-description">
|
</h1>
|
||||||
<p>is a simple file path library for Carp.</p>
|
<div class="module-description">
|
||||||
|
<p>is a simple file path library for Carp.</p>
|
||||||
<h2>Installation</h2>
|
<h2>Installation</h2>
|
||||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/path@0.0.1")
|
<pre><code class="language-clojure">(load "git@git.veitheller.de:carpentry/path.git@0.0.4")
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<h3>Usage</h3>
|
<h3>Usage</h3>
|
||||||
<p>The <code>Path</code> module mostly operates on <code>String</code> arguments. It allows you to
|
<p>The <code>Path</code> module mostly operates on <code>String</code> arguments. It allows you to
|
||||||
@@ -39,473 +40,473 @@ split, join, and merge paths and extensions in a lot of different ways. It also
|
|||||||
has some functions to work with the <code>PATH</code> environment variable.</p>
|
has some functions to work with the <code>PATH</code> environment variable.</p>
|
||||||
<p>It assumes either Windows or POSIX-style separators.</p>
|
<p>It assumes either Windows or POSIX-style separators.</p>
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#</>">
|
|
||||||
<h3 id="</>">
|
|
||||||
</>
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [a, b] String)
|
<a class="anchor" href="#</>">
|
||||||
</p>
|
<h3 id="</>">
|
||||||
<pre class="args">
|
</>
|
||||||
(</> before after)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>joins <code>before</code> and <code>after</code> using the default path separator.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [a, b] String)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(</> before after)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>joins <code>before</code> and <code>after</code> using the default path separator.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#absolute">
|
|
||||||
<h3 id="absolute">
|
|
||||||
absolute
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Maybe String))
|
<a class="anchor" href="#absolute">
|
||||||
</p>
|
<h3 id="absolute">
|
||||||
<pre class="args">
|
absolute
|
||||||
(absolute p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>makes an absolute path from <code>p</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Maybe String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(absolute p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>makes an absolute path from <code>p</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#absolute?">
|
|
||||||
<h3 id="absolute?">
|
|
||||||
absolute?
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] Bool)
|
<a class="anchor" href="#absolute?">
|
||||||
</p>
|
<h3 id="absolute?">
|
||||||
<pre class="args">
|
absolute?
|
||||||
(absolute? p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>checks whether a path is absolute.</p>
|
defn
|
||||||
<p>As such, it is the inverse to <a href="#relative">relative</a>.</p>
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] Bool)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(absolute? p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>checks whether a path is absolute.</p>
|
||||||
|
<p>As such, it is the inverse to <a href="#relative?">relative?</a>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#add-extension">
|
|
||||||
<h3 id="add-extension">
|
|
||||||
add-extension
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String, &String] String)
|
<a class="anchor" href="#add-extension">
|
||||||
</p>
|
<h3 id="add-extension">
|
||||||
<pre class="args">
|
add-extension
|
||||||
(add-extension p ext)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>adds an extension <code>ext</code> to a path <code>p</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a), (Ref String b)] String)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(add-extension p ext)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>adds an extension <code>ext</code> to a path <code>p</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#basename">
|
|
||||||
<h3 id="basename">
|
|
||||||
basename
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] String)
|
<a class="anchor" href="#basename">
|
||||||
</p>
|
<h3 id="basename">
|
||||||
<pre class="args">
|
basename
|
||||||
(basename p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>gets the basename of the path <code>p</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] String)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(basename p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>gets the basename of the path <code>p</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#cwd">
|
|
||||||
<h3 id="cwd">
|
|
||||||
cwd
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [] (Maybe String))
|
<a class="anchor" href="#cwd">
|
||||||
</p>
|
<h3 id="cwd">
|
||||||
<pre class="args">
|
cwd
|
||||||
(cwd)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>returns the current working directory as a <code>Maybe</code>. The ways in
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [] (Maybe String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(cwd)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>returns the current working directory as a <code>Maybe</code>. The ways in
|
||||||
which it can fail are OS-dependent, but it should happen relatively rare.</p>
|
which it can fail are OS-dependent, but it should happen relatively rare.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#drop-extension">
|
|
||||||
<h3 id="drop-extension">
|
|
||||||
drop-extension
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] String)
|
<a class="anchor" href="#drop-extension">
|
||||||
</p>
|
<h3 id="drop-extension">
|
||||||
<pre class="args">
|
drop-extension
|
||||||
(drop-extension p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>drops the extension of a path <code>p</code>. Does nothing if there
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] String)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(drop-extension p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>drops the extension of a path <code>p</code>. Does nothing if there
|
||||||
is none.</p>
|
is none.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#extension">
|
|
||||||
<h3 id="extension">
|
|
||||||
extension
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Maybe String))
|
<a class="anchor" href="#extension">
|
||||||
</p>
|
<h3 id="extension">
|
||||||
<pre class="args">
|
extension
|
||||||
(extension p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>gets the extension of a file as a <code>Maybe</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Maybe String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(extension p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>gets the extension of a file as a <code>Maybe</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#filename">
|
|
||||||
<h3 id="filename">
|
|
||||||
filename
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Maybe String))
|
<a class="anchor" href="#filename">
|
||||||
</p>
|
<h3 id="filename">
|
||||||
<pre class="args">
|
filename
|
||||||
(filename p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>gets the filename of the path <code>p</code> as a <code>(Maybe String)</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Maybe String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(filename p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>gets the filename of the path <code>p</code> as a <code>(Maybe String)</code>.</p>
|
||||||
<p>It will return <code>Nothing</code> if an empty string is passed.</p>
|
<p>It will return <code>Nothing</code> if an empty string is passed.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#get-search-path">
|
|
||||||
<h3 id="get-search-path">
|
|
||||||
get-search-path
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [] (Maybe (Array String)))
|
<a class="anchor" href="#get-search-path">
|
||||||
</p>
|
<h3 id="get-search-path">
|
||||||
<pre class="args">
|
get-search-path
|
||||||
(get-search-path)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>gets the <code>PATH</code> environment variable and splits it.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [] (Maybe (Array String)))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(get-search-path)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>gets the <code>PATH</code> environment variable and splits it.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#has-extension?">
|
|
||||||
<h3 id="has-extension?">
|
|
||||||
has-extension?
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] Bool)
|
<a class="anchor" href="#has-extension?">
|
||||||
</p>
|
<h3 id="has-extension?">
|
||||||
<pre class="args">
|
has-extension?
|
||||||
(has-extension? p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>cheks whether the path <code>p</code> has an extension.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] Bool)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(has-extension? p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>cheks whether the path <code>p</code> has an extension.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#is-extension?">
|
|
||||||
<h3 id="is-extension?">
|
|
||||||
is-extension?
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String, &String] Bool)
|
<a class="anchor" href="#is-extension?">
|
||||||
</p>
|
<h3 id="is-extension?">
|
||||||
<pre class="args">
|
is-extension?
|
||||||
(is-extension? p ext)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>checks whether the path <code>p</code> has the extension <code>ext</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a), (Ref String b)] Bool)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(is-extension? p ext)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>checks whether the path <code>p</code> has the extension <code>ext</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#join">
|
|
||||||
<h3 id="join">
|
|
||||||
join
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [(Ref (Array String))] String)
|
<a class="anchor" href="#join">
|
||||||
</p>
|
<h3 id="join">
|
||||||
<pre class="args">
|
join
|
||||||
(join ps)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>joins the path components <code>ps</code> into a path.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref (Array String) a)] String)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(join ps)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>joins the path components <code>ps</code> into a path.</p>
|
||||||
<p>As such, it is the inverse to <a href="#split">split</a>.</p>
|
<p>As such, it is the inverse to <a href="#split">split</a>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#path-max">
|
|
||||||
<h3 id="path-max">
|
|
||||||
path-max
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
external
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
Int
|
<a class="anchor" href="#path-max">
|
||||||
</p>
|
<h3 id="path-max">
|
||||||
<span>
|
path-max
|
||||||
|
</h3>
|
||||||
</span>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>defines the maximum path length on this OS.</p>
|
external
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
Int
|
||||||
|
</p>
|
||||||
|
<span>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
<p class="doc">
|
||||||
|
<p>defines the maximum path length on this OS.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#relative?">
|
|
||||||
<h3 id="relative?">
|
|
||||||
relative?
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] Bool)
|
<a class="anchor" href="#relative?">
|
||||||
</p>
|
<h3 id="relative?">
|
||||||
<pre class="args">
|
relative?
|
||||||
(relative? p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>checks whether a path is relative.</p>
|
defn
|
||||||
<p>As such, it is the inverse to <a href="#absolute">absolute</a>.</p>
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] Bool)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(relative? p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>checks whether a path is relative.</p>
|
||||||
|
<p>As such, it is the inverse to <a href="#absolute?">absolute?</a>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#replace-extension">
|
|
||||||
<h3 id="replace-extension">
|
|
||||||
replace-extension
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String, &String] String)
|
<a class="anchor" href="#replace-extension">
|
||||||
</p>
|
<h3 id="replace-extension">
|
||||||
<pre class="args">
|
replace-extension
|
||||||
(replace-extension p ext)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>replaces the extension of a path <code>p</code> with <code>ext</code>. Adds
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a), (Ref String b)] String)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(replace-extension p ext)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>replaces the extension of a path <code>p</code> with <code>ext</code>. Adds
|
||||||
an extension if there previously was none.</p>
|
an extension if there previously was none.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#search-path-separator">
|
|
||||||
<h3 id="search-path-separator">
|
|
||||||
search-path-separator
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
def
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
Char
|
<a class="anchor" href="#search-path-separator">
|
||||||
</p>
|
<h3 id="search-path-separator">
|
||||||
<span>
|
search-path-separator
|
||||||
|
</h3>
|
||||||
</span>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>is the separator for the <code>PATH</code> environment
|
def
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
Char
|
||||||
|
</p>
|
||||||
|
<span>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
<p class="doc">
|
||||||
|
<p>is the separator for the <code>PATH</code> environment
|
||||||
variable we use on this OS.</p>
|
variable we use on this OS.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#search-path-separator?">
|
|
||||||
<h3 id="search-path-separator?">
|
|
||||||
search-path-separator?
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [Char] Bool)
|
<a class="anchor" href="#search-path-separator?">
|
||||||
</p>
|
<h3 id="search-path-separator?">
|
||||||
<pre class="args">
|
search-path-separator?
|
||||||
(search-path-separator? c)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
|
defn
|
||||||
</p>
|
</div>
|
||||||
</div>
|
<p class="sig">
|
||||||
<div class="binder">
|
(Fn [Char] Bool)
|
||||||
<a class="anchor" href="#separator">
|
</p>
|
||||||
<h3 id="separator">
|
<pre class="args">
|
||||||
separator
|
(search-path-separator? c)
|
||||||
</h3>
|
</pre>
|
||||||
</a>
|
<p class="doc">
|
||||||
<div class="description">
|
|
||||||
def
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
Char
|
<a class="anchor" href="#separator">
|
||||||
</p>
|
<h3 id="separator">
|
||||||
<span>
|
separator
|
||||||
|
</h3>
|
||||||
</span>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>is the default separator we use on this OS.</p>
|
def
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
Char
|
||||||
|
</p>
|
||||||
|
<span>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
<p class="doc">
|
||||||
|
<p>is the default separator we use on this OS.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#separator?">
|
|
||||||
<h3 id="separator?">
|
|
||||||
separator?
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&Char] Bool)
|
<a class="anchor" href="#separator?">
|
||||||
</p>
|
<h3 id="separator?">
|
||||||
<pre class="args">
|
separator?
|
||||||
(separator? c)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>checks whether the character <code>c</code> is a separator for the
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref Char StaticLifetime)] Bool)
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(separator? c)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>checks whether the character <code>c</code> is a separator for the
|
||||||
<code>PATH</code> environment variable on this OS.</p>
|
<code>PATH</code> environment variable on this OS.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#separators">
|
|
||||||
<h3 id="separators">
|
|
||||||
separators
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
def
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(Array Char)
|
<a class="anchor" href="#separators">
|
||||||
</p>
|
<h3 id="separators">
|
||||||
<span>
|
separators
|
||||||
|
</h3>
|
||||||
</span>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>is the possible separators we could use on this OS.</p>
|
def
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Array Char)
|
||||||
|
</p>
|
||||||
|
<span>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
<p class="doc">
|
||||||
|
<p>is the possible separators we could use on this OS.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#split">
|
|
||||||
<h3 id="split">
|
|
||||||
split
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Array String))
|
<a class="anchor" href="#split">
|
||||||
</p>
|
<h3 id="split">
|
||||||
<pre class="args">
|
split
|
||||||
(split p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>splits the path <code>p</code> into its components.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Array String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(split p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>splits the path <code>p</code> into its components.</p>
|
||||||
<p>As such, it is the inverse to <a href="#join">join</a>.</p>
|
<p>As such, it is the inverse to <a href="#join">join</a>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#split-extension">
|
|
||||||
<h3 id="split-extension">
|
|
||||||
split-extension
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Maybe (Pair String String)))
|
<a class="anchor" href="#split-extension">
|
||||||
</p>
|
<h3 id="split-extension">
|
||||||
<pre class="args">
|
split-extension
|
||||||
(split-extension p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>splits the path <code>p</code> on its extension.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Maybe (Pair String String)))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(split-extension p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>splits the path <code>p</code> on its extension.</p>
|
||||||
<p>It will return a <code>(Maybe (Pair String String))</code>. <code>Maybe</code> because there might not
|
<p>It will return a <code>(Maybe (Pair String String))</code>. <code>Maybe</code> because there might not
|
||||||
be an extension, and <code>Pair</code> because it will return the part before and after
|
be an extension, and <code>Pair</code> because it will return the part before and after
|
||||||
the extension.</p>
|
the extension.</p>
|
||||||
@@ -524,27 +525,28 @@ the extension.</p>
|
|||||||
; => (Maybe.Just (Pair "file/path.txt.bob" "fred"))
|
; => (Maybe.Just (Pair "file/path.txt.bob" "fred"))
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#split-search-path">
|
|
||||||
<h3 id="split-search-path">
|
|
||||||
split-search-path
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Array String))
|
<a class="anchor" href="#split-search-path">
|
||||||
</p>
|
<h3 id="split-search-path">
|
||||||
<pre class="args">
|
split-search-path
|
||||||
(split-search-path p)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>splits a <code>PATH</code> environment variable <code>p</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Array String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(split-search-path p)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>splits a <code>PATH</code> environment variable <code>p</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
15
gendocs.carp
15
gendocs.carp
@@ -1,13 +1,10 @@
|
|||||||
(load "path.carp")
|
(load "path.carp")
|
||||||
|
|
||||||
(defndynamic gendocs []
|
(Project.config "title" "path")
|
||||||
(do
|
(Project.config "docs-directory" "./docs/")
|
||||||
(Project.config "title" "path")
|
(Project.config "docs-logo" "")
|
||||||
(Project.config "docs-directory" "./docs/")
|
(Project.config "docs-styling" "style.css")
|
||||||
(Project.config "docs-logo" "")
|
(Project.config "docs-generate-index" false)
|
||||||
(Project.config "docs-styling" "style.css")
|
(save-docs Path)
|
||||||
(Project.config "docs-generate-index" false)
|
|
||||||
(save-docs Path)))
|
|
||||||
|
|
||||||
(gendocs)
|
|
||||||
(quit)
|
(quit)
|
||||||
|
20
path.carp
20
path.carp
@@ -3,7 +3,7 @@
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load \"https://veitheller.de/git/carpentry/path@0.0.1\")
|
(load \"git@git.veitheller.de:carpentry/path.git@0.0.4\")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
@@ -16,7 +16,7 @@ It assumes either Windows or POSIX-style separators.")
|
|||||||
(defmodule Path
|
(defmodule Path
|
||||||
(doc absolute? "checks whether a path is absolute.
|
(doc absolute? "checks whether a path is absolute.
|
||||||
|
|
||||||
As such, it is the inverse to [relative](#relative).")
|
As such, it is the inverse to [relative?](#relative?).")
|
||||||
(doc separator "is the default separator we use on this OS.")
|
(doc separator "is the default separator we use on this OS.")
|
||||||
(doc separators "is the possible separators we could use on this OS.")
|
(doc separators "is the possible separators we could use on this OS.")
|
||||||
(doc search-path-separator "is the separator for the `PATH` environment
|
(doc search-path-separator "is the separator for the `PATH` environment
|
||||||
@@ -32,7 +32,7 @@ variable we use on this OS.")
|
|||||||
(def search-path-separator \;)
|
(def search-path-separator \;)
|
||||||
(def extension-pat #"\.[^\\/\.]*$")
|
(def extension-pat #"\.[^\\/\.]*$")
|
||||||
(def sep-string "\\"))
|
(def sep-string "\\"))
|
||||||
(not-on-windows
|
(posix-only
|
||||||
(defn absolute? [p] (String.starts-with? p "/"))
|
(defn absolute? [p] (String.starts-with? p "/"))
|
||||||
(def separator \/)
|
(def separator \/)
|
||||||
(def separators [\/])
|
(def separators [\/])
|
||||||
@@ -42,7 +42,7 @@ variable we use on this OS.")
|
|||||||
|
|
||||||
(doc relative? "checks whether a path is relative.
|
(doc relative? "checks whether a path is relative.
|
||||||
|
|
||||||
As such, it is the inverse to [absolute](#absolute).")
|
As such, it is the inverse to [absolute?](#absolute?).")
|
||||||
(defn relative? [p] (not (absolute? p)))
|
(defn relative? [p] (not (absolute? p)))
|
||||||
|
|
||||||
(doc separator? "checks whether the character `c` is a path separator on this
|
(doc separator? "checks whether the character `c` is a path separator on this
|
||||||
@@ -85,7 +85,7 @@ It will return `Nothing` if an empty string is passed.")
|
|||||||
(doc basename "gets the basename of the path `p`.")
|
(doc basename "gets the basename of the path `p`.")
|
||||||
(defn basename [p]
|
(defn basename [p]
|
||||||
(let [split (split p)
|
(let [split (split p)
|
||||||
but-last (Array.prefix-array &split (dec (Array.length &split)))]
|
but-last (Array.prefix &split (dec (Array.length &split)))]
|
||||||
(String.join sep-string &but-last)))
|
(String.join sep-string &but-last)))
|
||||||
|
|
||||||
(doc split-extension "splits the path `p` on its extension.
|
(doc split-extension "splits the path `p` on its extension.
|
||||||
@@ -113,7 +113,7 @@ Examples on POSIX:
|
|||||||
(let [i (Pattern.find extension-pat p)]
|
(let [i (Pattern.find extension-pat p)]
|
||||||
(if (= -1 i)
|
(if (= -1 i)
|
||||||
(Maybe.Nothing)
|
(Maybe.Nothing)
|
||||||
(Maybe.Just (Pair.init (prefix-string p i) (suffix-string p (inc i)))))))
|
(Maybe.Just (Pair.init (prefix p i) (suffix p (inc i)))))))
|
||||||
|
|
||||||
(doc extension "gets the extension of a file as a `Maybe`.")
|
(doc extension "gets the extension of a file as a `Maybe`.")
|
||||||
(defn extension [p]
|
(defn extension [p]
|
||||||
@@ -127,9 +127,9 @@ Examples on POSIX:
|
|||||||
(doc drop-extension "drops the extension of a path `p`. Does nothing if there
|
(doc drop-extension "drops the extension of a path `p`. Does nothing if there
|
||||||
is none.")
|
is none.")
|
||||||
(defn drop-extension [p]
|
(defn drop-extension [p]
|
||||||
@(match (split-extension p)
|
(match (split-extension p)
|
||||||
(Maybe.Nothing) p
|
(Maybe.Nothing) @p
|
||||||
(Maybe.Just pair) (Pair.a &pair)))
|
(Maybe.Just pair) @(Pair.a &pair)))
|
||||||
|
|
||||||
(doc add-extension "adds an extension `ext` to a path `p`.")
|
(doc add-extension "adds an extension `ext` to a path `p`.")
|
||||||
(defn add-extension [p ext] (String.concat &[@p @"." @ext]))
|
(defn add-extension [p ext] (String.concat &[@p @"." @ext]))
|
||||||
@@ -148,5 +148,5 @@ an extension if there previously was none.")
|
|||||||
(defn split-search-path [p] (String.split-by p &[search-path-separator]))
|
(defn split-search-path [p] (String.split-by p &[search-path-separator]))
|
||||||
(doc get-search-path "gets the `PATH` environment variable and splits it.")
|
(doc get-search-path "gets the `PATH` environment variable and splits it.")
|
||||||
(defn get-search-path []
|
(defn get-search-path []
|
||||||
(Maybe.apply (IO.getenv @"PATH") &(fn [p] (split-search-path &p))))
|
(Maybe.apply (IO.getenv "PATH") &(fn [p] (split-search-path &p))))
|
||||||
)
|
)
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
(use-all Path Test)
|
(use-all Path Test)
|
||||||
|
|
||||||
(if (not (Dynamic.or (= "windows" (os)) (= "mingw32" (os))))
|
(posix-only
|
||||||
(deftest test
|
(deftest test
|
||||||
(assert-equal test
|
(assert-equal test
|
||||||
"path/joined"
|
"path/joined"
|
||||||
@@ -41,11 +41,11 @@
|
|||||||
"cwd works"
|
"cwd works"
|
||||||
)
|
)
|
||||||
; TODO why does this test not work?
|
; TODO why does this test not work?
|
||||||
;(assert-equal test
|
(assert-equal test
|
||||||
; "file"
|
"file"
|
||||||
; &(drop-extension "file.txt")
|
&(drop-extension "file.txt")
|
||||||
; "drop-extension works if there is an extension"
|
"drop-extension works if there is an extension"
|
||||||
;)
|
)
|
||||||
(assert-equal test
|
(assert-equal test
|
||||||
"file"
|
"file"
|
||||||
&(drop-extension "file")
|
&(drop-extension "file")
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
())
|
())
|
||||||
(if (Dynamic.or (= "windows" (os)) (= "mingw32" (os)))
|
(windows-only
|
||||||
(deftest test
|
(deftest test
|
||||||
(assert-true test
|
(assert-true test
|
||||||
false
|
false
|
||||||
|
Reference in New Issue
Block a user