Encoding Action Plugin

Description

This is a action plugin that allows you to perform conversions between different character encodings.

These are the encodings that are accepted as fromEncoding and toEncoding in the actions:

asmo-708

big5

cp866

cp875

dos-720

dos-862

euc-jp

euc-kr

gb2312

ibm00858

ibm037

ibm437

ibm500

ibm737

ibm775

ibm850

ibm852

ibm855

ibm857

ibm860

ibm861

ibm863

ibm864

ibm865

ibm869

ibm870

iso-2022-jp

iso-2022-kr

iso-8859-1

iso-8859-2

iso-8859-3

iso-8859-4

iso-8859-5

iso-8859-6

iso-8859-7

iso-8859-8

iso-8859-9

iso-8859-13

iso-8859-15

koi8-r

koi8-u

ks_c_5601-1987

macintosh

shift_jis

unicode

unicodefffe

us-ascii

utf-7

utf-8

utf-32

utf-32be

windows-874

windows-1250

windows-1251

windows-1252

windows-1253

windows-1254

windows-1255

windows-1256

windows-1257

windows-1258

x-mac-arabic

x-mac-ce

x-mac-chinesesimp

x-mac-chinesetrad

x-mac-croatian

x-mac-cyrillic

x-mac-greek

x-mac-hebrew

x-mac-icelandic

x-mac-japanese

x-mac-korean

x-mac-romanian

x-mac-thai

x-mac-turkish

x-mac-ukrainian

Actions

Encoding.ConvertFile(string InputFilename, string fromEncoding, string OutputFilename, string toEncoding);

Description:

Reads the contents of a text file in one encoding and saves it using different encoding.

InputFilename:

(string) The full path to the input text file.

fromEncoding:

(string) The encoding of the source file to be read.

OutputFilename:

(string) The full path to the output text file.

toEncoding:

(string) The encoding of the destination text file.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Encoding.ConvertString(string InputString, string fromEncoding, string toEncoding);

Description:

Converts a string from one encoding to another string with different encoding.

InputString:

(string) The full path to the input text file.

fromEncoding:

(string) The encoding of the source file to be read.

toEncoding:

(string) The encoding of the destination text file.

Returns:

(string) The converted string in the new character encoding. You can use Application.GetLastError to determine whether this action failed, and why.

Encoding.ReadToTable(string Filename, string fromEncoding, string toEncoding);

Description:

Reads the contents of a text file in a certain encoding and returns it as a table in a different encoding.

Filename:

(string) The full path to the text file.

fromEncoding:

(string) The encoding of the source file to be read.

toEncoding:

(string) The optional encoding of the converted text in the table. The default is "iso-8859-1" (ANSI Latin-1).

Returns:

(table) 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 = Encoding.ReadToTable(strFile, "unicode", "windows-1251");
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

Encoding.ReadToString(string Filename, string fromEncoding, string toEncoding);

Description:

Reads the contents of a text file in one encoding and returns it as a string in a different encoding.

Filename:

(string) The full path to the text file.

fromEncoding:

(string) The encoding of the source file to be read.

toEncoding:

(string) The optional encoding of the converted text in the string. The default is "iso-8859-1" (ANSI Latin-1).

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 = Encoding.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

Encoding.WriteFromTable(string Filename, table Text, string toEncoding, string fromEncoding);

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.

toEncoding:

(string) The encoding of the file to be written.

fromEncoding:

(string) The optional encoding of the text in the table. If omitted, "iso-8859-1" (ANSI Latin-1) is assumed.

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
Encoding.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

Encoding.WriteFromString(string Filename, string Text, string toEncoding, string fromEncoding);

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.

toEncoding:

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

fromEncoding:

(string) The optional encoding of the text stored in the string. If omitted, "iso-8859-1" (ANSI Latin-1) is assumed.

Returns:

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

Example:

-- save a string with Russian text as a file in Unicode encoding
Encoding.WriteFromString(_TempFolder .. "\\unicodeFile.txt", myString, "unicode", "windows-1251");
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 Encoding Actions plugin.
12031 - Conversion failed.
12032 - File not found.
12033 - Could not save file.
12034 - Internal error.

Change Log

1.0.0.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 © 2009-2011 MindQuake Serviços de Informática Ltda.
Todos os direitos reservados.