Working with utf
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Jun 14 06:48:50 PDT 2007
Derek Parnell wrote:
> On Thu, 14 Jun 2007 15:13:35 +0200, Simen Haugen wrote:
>
>> "Derek Parnell" <derek at psych.ward> wrote in message
>> news:n1j2izm4a0x5.413sc7jjzk2x.dlg at 40tude.net...
>>> Convert to utf32 (dchar[]) then do your stuff and convert back to latin-1
>>> when you're done. Each dchar[] element is a single character.
>> You're kidding me, right? Then I only have to convert to utf-32 when reading
>> a file, and back to latin-1 when writing. Thats great! (except I have to
>> modify a lot of char[] to dchar[])
>
> dchar[] Y;
> char[] Z;
>
> Y = std.utf.toUTF32(Z);
Except his input is encoded as Latin-1, not UTF-8. Conversion is still
trivial though:
---
auto latin1 = cast(ubyte[]) std.file.read("some_latin-1_file.txt");
dchar[] utf = new dchar[](latin1.length);
for(size_t i = 0; i < latin1.length; i++) {
utf[i] = latin1[i];
}
---
and the other way around.
(The first 256 code points of Unicode are identical to Latin-1)
More information about the Digitalmars-d
mailing list