Module iconv
POSIX iconv binding for Lua.
Converts strings from one codeset to another. For more information, see the original Lua-iconv documentation.
For implementation-specific details of each function, see the corresponding z/OS C runtime library functions.
Functions
| iconv (converter, string) | Converts a string from one codeset to another. |
| new (to, from) | Create a conversion descriptor that you can then use with the iconv function to convert a string from one codeset to another. |
| open (to, from) | A synonym for the new function. |
Functions
- iconv (converter, string)
-
Converts a string from one codeset to another.
This function calls the C runtime library function
iconv().Parameters:
- converter
A conversion descriptor created previously by the
iconvfunction. - string string The string that you want to convert.
Returns:
-
Two arguments: the converted string and an error code.
The error code has one of the following values:
iconverror codesError code Description nilNo error. Conversion was successful. iconv.ERROR_NO_MEMORYFailed to allocate enough memory in the conversion process. iconv.ERROR_INVALIDAn invalid character was found in the input sequence. iconv.ERROR_INCOMPLETEAn incomplete character was found in the input sequence. iconv.ERROR_FINALIZEDTrying to use an already-finalized converter. This usually means that the user was tweaking the garbage collector private methods. iconv.ERROR_UNKNOWNThere was an unknown error. See also:
Usage:
-- Assumes that you have created a conversion descriptor named converter local before = "Transliterate me" local after = converter:iconv(before)
- converter
A conversion descriptor created previously by the
- new (to, from)
-
Create a conversion descriptor that you can then use with the
iconvfunction to convert a string from one codeset to another.For a list of supported codesets, see the IBM documentation.
Parameters:
- to
string
A string that specifies the codeset that you want to convert from.
To enable character transliteration, append the string "//TRANSLIT" to the value of this parameter.
To ignore invalid characters in the input string to the
iconvfunction, append the string "//IGNORE" to the value of this parameter. - from string A string that specifies the codeset that you want to convert to.
Returns:
-
A conversion descriptor that describes a conversion between two codesets,
or
nilon error.See also:
Usage:
local iconv = require("iconv") -- Specify codesets local from = "IBM-1047" local to = "ISO8859-1" -- Create conversion descriptor with transliteration option local converter = iconv.new(to .. "//TRANSLIT", from)
- to
string
A string that specifies the codeset that you want to convert from.
- open (to, from)
- A synonym for the new function.
