Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/paths.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoumith Chintala <soumith@gmail.com>2015-05-22 20:09:14 +0300
committerSoumith Chintala <soumith@gmail.com>2015-05-22 20:09:14 +0300
commit851f31425ca3ec878cbaf516b8e3dad55164d80d (patch)
tree42cdbdbfdc918d774c11bd03e409df368dd49fd5
parent328d5c17c44b4c7cb0623103c926dbae215745e4 (diff)
parenteec27d0dcaab9444b874ce25ea7e3e551290b730 (diff)
Merge pull request #7 from zakattacktwitter/master
Adding extname to complement basename.
-rw-r--r--README.md5
-rw-r--r--paths.c18
2 files changed, 23 insertions, 0 deletions
diff --git a/README.md b/README.md
index 7c9d606..6b22d18 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,11 @@ This is similar to the well know shell command `"basename"`.
Return the name of directory containing file `path`.
This is similar to the well known shell command `"dirname"`.
+<a name="paths.extname"/>
+### paths.extname(path) ###
+
+Return the extension of the `path` or nil if none is found.
+
<a name="paths.concat"/>
### paths.concat([path1,....,pathn]) ###
diff --git a/paths.c b/paths.c
index 910f76a..ee6a86b 100644
--- a/paths.c
+++ b/paths.c
@@ -339,6 +339,23 @@ lua_dirname(lua_State *L)
}
+static int
+lua_extname(lua_State *L)
+{
+ const char *fname = luaL_checkstring(L, 1);
+ const char *p;
+
+ p = fname + strlen(fname) - 1;
+ while (p >= fname) {
+ if (*p == '.') {
+ lua_pushstring(L, p + 1);
+ return 1;
+ }
+ p--;
+ }
+ return 0;
+}
+
/* ------------------------------------------------------ */
/* cwd and concat */
@@ -1095,6 +1112,7 @@ static const struct luaL_Reg paths__ [] = {
{"dirp", lua_dirp},
{"basename", lua_basename},
{"dirname", lua_dirname},
+ {"extname", lua_extname},
{"cwd", lua_cwd},
{"concat", lua_concatfname},
{"execdir", lua_execdir},