mhwlng
August 1st, 2008, 11:58 AM
A lot of web based stuff needs strings in utf-8 format (e.g. last.fm track submission)
Netremote has built-in lua string character set conversion functions.
Girder doesn't have these, but this works :
require 'htmltidy'
function stringconvert (instr,fromencoding,toencoding)
local c = htmltidy.new()
c:setOpt(htmltidy.opt.XmlTags, true)
c:setOpt(htmltidy.opt.NumEntities, false)
c:setOpt(htmltidy.opt.WrapLen, 9999)
c:setOpt(htmltidy.opt.ForceOutput, true)
c:setOpt(htmltidy.opt.InCharEncoding, fromencoding)
c:setOpt(htmltidy.opt.OutCharEncoding, toencoding)
c:parse("<![CDATA["..instr.."]]>")
local _,_,resultstr = string.find (c:saveToString(),"<!%[CDATA%[(.-)%]%]>");
return resultstr
end
print (stringconvert ("Anaïs Mitchell,"latin1","utf8"))
Anïs Mitchell
Marcel
Netremote has built-in lua string character set conversion functions.
Girder doesn't have these, but this works :
require 'htmltidy'
function stringconvert (instr,fromencoding,toencoding)
local c = htmltidy.new()
c:setOpt(htmltidy.opt.XmlTags, true)
c:setOpt(htmltidy.opt.NumEntities, false)
c:setOpt(htmltidy.opt.WrapLen, 9999)
c:setOpt(htmltidy.opt.ForceOutput, true)
c:setOpt(htmltidy.opt.InCharEncoding, fromencoding)
c:setOpt(htmltidy.opt.OutCharEncoding, toencoding)
c:parse("<![CDATA["..instr.."]]>")
local _,_,resultstr = string.find (c:saveToString(),"<!%[CDATA%[(.-)%]%]>");
return resultstr
end
print (stringconvert ("Anaïs Mitchell,"latin1","utf8"))
Anïs Mitchell
Marcel