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:
YOMAN1792
2025-05-08 10:33:03 -04:00
committed by GitHub
parent e30d4e49f5
commit 01e29f6e9b
+6 -1
View File
@@ -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