Am 14.09.2012 17:48, schrieb Leandro Santiago: > Hello. > > I'm having some problems with utf-8 and cxxtools. Hi Leandro,
if you look at http://www.utf8-chartable.de/ you can find the unicode codepoint for ç, which is 0xe7. When encoded as json it is \u00e7. The character ã has the unicode codepoint 0xe3 or in json \u00e3. This is exactly, what the json serializer makes out of it. So I see no problems in cxxtools. Utf8 encodes the 32 bit codepoint into a byte stream. 0xe7 is encoded in utf8 as \xc3a7. I know, it is irritating but I'm quite sure, it is correct in cxxtools. Btw: since cxxtools::Utf8Codec::decode is a static method, you can call it without creating an instance like this: cxxtools::String wname(cxxtools::Utf8Codec::decode(name)); The best way to handle unicode is to hold text data in cxxtools::String instead of std::string. It is not quite clean to use std::string to held utf8 data. Think e.g. about std::string::size, which returns the number of bytes needed to encode the text in utf8 instead of the number of characters in the string. But I must confess, that I couldn't even convince my own colleges to do it. In our applications we also use utf8 encoded data in std::string. It have lead to problems some times but we always found workarounds for it. If you serialize custom objects, you may want to do the encoding and decoding in the serializer and deserializer operators. E.g. we may have a structure: struct Foo { std::string name; }; which holds the name as utf8. The serializer operator will look like that: void operator<<= (cxxtools::SerializationInfo& si, const Foo& foo) { si.typeName("Foo"); si.addMember("name") <<= cxxtools::Utf8Codec::decode(foo.name); } and the deserializer operator: void operator>>= (const cxxtools::SerializationInfo& si, Foo& foo) { cxxtools::String s; si.getMember("name") >>= s; foo.name = cxxtools::Utf8Codec::encode(s); } Then you can serialize and deserialize Foo objects to json and back to Foo without hassle. Tommi ------------------------------------------------------------------------------ Got visibility? Most devs has no idea what their production app looks like. Find out how fast your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219671;13503038;y? http://info.appdynamics.com/FreeJavaPerformanceDownload.html _______________________________________________ Tntnet-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tntnet-general
