[I18n-sig] Passing unicode strings to file system calls

Martin v. Loewis martin@v.loewis.de
19 Jul 2002 18:14:27 +0200


"Bleyer, Michael" <MBleyer@DEFiNiENS.com> writes:

> I'd like a function that returns a list of legal encodings for that string,
> e.g.
> myLegalEncodingList = locale.getLegalEncodings(myUString)
> 
> The list would be something like
> ['cp1250','latin-1','utf8'] etc.
> for example.

What has the locale to do with that? The set of encodings to encode a
particular Unicode character is independent of the locale...

> Now if I have a unicode string I would try to convert it to the system
> default encoding first and if that doesn't work, I would like to give the
> user some feedback and maybe some choice (from a list of legal encodings)
> over which encoding to use instead.
> 
> Does that make sense?

Yes, that's a good approach. However, I'd recommend to use the
locale's encoding instead of the system default encoding, as reported
by nl_langinfo(CODEPAGE).

As for computing the list of possible encodings: I'm not sure what the
best data format for that would be.

Regards,
Martin