Merge remote-tracking branch 'myk002/myk_normalize_path' into develop

develop
lethosor 2021-06-30 00:16:08 -04:00
commit 8f6b99f8d1
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
4 changed files with 23 additions and 1 deletions

@ -55,6 +55,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``gui.Painter``: fixed error when calling ``viewport()`` method
- ``gui.dwarfmode``: new function: ``enterSidebarMode(sidebar_mode, max_esc)`` which uses keypresses to get into the specified sidebar mode from whatever the current screen is
- `reveal`: now exposes ``unhideFlood(pos)`` functionality to Lua
- new utility function: ``utils.normalizePath()``: normalizes directory slashes across platoforms to ``/`` and coaleses adjacent directory separators
- ``utils.processArgsGetopt()``: now returns negative numbers (e.g. ``-10``) in the list of positional parameters instead of treating it as an option string equivalent to ``-1 -0``
- ``utils.processArgsGetopt()``: now properly handles ``--`` like GNU ``getopt`` as a marker to treat all further parameters as non-options
- ``utils.processArgsGetopt()``: now detects when required arguments to long-form options are missing

@ -544,6 +544,13 @@ function check_number(text)
return nv ~= nil, nv
end
-- Normalize directory separator slashes across platforms to '/' and collapse
-- adjacent slashes into a single slash.
local platformSlash = package.config:sub(1,1)
function normalizePath(path)
return path:gsub(platformSlash, '/'):gsub('/+', '/')
end
function invert(tab)
local result = {}
for k,v in pairs(tab) do

@ -1 +1 @@
Subproject commit 98801f3dc979cf6a3277dde0b6617bfe5ac5e017
Subproject commit af53a985c54b29a5b3092127a5e8ec3495ef0cee

@ -14,6 +14,20 @@ function test.OrderedTable()
end
end
function test.normalizePath()
expect.eq('imapath/file.csv', utils.normalizePath('imapath/file.csv'))
expect.eq('/ima/path', utils.normalizePath('/ima/path'))
expect.eq('ima/path', utils.normalizePath('ima//path'))
expect.eq('imapath', utils.normalizePath('imapath'))
expect.eq('/imapath', utils.normalizePath('/imapath'))
expect.eq('/imapath', utils.normalizePath('//imapath'))
expect.eq('/imapath', utils.normalizePath('///imapath'))
expect.eq('imapath/', utils.normalizePath('imapath/'))
expect.eq('imapath/', utils.normalizePath('imapath//'))
end
function test.invert()
local t = {}
local i = utils.invert{'a', 4.4, false, true, 5, t}