Subject: Re: [boost] Silly Boost.Locale default narrow stringencodinginWindows
From: Yakov Galka (ybungalobill_at_[hidden])
Date: 2011-10-28 07:31:40
On Fri, Oct 28, 2011 at 13:17, Alf P. Steinbach <
> On 28.10.2011 12:36, Yakov Galka wrote:
>> On Fri, Oct 28, 2011 at 04:23, Alf P. Steinbach<
>> alf.p.steinbach+usenet_at_gmail.**com <alf.p.steinbach%2Busenet_at_[hidden]>>
>> On 27.10.2011 23:56, Peter Dimov wrote:
>>>> The advantage of using UTF-8 is that, apart from the border layer that
>>>> calls the OS (and that needs to be ported either way), the rest of the
>>>> code is happily char-based.
>>> I would be happy to learn this.
>>> How do I make the following program work with Visual C++ in Windows,
>>> narrow character string?
>>> #include<fcntl.h> // _O_U8TEXT
>>> #include<io.h> // _setmode, _fileno
>>> int main()
>>> //SetConsoleOutputCP( 65001 );
>>> //_setmode( _fileno( stdout ), _O_U8TEXT );
>>> printf( "BlÃ¥bÃ¦rsyltetÃ¸y! æ¥æ¬å½ ÐºÐ¾ÑÐºÐ°!\n" );
>> How will you make this program portable?
> Well, that was *my* question.
> The claim that this minimal "Hello, world!" program puts to the point, is
> that "the rest of the [UTF-8 based] code is happily char-based".
> Apparently that is not so.
My point is that you cannot talk about things without comparison.
> The out-commented code is from my random efforts to Make It Work(TM).
>>> It refused.
>> This is because windows narrow-chars can't be UTF-8. You could make it
>> portable by:
>> int main()
>> boost::printf("BlÃ¥bÃ¦rsyltetÃ¸y! æ¥æ¬å½ ÐºÐ¾ÑÐºÐ°!\n");
> Thanks, TIL boost::printf.
> The idea of UTF-8 as a universal encoding seems now to be to use some
> workaround such as boost::printf for each and every case where it turns out
> that it doesn't work portably.
You pull things out of context. We should COMPARE the UTF-8 approach to the
wide-char on windows narrow-char on non-windows approach. Your approach
involves using your own printf just as well:
#include "u/stdio_h.h" // u::CodingValue, u::printf, U
printf(U("BlÃ¥bÃ¦rsyltetÃ¸y! æ¥æ¬å½ ÐºÐ¾ÑÐºÐ°!\n")); // ADL?
u::printf(U("BlÃ¥bÃ¦rsyltetÃ¸y! æ¥æ¬å½ ÐºÐ¾ÑÐºÐ°!\n")); // or not ADL? depends on what
exactly U is.
but anyway you have to do O(N) work to wrap the N library functions you use.
Your approach is no way better.
>> You judge from a non-portable coed point-of-view. How about:
>> #include <cstdio>
>> #include "gtkext/message_box.h" // for gtkext::message_box
>> int main()
>> char buffer;
>> sprintf(buffer, "The answer is %d!", 6*7);
>> gtkext::message_box(buffer, "This is a title!",
>> And unlike your code, it's magically portable! (thanks to gtk using UTF-8
> Aha. When you use a library L that translates in platform-specific ways
> to/from UTF-8 for you, then UTF-8 is magically portable. For use of L.
> However, try to pass a `main` argument over to gtkext::message_box.
See the argv explanation in
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk