]> git.lizzy.rs Git - worldedit.git/commitdiff
Fix nodename normalization with translated descriptions
authorsfan5 <sfan5@live.de>
Wed, 18 Sep 2019 16:38:49 +0000 (18:38 +0200)
committersfan5 <sfan5@live.de>
Wed, 18 Sep 2019 16:48:31 +0000 (18:48 +0200)
worldedit_commands/init.lua

index d11eb9dca060f9ddaa4d6592ce5673d39d168ab5..4e067daab76b8e8c35b1a44b7faad31379d3fcab 100644 (file)
@@ -37,6 +37,33 @@ function worldedit.player_notify(name, message)
        minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)\r
 end\r
 \r
+-- https://github.com/minetest/minetest/blob/53dd7819277c53954d1298dfffa5287c306db8d0/src/util/string.cpp#L777\r
+local function strip_translation_escapes(input)\r
+       local s = function(idx) return input:sub(idx, idx) end\r
+       local out = ""\r
+       local i = 1\r
+       while i <= #input do\r
+               if s(i) == "\027" then -- escape sequence\r
+                       i = i + 1\r
+                       if s(i) == "(" then -- enclosed\r
+                               i = i + 1\r
+                               while i <= #input and s(i) ~= ")" do\r
+                                       if s(i) == "\\" then\r
+                                               i = i + 2\r
+                                       else\r
+                                               i = i + 1\r
+                                       end\r
+                               end\r
+                       end\r
+               else\r
+                       out = out .. s(i)\r
+               end\r
+               i = i + 1\r
+       end\r
+       --print(("%q -> %q"):format(input, out))\r
+       return out\r
+end\r
+\r
 local function string_endswith(full, part)\r
        return full:find(part, 1, true) == #full - #part + 1\r
 end\r
@@ -57,7 +84,7 @@ worldedit.normalize_nodename = function(nodename)
        end\r
        nodename = nodename:lower() -- lowercase both for case insensitive comparison\r
        for key, value in pairs(minetest.registered_nodes) do\r
-               local desc = value.description:lower()\r
+               local desc = strip_translation_escapes(value.description):lower()\r
                if desc == nodename then -- matches description\r
                        return key\r
                end\r