diff options
| author | ruki <[email protected]> | 2015-06-03 18:34:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-03 18:34:06 +0800 |
| commit | a73db10e9b42c8b18bf5b95d78855481beb67f20 (patch) | |
| tree | b2e13353bc39cfd3f3b0cfb115b07bc15e505a00 /xmake/scripts/base/string.lua | |
| parent | 795001d9b03960d9a8fc290e6f6f9710f49c86bc (diff) | |
trim spaces for the makefile command
Diffstat (limited to 'xmake/scripts/base/string.lua')
| -rw-r--r-- | xmake/scripts/base/string.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/xmake/scripts/base/string.lua b/xmake/scripts/base/string.lua index 793abad00..3abe68c05 100644 --- a/xmake/scripts/base/string.lua +++ b/xmake/scripts/base/string.lua @@ -49,5 +49,46 @@ function string.split(self, pattern) return list end +-- trim the spaces +function string.trim(self) + return (self:gsub("^%s*(.-)%s*$", "%1")) +end + +-- trim the left spaces +function string.ltrim(self) + return (self:gsub("^%s*", "")) +end + +-- trim the right spaces +function string.rtrim(self) + local n = #self + while n > 0 and s:find("^%s", n) do n = n - 1 end + return self:sub(1, n) +end + +-- append a substring with a given separator +function string.append(self, substr, separator) + + -- check + assert(self) + + -- not substr? return self + if not substr then + return self + end + + -- append it + local s = self + if #s == 0 then + s = substr + else + s = string.format("%s%s%s", s, separator or "", substr) + end + + -- ok + return s +end + + -- return module: string return string |
