From 2a54b101bdf102f64794a6ab8533f1cc71a06e1a Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Tue, 29 Jun 2021 07:14:21 +0000 Subject: [PATCH 1/3] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index 98801f3dc..af53a985c 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 98801f3dc979cf6a3277dde0b6617bfe5ac5e017 +Subproject commit af53a985c54b29a5b3092127a5e8ec3495ef0cee From eafa6e86f7f4a5b3fa11b137d6926202a010771b Mon Sep 17 00:00:00 2001 From: myk002 Date: Tue, 29 Jun 2021 12:22:05 -0700 Subject: [PATCH 2/3] add utils.normalizePath() --- library/lua/utils.lua | 7 +++++++ test/library/utils.lua | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/library/lua/utils.lua b/library/lua/utils.lua index b0bc70af4..39a6c156e 100644 --- a/library/lua/utils.lua +++ b/library/lua/utils.lua @@ -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 diff --git a/test/library/utils.lua b/test/library/utils.lua index b2c63dafd..6232bd9a2 100644 --- a/test/library/utils.lua +++ b/test/library/utils.lua @@ -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} From a6a970463118d4e6a8e7a39d2c57edf31105c504 Mon Sep 17 00:00:00 2001 From: myk002 Date: Tue, 29 Jun 2021 12:25:21 -0700 Subject: [PATCH 3/3] update changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index f91284001..219cf8d18 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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