diff --git a/lua/entities/gmod_wire_expression2/base/preprocessor.lua b/lua/entities/gmod_wire_expression2/base/preprocessor.lua index 2868e508f6..3a44320631 100644 --- a/lua/entities/gmod_wire_expression2/base/preprocessor.lua +++ b/lua/entities/gmod_wire_expression2/base/preprocessor.lua @@ -114,6 +114,18 @@ function PreProcessor:Trim(line) 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) @@ -123,7 +135,6 @@ function PreProcessor:TrimRight(line) end end - -- The line consists only of spaces return "" end diff --git a/lua/entities/gmod_wire_expression2/core/string.lua b/lua/entities/gmod_wire_expression2/core/string.lua index eb62f04a33..c7c6774b25 100644 --- a/lua/entities/gmod_wire_expression2/core/string.lua +++ b/lua/entities/gmod_wire_expression2/core/string.lua @@ -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 --[[******************************************************************************]]-- @@ -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 @@ -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 @@ -571,4 +554,4 @@ end [nodiscard] e2function string hashSHA256(string text) return hash_generic(self, text, util.SHA256) -end \ No newline at end of file +end