using encodings other than UTF-8 - part 2

Marcin Kuszczak aarti at interia.pl
Sat Oct 6 13:39:06 PDT 2007


Piotr Dworaczyk wrote:

> Hi,
> is there any way to process non ASCII characters in encodings other than
> UTF-8?
> 
> I've asked a similar question some time ago (
>
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=54417)
> about polish national characters, but haven't found any examples since.
> 
> D's very seductive as a better designed and/or C/C++/Java/C# alike
> language.
> As a hobby programmer and CS teacher I already thought about using it as a
> teaching tool,
> but, please understand, the character encoding issues are a no-go.
> 
> To tell the significance of the problem, just imagine, that beside of
> utf-8 (which still isn't very popular),
> there are two major implementations of the polish national characters:
> windows-1250 (cp-1250) and iso-8859-2.
> 
> I already thought about running a conversion to utf-8, before the D
> program's launch, and a conversion from utf-8 to the apropriate encoding,
> but it does make little sense.
> 
> So is there a way, or could there be a possibility to add it in future
> versions of the standard library?
> 
> Thanks for your answers,
> 
> Piotr Dworaczyk
> 


I use something like this for converting from other encodings:

char[] readFile(char[] name) {

        char[] file=cast(char[])std.file.read(name) ~ '\0';
        file=std.windows.charset.fromMBSz(cast(char*)file, 1250);
        return file;
}

and similarly for writing:
        std.windows.charset.toMBSz(content, 1250);      //1250 - polish windows codepage

It seems that it works on windows (and only on windows). But I have to agree
that support for codepages should be much better (e.g. easy detecting
current codepage)...

See for docs: http://www.digitalmars.com/d/phobos/std_windows_charset.html


-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://www.zapytajmnie.com (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------




More information about the Digitalmars-d mailing list