trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: March 2016

Re: [trinity-devel] Re: Re: TQString::fromUtf8 vs TQString::fromLatin1 [possible bug in parseVCard]

From: Fat-Zer <fatzer2@...>
Date: Sat, 26 Mar 2016 17:59:38 +0300
2016-03-26 11:42 GMT+03:00 deloptes <deloptes@...>:
> Hi,
> this is also how I understand the ascii(), but do you have explanation how I
> then see the ��� (utf?). The above was just an experiment.
> For the code I wrote I solved the problem by passing the c_str() to
> parseVCard. This passes char array and does not care about the content that
> much (my understanding)
>
> regards
>
Yes, It seems you are right there is a bug, haven't tried myself, but
should do the trick:

diff --git a/tdeabc/vcardparser/vcardparser.cpp
b/tdeabc/vcardparser/vcardparser.cpp
index 7ac07ce..db33263 100644
--- a/tdeabc/vcardparser/vcardparser.cpp
+++ b/tdeabc/vcardparser/vcardparser.cpp
@@ -152,7 +152,7 @@ VCard::List VCardParser::parseVCards( const TQString& text )
             KCodecs::quotedPrintableDecode( input, output );
           }
         } else {
-          output = TQCString(value.latin1());
+          output = TQCString(value.utf8());
         }

         if ( params.findIndex( "charset" ) != -1 ) { // have to
convert the data

Note that VCardParser::parseVCards() is generally encoding-unsafe...


PS, some notes about your code:
> std::string data_str(data.utf8(),data.utf8().length());
>        SE_LOG_DEBUG(getDisplayName(), "TDE addressbook ENTRY AFTER
>\n%s\n",data_str.c_str() );
Note that there is no need here to create here an intermediate
std::string, next code should work by itself:

std::string data_str(data.utf8(),data.utf8().length());
SE_LOG_DEBUG(getDisplayName(), "TDE addressbook ENTRY
AFTER\n%s\n",data.utf8() );

if not, just cast it to (const char *).

>TDEABC::Addressee addressee = converter.parseVCard(item.c_str());
This is an equivalent to fromLatin1(), so it will work only for your locale...

Next tim if you encounter such issues, try to provide a minimal
compiliable test example. That will significantly ease the testing and
understanding what's wrong...