summaryrefslogtreecommitdiff
path: root/xmake/scripts/base/string.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2015-12-05 10:04:47 +0800
committerruki <[email protected]>2015-12-05 10:04:47 +0800
commitb753c9e182813b395dd4910476ff4fb3c5e26fd9 (patch)
treee9233083762f24c2f988f4d31d7cec846d55bfb2 /xmake/scripts/base/string.lua
parent98a12249aff0eed41c11f31da54205dc876379bf (diff)
encode and decode string
Diffstat (limited to 'xmake/scripts/base/string.lua')
-rw-r--r--xmake/scripts/base/string.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/xmake/scripts/base/string.lua b/xmake/scripts/base/string.lua
index 3abe68c05..d6f3bf748 100644
--- a/xmake/scripts/base/string.lua
+++ b/xmake/scripts/base/string.lua
@@ -89,6 +89,26 @@ function string.append(self, substr, separator)
return s
end
+-- encode: ' ', '=', '\"', '<'
+function string.encode(self)
+
+ -- 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(self)
+
+ -- null?
+ if self == nil then return end
+
+ -- done
+ return (self:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end))
+end
+
-- return module: string
return string