View Single Post
  #3 (permalink)  
Old 04-23-2008
bernard's Avatar
bernard bernard is offline
ZeroC Staff
 
Name: Bernard Normier
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Palm Beach Gardens, FL
Posts: 761
Hi Christian,

Quote:
which would, however, generate a UnicodeEncodeError if a client sends a string with characters that are not representable in the server's locale, so more effort is needed to have robust printing in the server (the best I've been able to come up with is
Code:
print s.decode('utf8').encode(locale.getpreferredencoding(), 'replace')
which is not that trivial any more...).
We provide 3 string converter implementations in Ice 3.3:
  • UnicodeWstringConverter
    Converts UTF-16 or UTF-32 wstrings to/from UTF-8 sequences. By default, it's "lenient", i.e. some malformed input sequences are transformed into the Unicode replacement character. In 3.3.0, you'll be able to get the strict behavior as well (no replacement character).
  • IconvStringConverter
    Converts narrow or wstrings from the specified iconv encoding to/from UTF-8. It's always strict, i.e. if there is no mapping, you get an exception.
  • WindowsStringConverter
    Converts narrow strings encoded in a given code-page to/from UTF-8. Like with the Iconv converter, if there is no mapping, you get an exception.

So if you want to use a replacement character, you'll probably need to write your own C++ string converter.

Cheers,
Bernard
__________________
Bernard Normier
ZeroC, Inc.
Reply With Quote