Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lua/entities/gmod_wire_expression2/base/preprocessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
return string.sub(line, first, last)
end

function PreProcessor:TrimLeft(line)
for i = 1, #line do
local b = string.byte(line, i)

if b ~= 32 and (b < 9 or b > 13) then
return string.sub(line, i)
end
end

return ""
end

function PreProcessor:TrimRight(line)
for i = #line, 1, -1 do
local b = string.byte(line, i)
Expand All @@ -123,7 +135,6 @@
end
end

-- The line consists only of spaces
return ""
end

Expand Down Expand Up @@ -527,7 +538,7 @@
if not i then
-- no -> malformed variable name
self:Error("Variable name (" .. E2Lib.limitString(key, 10) .. ") must start with an uppercase letter", tr, { { at = tr, replace = key:sub(1, 1):upper() .. key:sub(2) } })
goto cont

Check warning on line 541 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
else
-- yes -> add all variables.
for column2, var in namestring:gmatch("()([^,]+)") do
Expand Down Expand Up @@ -568,7 +579,7 @@

if vtype ~= vtype:lower() then
self:Error("Variable type [" .. E2Lib.limitString(vtype, 10) .. "] must be lowercase", tr, { { at = tr, replace = vtype:lower() } })
goto cont

Check warning on line 582 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
elseif vtype == "number" then
vtype = "normal"
elseif vtype == "normal" then
Expand All @@ -580,7 +591,7 @@
else
-- invalid -> raise an error
self:Error("Variable declaration (" .. E2Lib.limitString(key, 10) .. ") contains invalid characters", tr)
goto cont

Check warning on line 594 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
end

-- fill in the missing types
Expand Down
31 changes: 7 additions & 24 deletions lua/entities/gmod_wire_expression2/core/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,34 +231,17 @@ end

__e2setcost(2)

-- E2Lib.PreProcessor trimming functions are much more efficient than regular ones, so it's better to use them
e2function string string:trim()
local ok, ret = pcall(function() WireLib.CheckRegex(this, "^%s*(.-)%s*$") return string.Trim(this) end)

if not ok then
return self:throw(ret)
else
return ret
end
return E2Lib.PreProcessor.Trim(nil, this)
end

e2function string string:trimLeft()
local ok, ret = pcall(function() WireLib.CheckRegex(this, "^%s*(.+)$") return string.TrimLeft(this) end)

if not ok then
return self:throw(ret)
else
return ret
end
return E2Lib.PreProcessor.TrimLeft(nil, this)
end

e2function string string:trimRight()
local ok, ret = pcall(function() WireLib.CheckRegex(this, "^(.-)%s*$") return string.TrimRight(this) end)

if not ok then
return self:throw(ret)
else
return ret
end
return E2Lib.PreProcessor.TrimRight(nil, this)
end

--[[******************************************************************************]]--
Expand All @@ -270,7 +253,7 @@ e2function number string:findRE(string pattern)
local ok, ret = pcall(function() WireLib.CheckRegex(this, pattern) return string_find(this, pattern) end)

if not ok then
return self:throw(ret)
return self:throw(ret, 0)
else
return ret or 0
end
Expand All @@ -281,7 +264,7 @@ e2function number string:findRE(string pattern, start)
local ok, ret = pcall(function() WireLib.CheckRegex(this, pattern) return string_find(this, pattern, start) end)

if not ok then
return self:throw(ret)
return self:throw(ret, 0)
else
return ret or 0
end
Expand Down Expand Up @@ -571,4 +554,4 @@ end
[nodiscard]
e2function string hashSHA256(string text)
return hash_generic(self, text, util.SHA256)
end
end
Loading