Skip to content

Commit

Permalink
Tuesday 2024-11-26 23:03:58
Browse files Browse the repository at this point in the history
  • Loading branch information
jackokring committed Nov 26, 2024
1 parent 98e377a commit ccddadb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
4 changes: 2 additions & 2 deletions extras-backup/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"nvim-dap-virtual-text": { "branch": "master", "commit": "76d80c3d171224315b61c006502a1e30c213a9ab" },
"nvim-jdtls": { "branch": "master", "commit": "ece818f909c6414cbad4e1fb240d87e003e10fda" },
"nvim-lint": { "branch": "master", "commit": "6b46370d02cd001509a765591a3ffc481b538794" },
"nvim-lspconfig": { "branch": "master", "commit": "16008a64f6ab9309641f30b8a7c9a432f1649b9a" },
"nvim-lspconfig": { "branch": "master", "commit": "830ec3893eeb2b21d182864b56931ca6d23d3e29" },
"nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
"nvim-snippets": { "branch": "main", "commit": "56b4052f71220144689caaa2e5b66222ba5661eb" },
"nvim-treesitter": { "branch": "master", "commit": "28591731d84c2fc18ddda60e1d53da24c31c4987" },
Expand All @@ -67,7 +67,7 @@
"telescope.nvim": { "branch": "master", "commit": "85922dde3767e01d42a08e750a773effbffaea3e" },
"todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" },
"tokyonight.nvim": { "branch": "main", "commit": "c2725eb6d086c8c9624456d734bd365194660017" },
"trouble.nvim": { "branch": "main", "commit": "b4b9355ccb2aa02043d830c37ceba71b3cdf375f" },
"trouble.nvim": { "branch": "main", "commit": "c633e8559adf529b85167a4cb489d7358e9efb1a" },
"ts-comments.nvim": { "branch": "main", "commit": "2002692ad1d3f6518d016550c20c2a890f0cbf0e" },
"venv-selector.nvim": { "branch": "regexp", "commit": "e82594274bf7b54387f9a2abe65f74909ac66e97" },
"vim-dadbod": { "branch": "master", "commit": "fe5a55e92b2dded7c404006147ef97fb073d8b1b" },
Expand Down
47 changes: 33 additions & 14 deletions lua/doris/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,16 @@ local nf = function(x, width, base)
width = width or 0
return sf("%" .. sf("%d", width) .. base, x)
end
---decimal string of number
---decimal string of number with default C numeric locale
---@param x integer
---@param width integer
---@return string
_G.dec = function(x, width)
return nf(x, width, "d")
local l = os.setlocale()
os.setlocale("C", "numeric")
local s = nf(x, width, "d")
os.setlocale(l, "numeric")
return s
end
---hex string of number
---@param x integer
Expand All @@ -601,14 +605,18 @@ end
_G.hex = function(x, width)
return nf(x, width, "x")
end
---scientific string of number
---scientific string of number with default C numeric locale
---@param x integer
---@param width integer
---@param prec integer
---@return string
_G.sci = function(x, width, prec)
local l = os.setlocale()
os.setlocale("C", "numeric")
-- default size 8 = 6 + #"x."
return nf(x, width, "." .. sf("%d", prec or 6) .. "G")
local s = nf(x, width, "." .. sf("%d", prec or 6) .. "G")
os.setlocale(l, "numeric")
return s
end

_G.upper = string.upper
Expand All @@ -617,29 +625,40 @@ _G.rep = string.rep
_G.reverse = string.reverse
_G.sort = table.sort

---to string with default C numeric locale
---@param number any
---@return string
_G.str = function(number)
---number to string with default C numeric locale
---nil return if can't convert to number
---@param num any
---@return string?
_G.str = function(num)
if type(num) ~= "number" then
return nil
end
local l = os.setlocale()
os.setlocale("C", "numeric")
local s = tostring(number)
local s = tostring(num)
os.setlocale(l, "numeric")
return s
end

---to number with default C numeric locale
---string to number with default C numeric locale
---nil return if not a number
---@param str string
---@param base? integer
---@return number
_G.val = function(str, base)
---@return number?
_G.val = function(str)
local l = os.setlocale()
os.setlocale("C", "numeric")
local s = tonumber(str, base or 10) or 0
local s = tonumber(str)
os.setlocale(l, "numeric")
return s
end

---to number from hex integer value only
---@param str string
---@return integer?
_G.val_hex = function(str)
return tonumber(str, 16)
end

---quote a string escaped (includes beginning and end "\"" literal)
---@param str any
---@return string
Expand Down

0 comments on commit ccddadb

Please sign in to comment.