我有这段遗留代码,它能够解码双重编码的UTF-8文本并还原为正常的UTF-8:
# Run with python3!
import codecs
import sys
s=codecs.open('doubleutf8.dat', 'r', 'utf-8').read()
sys.stdout.write(
s
.encode('raw_unicode_escape')
.decode('utf-8')
)
我需要将它翻译成Lua,并模仿所有可能的解码副作用(如果有的话)。
限制:我可以使用任何可用的Lua模块来处理UTF-8,但最好是稳定的,支持LuaRocks。我不会使用Lupa或其他Lua-Python桥接解决方案,也不会调用
os.execute()
来调用Python。
raw_unicode_escape
是什么?),我想看到一段实际的Lua代码。抱歉在这里有些懒。 - Alexander Gladysh