diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-01-11 15:37:12 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-11 15:37:12 +0100 |
| commit | bae8a0a45393518bbf7914b10bf36139a977cda6 (patch) | |
| tree | 6974858d868afc1d65dae8d19afc53213fe0ef99 /util.lua | |
| parent | 29afc301ea05bc907444b698c91b141c26167baa (diff) | |
| download | vis-lspc-bae8a0a45393518bbf7914b10bf36139a977cda6.tar.gz vis-lspc-bae8a0a45393518bbf7914b10bf36139a977cda6.zip | |
handle special cases in util.dirnamedetect-root
Diffstat (limited to 'util.lua')
| -rw-r--r-- | util.lua | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -127,7 +127,27 @@ end -- @param the pathname -- @return the pathname up to the last '/' function util.dirname(name) - return name:match('(.*[/])') + if name == '.' or name == '..' or name == '/' then + return name + end + + -- strip a trailing path separator + if name:sub(#name, #name) == '/' then + name = name:sub(1, #name - 1) + end + + local dirname = name:match('(.*)[/]') + -- There was no path separator in name. + if not dirname then + return '.' + end + + -- The name started with the root dir. + if dirname == '' then + return '/' + end + + return dirname end --- Create an iterator yielding the nth line of a file |
