Add a new Ansel Encoding - no plugins

Hello Everyone,

I have been asked about creating a solution for reading a file, and the file uses special characters which are ANSEL (American National Standard for Extended Latin), and here is the code page layout on ANSEL Wikipedia.

Is there a way to create a new encoding in native Xojo that works in both Windows and OS X?

Example pseudocode that this may look like in its final form would be:

[code]Dim AllFiles as New FileType
AllFiles.Name = “GEDCOM”
AllFiles.Extensions = “GED”
AllFiles.MacType = “GED”
AllFiles.MacCreator = “*”

Dim doc As FolderItem = GetOpenFolderitem(AllFiles)
Dim bs As BinaryStream = BinaryStream.Open(doc, False) // Open as read-only

//Convert to correct encoding (ANSEL)
Dim s as String
s = bs.Read(bs.Length)
s = s.DefineEncoding(Encodings.ANSEL) //Ansel encoding here…

// Read the whole BinaryStream
TextArea1.Text = s [/code]

If making this kind of encoding is not possible, then thats ok too.

As far as I can see it’s not so easy. This page describes the structure and translation. Hard to follow, because some characters have only one byte, some two (e.g. E0+41 = &u1EA2 > Latin Capital Letter A + Combining Hook above ? ) and some three (e.g. E0+E3+6F = &u1ED5 > Latin small Letter O + Combining Circumflex Accent + Combining Hook above ? ).

I think it needs a conversion table and a way, i don’t know, to search within the binary Data for those bytes and replace them. Maybe not in the source file, only within a variable which holds the source file.

Howevery i would prefer the new Xojo Framework if there is a way to do it. Can you work with this Eugene? Or any other Xojo developer?

I think ANSEL is obsolete except for its use in GEDCOM files. I had a look at it when it was discussed in this topic:
https://forum.xojo.com/18087-gedcom-parser/0
Though the topic has more to do with GEDCOM than ANSEL. There’s a link near the bottom to a GEDCOM to XML parser project that I wrote. But I avoided any attempt to read/convert anything except ASCII or Unicode. However it does read ANSEL treating it as single byte characters.

It would be interesting to see if it’s possible to add a new encoding to Xojo. But, I suspect the most practical solution is to read the text as a binary stream and process it byte by byte.

When reading this file (ANSEL.ged) with Hex Fiend we can see it’s an UTF-8 Textfile. Now reading it into Xojo and save a copy:

[code]Using Xojo.Core
Using Xojo.IO

Dim inputFile As FolderItem = SpecialFolder.Documents.Child(“ANSEL.ged”)
Dim outputFile As FolderItem = SpecialFolder.Documents.Child(“ANSEL out.ged”)

Try
Dim input As TextInputStream
input = TextInputStream.Open(inputFile, TextEncoding.UTF8)

Dim output As TextOutputStream
output = TextOutputStream.Create(outputFile, TextEncoding.UTF8)

Dim conv As Text = input.ReadAll
// wont find this combination, because after ReadAll, Xojo converted F5 41 into EF BF BD
conv = conv.ReplaceAll(&uF5 + &u41, “A?”) // &uF = double low line, &u41 = Latin Capital Letter A

output.Write(conv)
output.Close
Catch e As IOException
MsgBox "File IO Error: " + e.Reason
End Try [/code]

Now, if you compare both files in Hex Fiend, watch e.g. Line 227, then you can see in “ANSEL out.ged” that the Hex-Value after 2 PLAC is changed from 2 Bytes (Double Byte Character)

F5 41

into 4 Bytes

EF BF BD 41

That’s wrong. By the way, Xojo converts every invisible Byte before the Letter Hex-Value into EF BF BD. Thats wrong! Why does Xojo not convert into the same UTF-8 Hex-Values like the Source-File? I need the right value to decode the letters behind PLAC into the right UTF-8 code. After conversion with ReplaceAll it should look like this (in a normal Text-Editor):

