core :: Text :: escape_to_sh
Abort if the text contains a null byte.
assert "\n\"'\\\{\}0".escape_to_sh == "'\n\"'\\''\\\{\}0'"
# Escape to POSIX Shell (sh).
#
# Abort if the text contains a null byte.
#
# ~~~
# assert "\n\"'\\\{\}0".escape_to_sh == "'\n\"'\\''\\\{\}0'"
# ~~~
fun escape_to_sh: String do
var b = new Buffer
b.chars.add '\''
for i in [0..length[ do
var c = chars[i]
if c == '\'' then
b.append("'\\''")
else
assert without_null_byte: c != '\0'
b.add(c)
end
end
b.chars.add '\''
return b.to_s
end
lib/core/text/abstract_text.nit:761,2--782,4