Transcoder
Utils.getTranscoder(fromEncoding, toEncoding)
Instantiates a transcoder function that converts from fromEncoding to toEncoding. Requires the Utils module. This is the recommended way to create a transcoder.
Sample:
package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/Utils.lua"
local Utils = require "Utils"
local transcode = Utils.getTranscoder("UTF-8", "ISO-8859-1")
transcoded = transcode(value)
Converts value from the source encoding to the target encoding. The encoded bytes are returned in transcoded. If transcoding the entire value was not possible, the remaining bytes are transcoded on the next call. If nil is passed and there are still bytes left to transcode, an error will occur.
Sample — convert an incoming body from UTF-8 to ISO-8859-1:
package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/Utils.lua"
local Utils = require "Utils"
local transcode = Utils.getTranscoder("UTF-8", "ISO-8859-1")
function outputStream(req, resp, chunk)
return transcode(chunk)
end
nevis.charset.transcoder.new(fromEncoding, toEncoding)
Instantiates a low-level transcoder object. Only for advanced users — use Utils.getTranscoder() whenever possible.
Sample:
local transcoder = nevis.charset.transcoder.new("UTF-8", "ISO-8859-1")
transcoded, remaining = transcoder:transcode(value)
Converts value from the source encoding to the target encoding. Returns the transcoded bytes in transcoded and any bytes that could not be transcoded in remaining.