mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
refactor(locale): improve performance and type safety in IsValidLocaleString
- Replaced `ipairs` with a numeric `for` loop in the UTF-8 validation step for better performance. - Stored `validRanges[i]` in a local `range` variable to avoid duplicate table lookups. - Added a call to `ESX.ValidateType(str, 'string')` to ensure input is of type string before processing. These changes improve both performance and code safety.
This commit is contained in:
@@ -214,6 +214,10 @@ end
|
||||
---@param str string
|
||||
---@return boolean
|
||||
function ESX.IsValidLocaleString(str)
|
||||
if not ESX.ValidateType(str, 'string') then
|
||||
return false
|
||||
end
|
||||
|
||||
local locale = string.lower(Config.Locale)
|
||||
|
||||
local defaultRanges ={
|
||||
@@ -265,7 +269,8 @@ function ESX.IsValidLocaleString(str)
|
||||
for _, code in utf8.codes(str) do
|
||||
local isValid = false
|
||||
|
||||
for _, range in ipairs(validRanges) do
|
||||
for i = 1, #validRanges do
|
||||
local range = validRanges[i]
|
||||
if code >= range[1] and code <= range[2] then
|
||||
isValid = true
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user