summaryrefslogtreecommitdiff
path: root/lib.lua
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-02-01 18:10:09 -0500
committerShadowNinja <shadowninja@minetest.net>2015-02-01 18:10:09 -0500
commit4404c4071cddfd7c30b2420be54d184067797482 (patch)
treed555b2fe6773e8216d811ef95833f18e3cc2d3d4 /lib.lua
parentc4335aa3dca1d568167adcf13ec1285b76f25a9a (diff)
Add numbered insertions
Diffstat (limited to 'lib.lua')
-rw-r--r--lib.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/lib.lua b/lib.lua
index b3f183b..2349de4 100644
--- a/lib.lua
+++ b/lib.lua
@@ -1,19 +1,37 @@
intllib = intllib or {}
+local INS_CHAR = "@"
+intllib.INSERTION_CHAR = INS_CHAR
+
local escapes = {
["\\"] = "\\",
["n"] = "\n",
+ [INS_CHAR] = INS_CHAR..INS_CHAR,
}
-local function unescape(s)
- return s:gsub("([\\]?)\\(.)", function(slash, what)
- if slash and (slash ~= "") then
- return "\\"..what
+local function unescape(str)
+ local parts = {}
+ local n = 1
+ local function add(s)
+ parts[n] = s
+ n = n + 1
+ end
+
+ local start = 1
+ while true do
+ local pos = str:find("\\", start, true)
+ if pos then
+ add(str:sub(start, pos - 1))
else
- return escapes[what] or what
+ add(str:sub(start))
+ break
end
- end)
+ local c = str:sub(pos + 1, pos + 1)
+ add(escapes[c] or c)
+ start = pos + 2
+ end
+ return table.concat(parts)
end
local function find_eq(s)