2 PLAC A?B?C?D?E?F?G?H?I?J?K?L?M?N?O?P?Q?R?S?T?U?V?W?X?Y?Z?

As you can see, each letter is built on two letters (one invisible, diacritic and the normal one).

Why do say that it’s a UTF-8 file? I see nothing to indicate that. In fact the second line in the file is the encoding specification stating that it’s ANSEL. Xojo will assume an input file to be UTF-8 by default, if it is not instructed otherwise. If it attempts to interpret the ANSEL file as UTF-8, then you can’t really blame it for making wrong substitutions.

Edited to add:

In UTF-8 ‘F5’ is an illegal byte. It should never appear. So it is replaced with EFBFBD which is the unicode replacement character (diamond with question mark inside).

Hi Robert. Yes, the file does appear to be a UTF-8 file since there appears to be 256 characters and when using a Byte-Order-Mark program, the binary data remains UTF-8. The issue seems to be that when the incorrect encoding is used, then the unknown character numbers are automatically converted to the question mark in Xojo, which is the encoding.

Just for fun when I use a different encoding, characters appear and there are no errors. The problem is that the encoded characters assigned to the 8 bits are incorrect. This is the reason for my request to create a new encoding - if creation of a new encoding type is possible in Xojo. :slight_smile:

ANSEL is a 256 byte character encoding, and when I looked at the file with a hex editor, all of the bytes >127 were valid ANSEL extended characters or diacriticals. At the same time there were some bytes such as F5 that are never valid anywhere in a UTF-8 file. So, I don’t understand how it can be concluded that it’s a UTF-8 file rather than an ANSEL file. What am I missing?

It would be interesting to see if a user can add their own encoding to Xojo, but since there is a steady move away from special purpose encodings towards Unicode, I question whether it’s worthwhile to expend the effort. For a one off project, I would be inclined just to read the file as a binary stream and do a direct translation to Unicode. The translation is not difficult from a programming point of view. Going byte by byte, there are only three cases:

  1. Byte value is <128 – no translation required;
  2. Byte value is in range 161…198 – simple direct translation from input byte to corresponding Unicode character based on a small lookup table;
  3. Byte value is >223 – These are non spacing diacriticals that prefix an upcoming character. So, save the byte, and continue reading and saving diacritical bytes until encountering a byte <128. This combination of character byte plus one or more preceding diacritical bytes will uniquely correspond to one Unicode character, so look it up and replace the byte combination with that character.

The third case is the most work, but only because it requires a large lookup table. However, the work to create the lookups has already been done (and publicly posted) by at least two different developers, and those lookup tables could be machine converted into Xojo code without much effort.

I tried it this way. Read via TextInputStream and do a replace for all Character (Combinations). This works only for the replacements within the loop. The commented replacements after the loop would produce some error replacements. The result would be the same, if you do those replacements before the loop. This work ok for small file. But for large files, it’s really slow and as I said, it does not replace all letters well.

[code]Using Xojo.Core
Using Xojo.IO

Dim inputFile As FolderItem = SpecialFolder.Documents.Child(“ANSEL.ged”)

Try
Dim input As TextInputStream
input = TextInputStream.Open(inputFile, TextEncoding.ASCII)

Dim conv As Text = input.ReadAll
Dim letter As Text

’ A-Z and a-z
for i As Integer = &h41 To &h7A

letter = Text.FromUnicodeCodepoint(i)

