Unicode Action Plugin

Description

This is a small action plugin that allows you to read UTF-8 and Unicode encoded text files into a string, as well as save a string as a text file encoded in ANSI (Latin-1), UTF-8 or Unicode format.

Actions

Unicode.ReadToTable(string Filename, string Encoding);

Description:

Reads the contents of a text file in UTF-8 or Unicode encoding and returns it as a table where each line is an element, in ANSI (Latin-1) encoding.

Filename:

(string) The full path to the text file.

Encoding:

(string) The encoding of the file to be read. Allowed options are: "iso-8859-1" (no conversion) , "utf-8" and "unicode".

Returns:

(string) The converted text file as table. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- read a text file in Unicode encoding
strFile = _TempFolder .. "\\TextFile.txt";
myTable = Unicode.ReadToTable(strFile, "unicode");
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", "Got error code " .. error .. " while converting from Unicode", MB_OK, MB_ICONEXCLAMATION);
else
    -- now read each line in the table
    for i, text in myTable do
        Dialog.Message("info", "line " .. i .. " contains: " .. text, MB_OK);
    end
end

Unicode.ReadToString(string Filename, string Encoding);

Description:

Reads the contents of a text file in UTF-8 or Unicode encoding and returns it as a string in ANSI (Latin-1) encoding.

Filename:

(string) The full path to the text file.

Encoding:

(string) The encoding of the file to be read. Allowed options are: "iso-8859-1" (no conversion) , "utf-8" and "unicode".

Returns:

(string) The converted text file as string. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- read a XML file in UTF-8 encoding
strXMLPath = _TempFolder .. "\\utf8File.xml";
convertedXml = Unicode.ReadToString(strXMLPath, "utf-8");
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", "Got error code " .. error .. " while converting from UTF-8", MB_OK, MB_ICONEXCLAMATION);
else
    -- everything ok, proceed with XML processing...
    XML.SetXML(convertedXml);
end

Unicode.WriteFromTable(string Filename, table Text, string Encoding);

Description:

Writes a table's contents out to a text file. The table should consist of one line of text per table item.

Filename:

(string) The full path to the text file.

Text:

(table) The lines of text to write.

Encoding:

(string) The encoding of the file to be written. Allowed options are: "iso-8859-1", "utf-8" and "unicode".

Returns:

(nothing) You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- save a table as text file with UTF-8 encoding
Unicode.WriteFromTable(_TempFolder .. "\\utf8File.txt", myTable, "utf-8");
if (error ~= 0) then
    Dialog.Message("Error", "Got error code " .. error .. " while converting to UTF-8", MB_OK, MB_ICONEXCLAMATION);
end

Unicode.WriteFromString(string Filename, string Text, string Encoding);

Description:

Writes a string of text to a new file in a specific character encoding.

Filename:

(string) The full path to the text file.

Text:

(string) The string of text to write.

Encoding:

(string) The encoding of the file to be written. Allowed options are: "iso-8859-1", "utf-8" and "unicode".

Returns:

(nothing) You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- save a string as text file with Unicode encoding
Unicode.WriteFromString(_TempFolder .. "\\unicodeFile.txt", myString, "unicode");
if (error ~= 0) then
    Dialog.Message("Error", "Got error code " .. error .. " while converting to Unicode", MB_OK, MB_ICONEXCLAMATION);
end

 

Error Codes

12030 - Failed to start Unicode Actions plugin.
12031 - Conversion failed.
12032 - File not found.
12033 - Could not save file.
12034 - Internal error.

Change Log

1.0.2.0

1.0.1.0

 

Additional Information

Author:

Ulrich Peters
upeters@mindquake.com.br

Copyright:

Plugin is copyright © 2009 MindQuake Serviços de Informática Ltda.

Website:

http://www.mindquake.com.br


Copyright © 2008-2009 MindQuake Serviços de Informática Ltda.
Todos os direitos reservados.