diff options
| author | ruki <[email protected]> | 2020-09-29 00:35:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-09-29 00:35:13 +0800 |
| commit | 675fc8fca1e62f24e505523eb1b8e0523a9ffb94 (patch) | |
| tree | 61da761bba308ade0ce8455c674e792822c71c86 /xmake/core/base/string.lua | |
| parent | d662c54d57accd1382c2368e3c7f27832d9ef10d (diff) | |
improve cmake/install and add string.replace
Diffstat (limited to 'xmake/core/base/string.lua')
| -rw-r--r-- | xmake/core/base/string.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua index 9adf9e748..3a4eab821 100644 --- a/xmake/core/base/string.lua +++ b/xmake/core/base/string.lua @@ -137,6 +137,21 @@ function string:decode() return (self:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end)) end +-- replace text +function string:replace(old, new, opt) + if opt and opt.plain then + local b, e = self:find(old, 1, true) + if b == nil then + return self, 0 + else + local str, count = self:sub(e + 1):replace(old, new, opt) + return (self:sub(1, b - 1) .. new .. str), count + 1 + end + else + return self:gsub(old, new) + end +end + -- try to format function string.tryformat(format, ...) |