' E0 (Unicode: hook above, 0309) / low rising tone mark
conv = conv.ReplaceAll(&uE0 + letter,  letter + &u0309, Text.CompareCaseSensitive)
' E1 (Unicode: grave, 0300) / grave accent
conv = conv.ReplaceAll(&uE1 + letter,  letter + &u0300, Text.CompareCaseSensitive)
' E2 (Unicode: acute, 0301) / acute accent
conv = conv.ReplaceAll(&uE2 + letter,  letter + &u0301, Text.CompareCaseSensitive)
' E3 (Unicode: circumflex, 0302) / circumflex accent
conv = conv.ReplaceAll(&uE3 + letter,  letter + &u0302, Text.CompareCaseSensitive)
' E4 (Unicode: tilde, 0303) / tilde
conv = conv.ReplaceAll(&uE4 + letter,  letter + &u0303, Text.CompareCaseSensitive)
' E5 (Unicode: macron, 0304) / macron
conv = conv.ReplaceAll(&uE5 + letter,  letter + &u0304, Text.CompareCaseSensitive)
' E6 (Unicode: breve, 0306) / breve
conv = conv.ReplaceAll(&uE6 + letter,  letter + &u0306, Text.CompareCaseSensitive)
' E7 (Unicode: dot above, 0307) / dot above
conv = conv.ReplaceAll(&uE7 + letter,  letter + &u0307, Text.CompareCaseSensitive)
' E8 (Unicode: diaeresis, 0308) / umlaut (dieresis)
conv = conv.ReplaceAll(&uE8 + letter,  letter + &u0308, Text.CompareCaseSensitive)
' E9 (Unicode: caron, 030C) / hacek
conv = conv.ReplaceAll(&uE9 + letter,  letter + &u030C, Text.CompareCaseSensitive)

' EA (Unicode: ring above, 030A) / circle above (angstrom)
conv = conv.ReplaceAll(&uEA + letter,  letter + &u030A, Text.CompareCaseSensitive)
' EB (Unicode: ligature left half, FE20) / ligature, left half
conv = conv.ReplaceAll(&uEB + letter,  letter + &uFE20, Text.CompareCaseSensitive)
' EC (Unicode: ligature right half, FE21) / ligature, right half
conv = conv.ReplaceAll(&uEC + letter,  letter + &uFE21, Text.CompareCaseSensitive)
' ED (Unicode: comma above right, 0315) / high comma, off center
conv = conv.ReplaceAll(&uED + letter,  letter + &u0315, Text.CompareCaseSensitive)
' EE (Unicode: double acute, 030B) / double acute accent
conv = conv.ReplaceAll(&uEE + letter,  letter + &u030B, Text.CompareCaseSensitive)
' EF (Unicode: candrabindu, 0310) / candrabindu
conv = conv.ReplaceAll(&uEF + letter,  letter + &u0310, Text.CompareCaseSensitive)

' F0 (Unicode: cedilla, 0327) / cedilla
conv = conv.ReplaceAll(&uF0 + letter,  letter + &u0327, Text.CompareCaseSensitive)
' F1 (Unicode: ogonek, 0328) / right hook
conv = conv.ReplaceAll(&uF1 + letter,  letter + &u0328, Text.CompareCaseSensitive)
' F2 (Unicode: dot below, 0323) / dot below
conv = conv.ReplaceAll(&uF2 + letter,  letter + &u0323, Text.CompareCaseSensitive)
' F3 (Unicode: diaeresis below, 0324) / double dot below
conv = conv.ReplaceAll(&uF3 + letter,  letter + &u0324, Text.CompareCaseSensitive)
' F4 (Unicode: ring below, 0325) / circle below
conv = conv.ReplaceAll(&uF4 + letter,  letter + &u0325, Text.CompareCaseSensitive)
' F5 (Unicode: double low line, 0333) / double underscore
conv = conv.ReplaceAll(&uF5 + letter,  letter + &u0333, Text.CompareCaseSensitive)
' F6 (Unicode: line below, 0332) / underscore
conv = conv.ReplaceAll(&uF6 + letter,  letter + &u0332, Text.CompareCaseSensitive)
' F7 (Unicode: comma below, 0326) / left hook
conv = conv.ReplaceAll(&uF7 + letter,  letter + &u0326, Text.CompareCaseSensitive)
' F8 (Unicode: left half ring below, 031C) / right cedilla
conv = conv.ReplaceAll(&uF8 + letter,  letter + &u031C, Text.CompareCaseSensitive)
' F9 (Unicode: breve below, 032E) / half circle below
conv = conv.ReplaceAll(&uF9 + letter,  letter + &u032E, Text.CompareCaseSensitive)

