strange result for string <=> wstring <=> utf8 convert under windows

Everything related to libfilezilla

Moderator: Project members

Post Reply
Message
Author
twu2
425 Can't open data connection
Posts: 45
Joined: 2005-02-26 16:54

strange result for string <=> wstring <=> utf8 convert under windows

#1 Post by twu2 » 2016-10-03 15:54

Build Environment: Debian sid x86_64
Compile: x86_64-w64-mingw32-gcc 6.1.1 20160815 (current version in Debian sid)
Target OS: Windows 10 Pro (Tranditional Chinese)

Test code:

Code: Select all

        std::wstring ws = L"test";
        printf("ws length = %d\n", ws.size());
        // => ws length = 4
        std::string s1 = fz::to_utf8(ws);
        printf("s1 length = %d\n", s1.size());
        // => s1 length = 4
        std::string s2 = fz::to_string(ws);
        printf("s2 length = %d\n", s2.size());
        // => s2 length = 0
        if (s1 == s2)
            printf("s1 == s2\n");
        else
            printf("s1 != s2\n");
        // => s1 != s2
        std::wstring ws1 = fz::to_wstring(s1);
        printf("ws1 length = %d\n", ws1.size());
        // => ws1 length = 0
        std::wstring ws2 = fz::to_wstring(s2);
        // => ws2 length = 0
        if (ws1 == ws2)
            printf("ws1 == ws2\n");
        else
            printf("ws1 != ws2\n");
        // => ws1 == ws2
        std::wstring ws3 = fz::to_wstring_from_utf8(s1);
        printf("ws3 length = %d\n", ws3.size());
        // => ws3 length = 4
        std::wstring ws4 = fz::to_wstring_from_utf8(s2);
        printf("ws4 length = %d\n", ws4.size());
        // => ws4 length = 0
        if (ws3 == ws4)
            printf("ws3 == ws4\n");
        else
            printf("ws3 != ws4\n");
        // => ws3 != ws4
        if (ws == ws3)
            printf("ws == ws3\n");
        else
            printf("ws != ws3\n");
        // => ws == ws3
Work fine:
fz::to_utf8() convert from wstring to utf-8 string
fz::to_wstring_from_utf8() convert from utf-8 string to wstring

Not work (it should work for English string):
fz::to_string() convert from wstring to string
fz::to_wstring() convert from string to wstring

User avatar
botg
Site Admin
Posts: 31572
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

Re: strange result for string <=> wstring <=> utf8 convert under windows

#2 Post by botg » 2016-10-03 16:03

See the red warning at https://wiki.filezilla-project.org/Cros ... nvironment

If you have wine-binfmt installed and configured, you can run 'make check' when cross-compiling to run libfilezilla's test suite. It will fail if the MinGW runtime hasn't been patched.

twu2
425 Can't open data connection
Posts: 45
Joined: 2005-02-26 16:54

Re: strange result for string <=> wstring <=> utf8 convert under windows

#3 Post by twu2 » 2016-10-05 14:31

I apply the patch, it work fine now. Thanks.

Post Reply