UnicodeConverter toUTF8 not working?

Please post support and help requests here.
deisenhut
Posts: 11
Joined: 30 Jul 2013, 00:11

UnicodeConverter toUTF8 not working?

Postby deisenhut » 13 Aug 2013, 23:23

It doesn't appear as if UnicodeConverter::ToUTF8() function is working. What am I doing wrong here?

I am building the following test function on Win32 (Windows 7 x64) with Unicode enabled.

Code: Select all

#include <iostream>
#include "Poco/UnicodeConverter.h"

using namespace std ;

void TestFunction()
{
   wstring input(L"Test String");
   string output;
   Poco::UnicodeConverter::toUTF8(input, output);
   cout << "Output: " << output << endl;
}


The output for this function is

Code: Select all

Output:


What am I missing? wstring on Win32 should be UTF16. UnicodeConverter should be converting between UTF16 and UTF8. The second parameter of toUTF8() is a reference parameter, so output should be getting modified.

Under the hood, UnicodeConverter is using UTF16Encoding object with TextConverter to issue the following command:

Code: Select all

   converter.convert(utf16String.data(), (int) utf16String.length()*sizeof(wchar_t), utf8String);


Then the TextConverter loops through the wchar_t array of the source. My next step would be to rebuild Poco for Debug so that I can step through this function to figure out what is wrong. But hopefully what I'm doing wrong is obvious to someone else here.

Thanks,
Dan

deisenhut
Posts: 11
Joined: 30 Jul 2013, 00:11

Re: UnicodeConverter toUTF8 not working?

Postby deisenhut » 14 Aug 2013, 16:40

Here's some useful information on this problem. It only happens when building for Debug! If I build for "Release", it works as expected.

I also found something else behaving strangely when building for Debug. Poco::File doesn't work right. See the following test code:

Code: Select all

   string sourceFile("SomeTestFile.txt");
   cout << "Source: " << sourceFile << endl;
   try {
      Poco::File sourceFileObj(sourceFile);
   } catch (Poco::Exception ex) {
      cout << "Exception Caught: " << ex.message() << endl;
   }
   cout << "Completed." << endl;


This only outputs:

Code: Select all

Source: SomeTestFile.txt


The "Completed." at the end is not outputted! But only if building for Debug. Works fine for Release. Looking in the Poco source, I do not currently understand why this is happening.

Note: Poco was built for Release and was not rebuilt when switching between Debug and Release above. Both are linking to the same Poco library. Is this causing a problem?

Thanks,
Dan

guenter
Posts: 1191
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: UnicodeConverter toUTF8 not working?

Postby guenter » 14 Aug 2013, 17:07

You should never mix debug and release builds. When building your application for release, also use the POCO release build. Same for debug. Otherwise a lot of bad things may happen. For example, debug and release builds on Windows may use different heap layout (due to error/leak detection) and even layout of C++ standard library classes may be different, leading to strange things when you start to mix them.

deisenhut
Posts: 11
Joined: 30 Jul 2013, 00:11

Re: UnicodeConverter toUTF8 not working?

Postby deisenhut » 14 Aug 2013, 17:17

Thanks. I'll have to build the debug version for Poco and check them in as well, then modify all our project files to use the debug version for linking.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests

cron