' FA (Unicode: double tilde left half, FE22) / double tilde, left half
conv = conv.ReplaceAll(&uFA + letter,  letter + &uFE22, Text.CompareCaseSensitive)
' FB (Unicode: double tilde right half, FE23) / double tilde, right half
conv = conv.ReplaceAll(&uFB + letter,  letter + &uFE23, Text.CompareCaseSensitive)
' FE (Unicode: comma above, 0313) / high comma, centered
conv = conv.ReplaceAll(&uFE + letter,  letter + &u0313, Text.CompareCaseSensitive)

Next

’ conv = conv.ReplaceAll(&uA1, &u0141)
’ conv = conv.ReplaceAll(&uA2, &u00D8)
’ conv = conv.ReplaceAll(&uA3, &u0110)
’ conv = conv.ReplaceAll(&uA4, &u00DE)
’ conv = conv.ReplaceAll(&uA5, &u00C6)
’ conv = conv.ReplaceAll(&uA6, &u0152)
’ conv = conv.ReplaceAll(&uA7, &u02B9)
’ conv = conv.ReplaceAll(&uA8, &u00B7)
’ conv = conv.ReplaceAll(&uA9, &u266D)

’ conv = conv.ReplaceAll(&uAA, &u00AE) ’ ®
’ conv = conv.ReplaceAll(&uAB, &u00B1)
’ conv = conv.ReplaceAll(&uAC, &u01A0)
’ conv = conv.ReplaceAll(&uAD, &u01AF)

’ conv = conv.ReplaceAll(&uAE, &u02BC) ’ Part of ASCII
’ conv = conv.ReplaceAll(&uB0, &u02BB) ’ Part of ASCII
’ conv = conv.ReplaceAll(&uB1, &u0142)
’ conv = conv.ReplaceAll(&uB2, &u00F8)
’ conv = conv.ReplaceAll(&uB9, &u00A3)
’ conv = conv.ReplaceAll(&uBA, &u00F0)

’ conv = conv.ReplaceAll(&uC2, &u2117)
’ conv = conv.ReplaceAll(&uC3, &u00A9)
’ conv = conv.ReplaceAll(&uC4, &u266F)
’ conv = conv.ReplaceAll(&uC5, &u00BF)
’ conv = conv.ReplaceAll(&uC6, &u00A1)
’ conv = conv.ReplaceAll(&uCF, &u00DF)

TextArea1.Text = conv

Catch e As IOException
MsgBox "File IO Error: " + e.Reason
End Try[/code]

You are right. I can understand your input. But if you have really large Files, how to handle? I don’t wanna modify the original file and I don’t wanna create a copy of this file at the computer.

Could you give a simple, short example of looping through each individual byte of binary files? This would also be interesting, for example, to replace all EndOfLines (CR, LF and CRLF) with &uA.

Apparently I had too much time on my hands.

