mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-28 23:01:26 +00:00
Merge pull request #1837 from seltonmt012/fix/esx-lib-helpers
fix(esx_lib): correct the shared table and string helpers
This commit is contained in:
@@ -47,7 +47,7 @@ end
|
|||||||
function xLib.string.toPascal(s)
|
function xLib.string.toPascal(s)
|
||||||
xLib.verify(s, 'string', true)
|
xLib.verify(s, 'string', true)
|
||||||
|
|
||||||
local res = s:gsub("(%a)([%w_]*)", function(first, rest)
|
local res = s:gsub("(%a)([%w]*)", function(first, rest)
|
||||||
return first:upper() .. rest:lower()
|
return first:upper() .. rest:lower()
|
||||||
end):gsub("_", "")
|
end):gsub("_", "")
|
||||||
|
|
||||||
@@ -114,6 +114,10 @@ end
|
|||||||
function xLib.string.replace(s, old, new)
|
function xLib.string.replace(s, old, new)
|
||||||
xLib.verify(s, 'string', true)
|
xLib.verify(s, 'string', true)
|
||||||
|
|
||||||
|
if type(new) == "string" then
|
||||||
|
new = new:gsub("%%", "%%%%")
|
||||||
|
end
|
||||||
|
|
||||||
local result = s:gsub(xLib.string.escapePattern(old), new)
|
local result = s:gsub(xLib.string.escapePattern(old), new)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -14,13 +14,9 @@ function xLib.table.isArray(tbl)
|
|||||||
end
|
end
|
||||||
|
|
||||||
count, maxIndex = count + 1, math.max(maxIndex, k)
|
count, maxIndex = count + 1, math.max(maxIndex, k)
|
||||||
|
|
||||||
if count > maxIndex then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return count == maxIndex
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param tbl table
|
---@param tbl table
|
||||||
@@ -38,13 +34,6 @@ function xLib.table.searchForKey(tbl, item)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param tbl table
|
|
||||||
---@param item any
|
|
||||||
---@return boolean
|
|
||||||
function xLib.table.contains(tbl, item)
|
|
||||||
return xLib.table.searchForKey(tbl, item) ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param tbl table
|
---@param tbl table
|
||||||
---@param filter fun(value:any, key:any):boolean
|
---@param filter fun(value:any, key:any):boolean
|
||||||
---@return table
|
---@return table
|
||||||
@@ -122,7 +111,7 @@ function xLib.table.dump(tbl)
|
|||||||
local s = '{ '
|
local s = '{ '
|
||||||
for k,v in pairs(tbl) do
|
for k,v in pairs(tbl) do
|
||||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||||
s = s .. '['..k..'] = ' .. tbl(v) .. ','
|
s = s .. '['..k..'] = ' .. xLib.table.dump(v) .. ','
|
||||||
end
|
end
|
||||||
return s .. '} '
|
return s .. '} '
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user