summaryrefslogtreecommitdiff
path: root/xmake/core/base/string.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-07-17 22:38:21 +0800
committerruki <[email protected]>2019-07-17 09:50:12 +0800
commit7138d5770975053ad4fe60f1d8bdd5e4c774fe5b (patch)
treea6ca7509a4522337687e22f586f786c8c8395208 /xmake/core/base/string.lua
parent54386754982c5580e9d351484eabd45ebfd20c48 (diff)
optimize string.trim using c implemention
Diffstat (limited to 'xmake/core/base/string.lua')
-rw-r--r--xmake/core/base/string.lua17
1 files changed, 4 insertions, 13 deletions
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua
index 5242a0a1e..77cb36e68 100644
--- a/xmake/core/base/string.lua
+++ b/xmake/core/base/string.lua
@@ -23,6 +23,7 @@ local string = string or {}
-- save original interfaces
string._dump = string._dump or string.dump
+string._trim = string._trim or string.trim
-- make string with the level
function string._makestr(object, deflate, serialize, level)
@@ -190,36 +191,26 @@ end
-- trim the spaces
function string:trim()
- return (self:gsub("^%s*(.-)%s*$", "%1"))
+ return self:_trim(0)
end
-- trim the left spaces
function string:ltrim()
- return (self:gsub("^%s*", ""))
+ return self:_trim(-1)
end
-- trim the right spaces
function string:rtrim()
- return (self:gsub("%s*$", ""))
+ return self:_trim(1)
end
-- encode: ' ', '=', '\"', '<'
function string:encode()
-
- -- null?
- if self == nil then return end
-
- -- done
return (self:gsub("[%s=\"<]", function (w) return string.format("%%%x", w:byte()) end))
end
-- decode: ' ', '=', '\"'
function string:decode()
-
- -- null?
- if self == nil then return end
-
- -- done
return (self:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end))
end