[code]Public Sub ANSELtoUnicode()
Dim diacriticals As String = “”
Dim ANSELcodePoint As UInt8
Dim UnicodeCodePoint As String
dim input As BinaryStream
dim myFile As FolderItem
'charset2 is the set of ANSEL accented characters 161…207
dim charSet2() as string = array(_
&u0141,&u00D8,&u0110,&u00DE,&u00C6,&u0152,&u01B9,&u00B7,_
&u266D,&u00AE,&u00B1,&u01A0,&u01AF,&u01BC,&uFFFD,&u02BB,_
&u0142,&u00F8,&u0111,&u00FE,&u00E6,&u0153,&u02BA,&u0131,_
&u00A3,&u00F0,&uFFFD,&u01A1,&u01B0,&u25A1,&u25A0,&u00B0,_
&u2113,&u2117,&u00A9,&u266F,&u00BF,&u00A1,&uFFFD,&uFFFD,_
&uFFFD,&uFFFD,&uFFFD,&uFFFD,&u0065,&u006F,&u00DF)
'charset3 is the set of all possible combinations of
'ANSEL combining diacriticals and final character
'The following data was taken from heiner-eichmann.de/gedcom/unicomb.out
'and then machine converted. The format of each element is as follows:
'The first 4 hex digits are the Unicode codepoint output value.
'The remaining hex digit pairs are the ANSEL diacritical prefixes
'and the base character, which make up the dictionary key.
dim charSet3pairs() as string = array(_
“1EA2E041”,“1EBAE045”,“1EC8E049”,“1ECEE04F”,“1EE6E055”,“1EF6E059”,“1EA3E061”,“1EBBE065”,“1EC9E069”,“1ECFE06F”,_
“1EE7E075”,“1EF7E079”,“00C0E141”,“00C8E145”,“00CCE149”,“00D2E14F”,“00D9E155”,“1E80E157”,“1EF2E159”,_
“00E0E161”,“00E8E165”,“00ECE169”,“00F2E16F”,“00F9E175”,“1E81E177”,“1EF3E179”,“00C1E241”,“0106E243”,_
“00C9E245”,“01F4E247”,“00CDE249”,“1E30E24B”,“0139E24C”,“1E3EE24D”,“0143E24E”,“00D3E24F”,“1E54E250”,_
“0154E252”,“015AE253”,“00DAE255”,“1E82E257”,“00DDE259”,“0179E25A”,“00E1E261”,“0107E263”,“00E9E265”,_
“01F5E267”,“00EDE269”,“1E31E26B”,“013AE26C”,“1E3FE26D”,“0144E26E”,“00F3E26F”,“1E55E270”,“0155E272”,_
“015BE273”,“00FAE275”,“1E83E277”,“00FDE279”,“017AE27A”,“01FCE2C6”,“01FDE2E6”,“1E64E2E753”,“1E65E2E773”,_
“00C2E341”,“0108E343”,“00CAE345”,“011CE347”,“0124E348”,“00CEE349”,“0134E34A”,“00D4E34F”,“015CE353”,_
“00DBE355”,“0174E357”,“0176E359”,“1E90E35A”,“00E2E361”,“0109E363”,“00EAE365”,“011DE367”,“0125E368”,_
“00EEE369”,“0135E36A”,“00F4E36F”,“015DE373”,“00FBE375”,“0175E377”,“0177E379”,“1E91E37A”,“1EA8E3E041”,_
“1EC2E3E045”,“1ED4E3E04F”,“1EA9E3E061”,“1EC3E3E065”,“1ED5E3E06F”,“1EA6E3E141”,“1EC0E3E145”,“1ED2E3E14F”,_
“1EA7E3E161”,“1EC1E3E165”,“1ED3E3E16F”,“1EA4E3E241”,“1EBEE3E245”,“1ED0E3E24F”,“1EA5E3E261”,“1EBFE3E265”,_
“1ED1E3E26F”,“1EAAE3E441”,“1EC4E3E445”,“1ED6E3E44F”,“1EABE3E461”,“1EC5E3E465”,“1ED7E3E46F”,“1EACE3F241”,_
“1EC6E3F245”,“1ED8E3F24F”,“1EADE3F261”,“1EC7E3F265”,“1ED9E3F26F”,“00C3E441”,“1EBCE445”,“0128E449”,_
“00D1E44E”,“00D5E44F”,“0168E455”,“1E7CE456”,“1EF8E459”,“00E3E461”,“1EBDE465”,“0129E469”,“00F1E46E”,_
“00F5E46F”,“0169E475”,“1E7DE476”,“1EF9E479”,“1E4CE4E24F”,“1E78E4E255”,“1E4DE4E26F”,“1E79E4E275”,“1E4EE4E84F”,_
“1E4FE4E86F”,“0100E541”,“0112E545”,“1E20E547”,“012AE549”,“014CE54F”,“016AE555”,“0101E561”,“0113E565”,_
“1E21E567”,“012BE569”,“014DE56F”,“016BE575”,“01E2E5C6”,“01E3E5E6”,“1E14E5E145”,“1E50E5E14F”,“1E15E5E165”,_
“1E51E5E16F”,“1E16E5E245”,“1E52E5E24F”,“1E17E5E265”,“1E53E5E26F”,“1E7AE5E855”,“1E7BE5E875”,“0102E641”,_
“0114E645”,“011EE647”,“012CE649”,“014EE64F”,“016CE655”,“0103E661”,“0115E665”,“011FE667”,“012DE669”,_
“014FE66F”,“016DE675”,“1EB2E6E041”,“1EB3E6E061”,“1EB0E6E141”,“1EB1E6E161”,“1EAEE6E241”,“1EAFE6E261”,_
“1EB4E6E441”,“1EB5E6E461”,“1EB6E6F241”,“1EB7E6F261”,“1E02E742”,“010AE743”,“1E0AE744”,“0116E745”,“1E1EE746”,_
“0120E747”,“1E22E748”,“0130E749”,“1E40E74D”,“1E44E74E”,“1E56E750”,“1E58E752”,“1E60E753”,“1E6AE754”,_
“1E86E757”,“1E8AE758”,“1E8EE759”,“017BE75A”,“1E03E762”,“010BE763”,“1E0BE764”,“0117E765”,“1E1FE766”,_
“0121E767”,“1E23E768”,“1E41E76D”,“1E45E76E”,“1E57E770”,“1E59E772”,“1E61E773”,“1E6BE774”,“1E87E777”,_
“1E8BE778”,“1E8FE779”,“017CE77A”,“1E9BE77F”,“01E0E7E541”,“01E1E7E561”,“00C4E841”,“00CBE845”,“1E26E848”,_
“00CFE849”,“00D6E84F”,“00DCE855”,“1E84E857”,“1E8CE858”,“0178E859”,“00E4E861”,“00EBE865”,“1E27E868”,_
“00EFE869”,“00F6E86F”,“1E97E874”,“00FCE875”,“1E85E877”,“1E8DE878”,“00FFE879”,“01DBE8E155”,“01DCE8E175”,_
“1E2EE8E249”,“01D7E8E255”,“1E2FE8E269”,“01D8E8E275”,“01DEE8E541”,“01D5E8E555”,“01DFE8E561”,“01D6E8E575”,_
“01D9E8E955”,“01DAE8E975”,“01CDE941”,“010CE943”,“010EE944”,“011AE945”,“01E6E947”,“01CFE949”,“01E8E94B”,_
“013DE94C”,“0147E94E”,“01D1E94F”,“0158E952”,“0160E953”,“0164E954”,“01D3E955”,“017DE95A”,“01CEE961”,_
“010DE963”,“010FE964”,“011BE965”,“01E7E967”,“01D0E969”,“01F0E96A”,“01E9E96B”,“013EE96C”,“0148E96E”,_
“01D2E96F”,“0159E972”,“0161E973”,“0165E974”,“01D4E975”,“017EE97A”,“01EEE9B7”,“01C4E9F1”,“01C6E9F3”,_
“01EFE992”,“1E66E9E753”,“1E67E9E773”,“00C5EA41”,“016EEA55”,“00E5EA61”,“016FEA75”,“1E98EA77”,“1E99EA79”,_
“01FAEAE241”,“01FBEAE261”,“0150EE4F”,“0170EE55”,“0151EE6F”,“0171EE75”,“00C7F043”,“1E10F044”,“0122F047”,_
“1E28F048”,“0136F04B”,“013BF04C”,“0145F04E”,“0156F052”,“015EF053”,“0162F054”,“00E7F063”,“1E11F064”,_
“0123F067”,“1E29F068”,“0137F06B”,“013CF06C”,“0146F06E”,“0157F072”,“015FF073”,“0163F074”,“1E08F0E243”,_
“1E09F0E263”,“1E1CF0E645”,“1E1DF0E665”,“0104F141”,“0118F145”,“012EF149”,“01EAF14F”,“0172F155”,“0105F161”,_
“0119F165”,“012FF169”,“01EBF16F”,“0173F175”,“01ECF1E54F”,“01EDF1E56F”,“1EA0F241”,“1E04F242”,“1E0CF244”,_
“1EB8F245”,“1E24F248”,“1ECAF249”,“1E32F24B”,“1E36F24C”,“1E42F24D”,“1E46F24E”,“1ECCF24F”,“1E5AF252”,_
“1E62F253”,“1E6CF254”,“1EE4F255”,“1E7EF256”,“1E88F257”,“1EF4F259”,“1E92F25A”,“1EA1F261”,“1E05F262”,_
“1E0DF264”,“1EB9F265”,“1E25F268”,“1ECBF269”,“1E33F26B”,“1E37F26C”,“1E43F26D”,“1E47F26E”,“1ECDF26F”,_
“1E5BF272”,“1E63F273”,“1E6DF274”,“1EE5F275”,“1E7FF276”,“1E89F277”,“1EF5F279”,“1E93F27A”,“1E38F2E54C”,_
“1E5CF2E552”,“1E39F2E56C”,“1E5DF2E572”,“1E68F2E753”,“1E69F2E773”,“1E72F355”,“1E73F375”,“1E00F441”,_
“1E01F461”,“1E2AF948”,“1E2BF968”)

