Merge pull request #2469 from psychon/remove_dead_code

menubar.utils: Remove some (basically) dead code
This commit is contained in:
mergify[bot] 2018-11-07 20:39:49 +00:00 committed by GitHub
commit 6cdd737c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 98 deletions

View file

@ -41,16 +41,6 @@ local default_icon = nil
--- Name of the WM for the OnlyShowIn entry in the .desktop file. --- Name of the WM for the OnlyShowIn entry in the .desktop file.
utils.wm_name = "awesome" utils.wm_name = "awesome"
--- Possible escape characters (not including the preceding backslash) in
--.desktop files and their equates.
local escape_sequences = {
[ [[\\]] ] = [[\]],
[ [[\n]] ] = '\n',
[ [[\r]] ] = '\r',
[ [[\s]] ] = ' ',
[ [[\t]] ] = '\t',
}
-- Maps keys in desktop entries to suitable getter function. -- Maps keys in desktop entries to suitable getter function.
-- The order of entries is as in the spec. -- The order of entries is as in the spec.
-- https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html -- https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html
@ -228,49 +218,6 @@ function utils.rtrim(s)
return s return s
end end
--- Unescape strings read from desktop files.
-- Possible sequences are \n, \r, \s, \t, \\, which have the usual meanings.
-- @tparam string s String to unescape
-- @treturn string The unescaped string
function utils.unescape(s)
if not s then return end
-- Ignore the second return value of string.gsub() (number replaced)
s = string.gsub(s, "\\.", function(sequence)
return escape_sequences[sequence] or sequence
end)
return s
end
--- Separate semi-colon separated lists.
-- Semi-colons in lists are escaped as '\;'.
-- @tparam string s String to parse
-- @treturn table A table containing the separated strings. Each element is
-- unescaped by utils.unescape().
function utils.parse_list(s)
if not s then return end
-- Append terminating semi-colon if not already there.
if string.sub(s, -1) ~= ';' then
s = s .. ';'
end
local segments = {}
local part = ""
-- Iterate over sub-strings between semicolons
for word, backslashes in string.gmatch(s, "([^;]-(\\*));") do
if #backslashes % 2 ~= 0 then
-- The semicolon was escaped, remember this part for later
part = part .. word:sub(1, -2) .. ";"
else
table.insert(segments, utils.unescape(part .. word))
part = ""
end
end
return segments
end
--- Lookup an icon in different folders of the filesystem. --- Lookup an icon in different folders of the filesystem.
-- @tparam string icon_file Short or full name of the icon. -- @tparam string icon_file Short or full name of the icon.
-- @treturn string|boolean Full name of the icon, or false on failure. -- @treturn string|boolean Full name of the icon, or false on failure.

View file

@ -7,51 +7,6 @@ local utils = require("menubar.utils")
local theme = require("beautiful") local theme = require("beautiful")
local glib = require("lgi").GLib local glib = require("lgi").GLib
describe("menubar.utils unescape", function()
local single_strings = {
[ [[\n:\r:\s:\t:\\]] ] = "\n:\r: :\t:\\",
-- Make sure escapes are not read recursively
[ [[\\s]] ] = [[\s]],
-- Make sure ';' is not escaped for non-list strings and other
-- characters are not escaped
[ [[ab\c\;1\23]] ] = [[ab\c\;1\23]],
}
for escaped, unescaped in pairs(single_strings) do
it(escaped, function()
assert.is.equal(unescaped, utils.unescape(escaped))
end)
end
local list_strings = {
-- Normal list
[ [[abc;123;xyz]] ] = { "abc", "123", "xyz" },
-- Optional terminating semicolon
[ [[abc;123;xyz;]] ] = { "abc", "123", "xyz" },
-- Blank item
[ [[abc;;123]] ] = { "abc", "", "123" },
-- Trailing whitespace
[ [[abc;123; ]] ] = { "abc", "123", " " },
-- Escape semicolon
[ [[abc\;;12\;3;\;xyz]] ] = { "abc;", "12;3", ";xyz" },
-- Normal escapes are parsed like normal
[ [[ab\c;1\s23;x\\yz]] ] = { "ab\\c", "1 23", "x\\yz" },
-- Escaped backslashes before semicolon
[ [[abc\\\;;12\\;3;xyz]] ] = { "abc\\;", "12\\", "3", "xyz" },
}
for escaped, unescaped in pairs(list_strings) do
it(escaped, function()
local returned = utils.parse_list(escaped)
assert.is.equal(#unescaped, #returned)
for i = 1, #unescaped do
assert.is.equal(unescaped[i], returned[i])
end
end)
end
end)
describe("menubar.utils lookup_icon_uncached", function() describe("menubar.utils lookup_icon_uncached", function()
local shimmed = {} local shimmed = {}
local icon_theme local icon_theme