*** empty log message ***

git-svn-id: file:///var/svn/lua-iconv/trunk@16 9538949d-8f27-0410-946f-ce01ef448559
This commit is contained in:
Alexandre Erwin Ittner 2005-07-08 02:25:50 +00:00
parent c4709924a3
commit 3952102886

52
iconv.lua Normal file
View File

@ -0,0 +1,52 @@
-- Common locations (add new ones if needed).
local locs = {
-- Unices
"libluaiconv.so",
"./libluaiconv.so",
"/usr/lib/libluaiconv.so",
"/usr/local/lib/libluaiconv.so",
"/usr/local/lib/lua/5.0/lib/libluaiconv.so",
-- Windows
"libluaiconv.dll",
"luaiconv.dll",
".\\luaiconv.dll",
".\\libluaiconv.dll",
"c:\\lua\\lib\\libluaiconv.dll"
}
local loadiconv, fname, ndx
for ndx, fname in ipairs(locs) do
loadiconv = loadlib(fname, "luaopen_iconv")
if loadiconv then
break
end
end
assert(loadiconv, "Can't load Lua-iconv")
loadiconv()
-- An useful extension: Detects automatically the charset of the string
-- and returns it on the chosen one.
iconv.commoncharsets = {
"ascii", "iso-8859-1", "utf-8", "utf-16", "windows-1252"
}
iconv.autoconvert = function(tocode, str)
local _, fromcode, cd, ret, err
for _, fromcode in pairs(iconv.commoncharsets) do
cd = iconv.new(tocode, fromcode)
ret, err = cd:iconv(str)
if not err then
return ret
end
end
return nil
end