summaryrefslogtreecommitdiff
path: root/xmake/core/sandbox/modules/io.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-06 00:49:41 +0800
committerruki <[email protected]>2022-10-06 00:49:41 +0800
commite8d8b9e3ab29ac0dd9a79f0354bb4faec28f3851 (patch)
tree22b2e954dc8333c901e99bcd3eee0087694bc83e /xmake/core/sandbox/modules/io.lua
parent8055b6a045eabe62935a550e5d58d13591950c11 (diff)
add io.insert
Diffstat (limited to 'xmake/core/sandbox/modules/io.lua')
-rw-r--r--xmake/core/sandbox/modules/io.lua25
1 files changed, 12 insertions, 13 deletions
diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua
index f424872eb..6aeb8ce13 100644
--- a/xmake/core/sandbox/modules/io.lua
+++ b/xmake/core/sandbox/modules/io.lua
@@ -170,14 +170,8 @@ end
-- gsub the given file and return replaced data
function sandbox_io.gsub(filepath, pattern, replace, opt)
-
- -- check
assert(filepath)
-
- -- format it first
filepath = vformat(filepath)
-
- -- replace all
local data, count, errors = io.gsub(filepath, pattern, replace, opt)
if not data then
raise(errors)
@@ -185,16 +179,10 @@ function sandbox_io.gsub(filepath, pattern, replace, opt)
return data, count
end
--- replace text of the given file and return replaced data
+-- replace text of the given file and return new data
function sandbox_io.replace(filepath, pattern, replace, opt)
-
- -- check
assert(filepath)
-
- -- format it first
filepath = vformat(filepath)
-
- -- replace all
local data, count, errors = io.replace(filepath, pattern, replace, opt)
if not data then
raise(errors)
@@ -202,6 +190,17 @@ function sandbox_io.replace(filepath, pattern, replace, opt)
return data, count
end
+-- insert text before line number in the given file and return new data
+function sandbox_io.insert(filepath, lineidx, text, opt)
+ assert(filepath)
+ filepath = vformat(filepath)
+ local data, errors = io.insert(filepath, lineidx, text, opt)
+ if not data then
+ raise(errors)
+ end
+ return data
+end
+
-- get std file
function sandbox_io.stdfile(filepath)