Compare commits

...

1 Commits

Author SHA1 Message Date
perro tuerto d8e6f97cb6 Autoformat 2023-07-01 10:05:59 -07:00
1 changed files with 24 additions and 54 deletions

View File

@ -17,7 +17,7 @@ function dog.import()
local lib = _G[libkey]
if type(dogfns) == "table" then
for fnkey, fn in pairs(dogfns) do
if not(lib[fnkey]) then
if not lib[fnkey] then
lib[fnkey] = fn
else
local name = libkey .. "." .. fnkey .. "()"
@ -33,7 +33,7 @@ end
-- @param ... string: Chunks for popen
-- @return boolean, string: Status and output of popen
function dog.io.try(...)
local cmd = table.concat({...}, " ") .. " 2>&1"
local cmd = table.concat({ ... }, " ") .. " 2>&1"
local handle = io.popen(cmd)
local output = handle:read("*a")
local status = (handle:close() ~= nil and true or false)
@ -59,37 +59,27 @@ end
-- Checks if OS is windows
-- @return boolean: Windows or not
function dog.os.iswin()
return dog.os.uname() == "windows"
end
function dog.os.iswin() return dog.os.uname() == "windows" end
-- Checks if OS is Unix
-- @return boolean: Unix or not
function dog.os.isunix()
return dog.os.uname() ~= "windows"
end
function dog.os.isunix() return dog.os.uname() ~= "windows" end
-- Gets OS language
-- @return string, string, string: Language, locale and encoding
function dog.os.lang()
local lang = os.getenv("LANG")
if lang ~= nil then
return lang:match("(%w%w)_?(%w?%w?)%.?(.*)")
end
if lang ~= nil then return lang:match("(%w%w)_?(%w?%w?)%.?(.*)") end
return "en", "US", "UTF-8"
end
-- Checks if string is empty
-- @return boolean: Empty or not
function dog.string.isempty(str)
return str == ''
end
function dog.string.isempty(str) return str == "" end
-- Changes newlines so everything is in one line
-- @return string: String with formatted newlines as literal "\n"
function dog.string.linearize(str)
return str:gsub("\n", "\\n")
end
function dog.string.linearize(str) return str:gsub("\n", "\\n") end
-- Normalizes string
-- @return string: Normalized string
@ -130,15 +120,11 @@ end
-- Removes spaces at the beginning of the string
-- @return string: Left stripped string
function dog.string.lstrip(str)
return str:gsub("^%s+", "")
end
function dog.string.lstrip(str) return str:gsub("^%s+", "") end
-- Removes spaces at the end of the string
-- @return string: Right stripped string
function dog.string.rstrip(str)
return str:gsub("%s+$", "")
end
function dog.string.rstrip(str) return str:gsub("%s+$", "") end
-- Removes spaces at the beginning and at the end of the string
-- @return string: Stripped string
@ -148,25 +134,19 @@ function dog.string.strip(str)
end
-- Alias of strip
function dog.string.trim(str)
return dog.string.strip(str)
end
function dog.string.trim(str) return dog.string.strip(str) end
-- The following are heavily influenced by Python pathlib
-- Check: https://docs.python.org/3/library/pathlib.html
-- Checks if string is a file or a directory
-- @return boolean: Exists or not
function dog.string.exists(str)
return os.rename(str, str) ~= nil
end
function dog.string.exists(str) return os.rename(str, str) ~= nil end
-- Checks if string is a file
-- @return boolean: File or not
function dog.string.isfile(str)
if dog.string.exists(str) then
return io.open(str, "a+") ~= nil
end
if dog.string.exists(str) then return io.open(str, "a+") ~= nil end
return false
end
@ -184,9 +164,7 @@ end
-- Reads file content as string
-- @return string or nil: File as string or nil
function dog.string.readtext(str)
if dog.string.exists(str) then
return io.open(str):read("*a")
end
if dog.string.exists(str) then return io.open(str):read("*a") end
end
-- Read file content as lines
@ -203,9 +181,7 @@ end
-- Gets file without suffix
-- @return string: File wihtout suffix
function dog.string.stem(str)
return str:gsub("%.%a+$", "")
end
function dog.string.stem(str) return str:gsub("%.%a+$", "") end
-- Gets file extensions
-- @return table: List of file extensions
@ -221,9 +197,7 @@ end
-- @return string: Final file extension
function dog.string.suffix(str)
local suffixes = str:suffixes()
if suffixes[#suffixes] then
return suffixes[#suffixes]
end
if suffixes[#suffixes] then return suffixes[#suffixes] end
return ""
end
@ -232,12 +206,12 @@ end
-- @return table: ASCII-Unicode table equivalency
function dog.utf8.table()
return {
["a"] = {"á", "à", "ä"},
["e"] = {"é", "è", "ë"},
["i"] = {"í", "ì", "ï"},
["o"] = {"ó", "ò", "ö"},
["u"] = {"ú", "ù", "ü"},
["n"] = {"ñ"},
["a"] = { "á", "à", "ä" },
["e"] = { "é", "è", "ë" },
["i"] = { "í", "ì", "ï" },
["o"] = { "ó", "ò", "ö" },
["u"] = { "ú", "ù", "ü" },
["n"] = { "ñ" },
}
end
@ -245,7 +219,6 @@ end
-- Check: https://pandoc.org/lua-filters.html#module-pandoc
if pandoc ~= nil then
-- Gets file extension namespace
-- Check: https://pandoc.org/MANUAL.html#general-options
-- If suffix is 'md' or empty, the default is markdown.
@ -283,7 +256,7 @@ if pandoc ~= nil then
-- @param content pandoc.MetaValue: Pandoc content value
-- @return string: Pandoc stringified value
function pandoc.utils.rawstringify(content)
return pandoc.utils.stringify(content:walk {
return pandoc.utils.stringify(content:walk({
Plain = function(plain)
table.insert(plain.content, pandoc.Space())
return plain
@ -295,11 +268,9 @@ if pandoc ~= nil then
RawInline = function(rawinline)
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
end,
SoftBreak = function(_)
return pandoc.Str("\n")
end,
SoftBreak = function(_) return pandoc.Str("\n") end,
Inline = function(inline) return pandoc.utils.stringify(inline) end,
})
}))
end
-- Converts pandoc.Meta to table
@ -325,7 +296,6 @@ if pandoc ~= nil then
end
return newmeta
end
end
return dog