dim charSet3 As new Dictionary
'Build charSet3 transliteration Dictionary
for i as Integer = 0 to UBound(charSet3pairs)
'Get the Unicode codepoint output value
dim cs3value As String = chr(val("&h"+left(charSet3pairs(i),4)))
'Get the ANSEL diacritical prefixes and the base character, which make up the key
dim cs3key As String = mid(charSet3pairs(i),5)
charSet3.Value(cs3key)=cs3value
next

//The program code above this point should probably be placed in a separate
//initialization routine because it doesn’t need to run each time a file is read.

'Get an ANSEL encoded input file and open it
myFile=GetOpenFolderItem("")
'Open file as a read only BinaryStream
input=BinaryStream.Open(myFile,False)

'Now process the input byte by byte
while not input.EOF
ANSELcodePoint = input.ReadUInt8
if ANSELcodePoint<128 Then
'charSet1 - This range of characters is the same in all encodings
if len(diacriticals)>0 then
'There are diacriticals to prefix to this character
diacriticals=diacriticals+right(“00”+hex(ANSELcodePoint),2)
if charSet3.HasKey(diacriticals) then
UnicodeCodePoint=charSet3.Value(diacriticals)
else
'Not found, so go with the unaccented character
UnicodeCodePoint=chr(ANSELcodePoint)
end if
diacriticals=""
else
'No diacriticals, so the character needs no translation
UnicodeCodePoint=chr(ANSELcodePoint)
end if
elseif ANSELcodePoint<161 Then
'This range is Invalid, so convert to Unicode Replacement Character
UnicodeCodePoint=&uFFFD
elseif ANSELcodePoint<208 Then
'This is the ANSEL set of accented characters
UnicodeCodePoint=charSet2(ANSELcodePoint-161)
elseif ANSELcodePoint<224 Then
'This range is Invalid, so convert to Unicode Replacement Character
UnicodeCodePoint=&uFFFD
else
'The ANSEL codepoint is a combining diacritical, so append it to the diacritical string.
diacriticals=diacriticals+right(“00”+hex(ANSELcodePoint),2)
end if
'At this point the input ANSEL character has been converted to Unicode
'So we send it out to be handled by another routine
'For this example we simply display it in a TextArea
myTextArea.AppendText UnicodeCodePoint
wend
End Sub
[/code]