Author Topic: Last standing unicode problem  (Read 21563 times)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Last standing unicode problem
« on: November 24, 2005, 02:02:40 pm »
Bold title for a topic :)

Well, I 've updated my local wx installation to wx2.6.2/unicode and fixed all minor incompatibilities.
Except for one thing:

Code
int someint;
wxString astr;
wxString anotherstr;

astr << _T("aval"); // ok
astr << anotherstr; // ok
astr << someint; // *not* ok

I can't stream numbers to wxString  :shock:
Anyone else has seen this? Knows a workaround?
The only workaround I found is using wxString::Format() instead of streams but this would mean scanning the entire source tree to find where integers are streamed to wxString and alter the code...
Be patient!
This bug will be fixed soon...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Last standing unicode problem
« Reply #1 on: November 24, 2005, 06:36:08 pm »
a little bit offtopic, but if you already moved to wx262, what happened to the splitpanel position problem? (the splitter position getting forgotten). Is that fixed already?

takeshimiya

  • Guest
Re: Last standing unicode problem
« Reply #2 on: November 24, 2005, 06:52:57 pm »
What happens if you change these defaults?:

// If enabled (1), compiles wxWidgets streams classes
#define wxUSE_STREAMS       1

// Use standard C++ streams if 1. If 0, use wxWin streams implementation only.
#define wxUSE_STD_IOSTREAM  0

// Enable conversion to standard C++ string if 1.
#define wxUSE_STD_STRING  0


The wxWidgets stream classes may have bugs.
« Last Edit: November 24, 2005, 06:58:02 pm by Takeshi Miya »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #3 on: November 24, 2005, 07:49:11 pm »
a little bit offtopic, but if you already moved to wx262, what happened to the splitpanel position problem? (the splitter position getting forgotten). Is that fixed already?

I 've fixed it for the classbrowser since lastweek.
I 'll fix it for open files list too.

What happens if you change these defaults?:

// If enabled (1), compiles wxWidgets streams classes
#define wxUSE_STREAMS 1

// Use standard C++ streams if 1. If 0, use wxWin streams implementation only.
#define wxUSE_STD_IOSTREAM 0

// Enable conversion to standard C++ string if 1.
#define wxUSE_STD_STRING 0


The wxWidgets stream classes may have bugs.

Thanks for the suggestion, but I would like not to tamper with wx settings.
First, because it 'd make the build process more difficult for new users.
Second, because most linux users will use the pre-built wx lib coming with their distro. We should not force them to build wx themselves, not to mention that C::B would never stand a chance to become a part of distros then...

Well, seems like I 'll have to dig through the code and replace those instances with wxString::Format()...
Be patient!
This bug will be fixed soon...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Last standing unicode problem
« Reply #4 on: November 24, 2005, 08:46:45 pm »
wxString::operator <<

wxString& operator <<(int i)
wxString& operator <<(float f)
wxString& operator <<(double d)

These functions work as C++ stream insertion operators: they insert the given value into the string. Precision or format cannot be set using them, you can use Printf for this.

--

Yiannis, mind explaining exactly why you can't use it? It throws a runtime error or what?

takeshimiya

  • Guest
Re: Last standing unicode problem
« Reply #5 on: November 24, 2005, 08:49:58 pm »
Errm, I suggest those settings only to test if it's a wxWidgets bug in the stream classes.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #6 on: November 24, 2005, 09:07:04 pm »
Yiannis, mind explaining exactly why you can't use it? It throws a runtime error or what?

Nope, just it isn't actually added to the string:

Code
wxString astr = "Test";
astr << 5;

astr == "Test", instead of "Test5"...
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: Last standing unicode problem
« Reply #7 on: November 24, 2005, 11:33:09 pm »
how about using the stl streams directly, should be portable ;
ostringstream class (things go into a sting buffer which can be requested at the end of all appending); ostringstream is just like cout, only everything get's into a strring.

But then again, you have to replace stuff, which you wanted to prevent doing in the first place ;-)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Last standing unicode problem
« Reply #8 on: November 24, 2005, 11:53:36 pm »
Yiannis: Mind giving us a particular filename / line no. ?

takeshimiya

  • Guest
Re: Last standing unicode problem
« Reply #9 on: November 25, 2005, 12:15:52 am »
killerbot: that's why I'm saying to test with the STL streams instead of the wx streams. Only to know if it's a bug of wx or not.
#define wxUSE_STD_IOSTREAM  1
#define wxUSE_STD_STRING  1
« Last Edit: November 25, 2005, 12:17:25 am by Takeshi Miya »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #10 on: November 25, 2005, 12:32:29 am »
Yiannis: Mind giving us a particular filename / line no. ?

Sure. Here's the file I noticed the problem:

file: src/plugins/debuggergdb/gdb_commands.h
line: 189

Code
m_Cmd << out << _T(":") << bp->line + 1;
Be patient!
This bug will be fixed soon...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Last standing unicode problem
« Reply #11 on: November 25, 2005, 12:40:30 am »
Quote
m_Cmd << out << _T(":") << bp->line + 1;

Try this:

Code
m_Cmd << out << _T(":") << (bp->line + 1);

Or this:


Code
m_Cmd << out << _T(":");
m_Cmd << (bp->line + 1);

Or this:

Code
(m_Cmd << out << _T(":")) << (bp->line + 1);

And tell us what happens.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #12 on: November 25, 2005, 10:02:51 am »
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Last standing unicode problem
« Reply #13 on: December 02, 2005, 12:19:16 pm »
Just curious, but does this work-around work?:
Code
std::string str;
str << "Hi" << 5;
wxString str_new(_T(str));

Please notice that I've used default std::string for the first one.
(I cannot test it at the moment since I am at work.)

Morten.
« Last Edit: December 02, 2005, 12:22:15 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #14 on: December 02, 2005, 12:56:25 pm »
Just curious, but does this work-around work?:
Code
std::string str;
str << "Hi" << 5;
wxString str_new(_T(str));

Please notice that I've used default std::string for the first one.
(I cannot test it at the moment since I am at work.)

Morten.


Using the STL is not an accepted solution...
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: Last standing unicode problem
« Reply #15 on: December 02, 2005, 01:09:42 pm »
just curious, why is STL not acceptable ??

Not portable with selection ansi/unicode ??

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #16 on: December 02, 2005, 01:36:56 pm »
just curious, why is STL not acceptable ??

Not portable with selection ansi/unicode ??

For starters, STL is not enabled by default in wxWidgets configuration.
And even, if enabled, we 'd have tons of problems with wxWidgets and STL (tried it). Not to mention the unicode issues...

EDIT: don't get me wrong, in my own non-wx projects I use STL all the time. I don't know what I would have done without it ;)
Be patient!
This bug will be fixed soon...

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Last standing unicode problem
« Reply #17 on: December 02, 2005, 01:51:32 pm »
EDIT: don't get me wrong, in my own non-wx projects I use STL all the time. I don't know what I would have done without it ;)
Sorry for the question, but what do you use instead of STL in your wx projects?

Thank you.

Best wishes,
Michael

takeshimiya

  • Guest
Re: Last standing unicode problem
« Reply #18 on: December 02, 2005, 02:21:21 pm »
And I can add: Sorry for the question :), but what are your non-wx projects? Something opensource?

Back on topic:
I've diff-compared the string related code from 2.6.1 and 2.6.2 and found nothing relevant. :?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Last standing unicode problem
« Reply #19 on: December 02, 2005, 02:32:46 pm »
And I can add: Sorry for the question :), but what are your non-wx projects? Something opensource?

Unfortunately, no :)

Back on topic:
I've diff-compared the string related code from 2.6.1 and 2.6.2 and found nothing relevant. :?

Yes, I know. It makes no sense at all...
Be patient!
This bug will be fixed soon...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Last standing unicode problem
« Reply #20 on: December 02, 2005, 04:18:23 pm »
Oh well...  :| I guess there's nothing else we can do.

Offline me22

  • Official tester
  • Multiple posting newcomer
  • ***
  • Posts: 53
    • TA Universe
Re: Last standing unicode problem
« Reply #21 on: December 02, 2005, 04:46:26 pm »
Just curious, but does this work-around work?:
Code
std::string str;
str << "Hi" << 5;
wxString str_new(_T(str));

Please notice that I've used default std::string for the first one.
(I cannot test it at the moment since I am at work.)

Morten.
That wont work because std::string doesn't have formatting -- you'd use a stringstream for that:
Code
std::basic_stringstream<wxChar> ss;
ss << "Hi" << 5;
wxString str_new( ss.str() );
( because iostreams keep all the formatting information in istream and ostream, to avoid excessive duplication )

Note that I do not think this would be a good solution.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Last standing unicode problem
« Reply #22 on: December 03, 2005, 01:22:10 pm »
That wont work because std::string doesn't have formatting [...]
I know about that. This was a copy&paste mistake because I had posted this already in another thread using wxString instead of std::string. But i found out that this had already been tested in this thread...

I was hoping that nobody would realise... :oops: :oops: :oops:

Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

undofen

  • Guest
Re: Last standing unicode problem
« Reply #23 on: December 04, 2005, 03:44:34 am »
I'm not sure if thats so easy to do, but I would really appreciate if anyone could write down a "not nice but working" solution to this, a solution that I could just paste into that place in the file and make codeblocks usable until the right fix is found. I tried to convert that number to a string but I only know the basics of c++ and dont know anything about wx so it didnt work ;-). TIA

andrimar

  • Guest
Re: Last standing unicode problem
« Reply #24 on: December 04, 2005, 04:06:26 am »
We could go the old QT <-> KDE relationship way and wrap our workaround in an extended wxString class. That way we wouldn't have to change wx internals, keeping distro makers and users happy. Just my 2 cents on the matter after reading this thread but no related code. Hope it inspires someone :)

takeshimiya

  • Guest
Re: Last standing unicode problem
« Reply #25 on: December 04, 2005, 05:17:56 am »
I don't know if this helps, but from the wxWiKi:

Converting an integer to wxString

To convert, for example, an integer to a wxString, you can use several methods:

    * wxString mynewstring = wxString::Format("%d", myoldinteger)
    * wxString s; s.Printf("%d", myint);
    * wxString mynewstring = wxString("") << myoldinteger;


If you're going straight into a text control, you can skip the conversion entirely: *textctrl << myint;


undofen

  • Guest
Re: Last standing unicode problem
« Reply #26 on: December 10, 2005, 02:43:12 pm »
using the latest rocket engeeniering and the post above I developed this fix, I suppose its not the best solution, but if someone wants a working debugger with wx-2.6.2 and knows nothing about codeblocks it should be enough:
in /src/plugins/debuggergdb/gdb_commands.h , lines ~ 200
Code
                    if (!m_BP->temporary)
                        m_Cmd << _T("break ");
                    else
                        m_Cmd << _T("tbreak ");
++                  wxString s; s.Printf(_("%d"), m_BP->line + 1);
++                    m_Cmd << out << _T(":") << s;
--                       m_Cmd << out << _T(":") << m_BP->line + 1;
                }

EDIT: the debugger is working now, a pity though it's not highlighting the actual line, nor any other line (breakpoint line, error line)
« Last Edit: December 10, 2005, 02:45:04 pm by undofen »

anonuser

  • Guest
Re: Last standing unicode problem
« Reply #27 on: December 10, 2005, 06:42:39 pm »
There shouldn't be any unicode issue with the STL.

there's wstring and string. wstring being the wide character version which is also capable of doing unicode.
Perhaps there is an issue with wxString?

Offline me22

  • Official tester
  • Multiple posting newcomer
  • ***
  • Posts: 53
    • TA Universe
Re: Last standing unicode problem
« Reply #28 on: December 10, 2005, 08:14:15 pm »
There shouldn't be any unicode issue with the STL.

there's wstring and string. wstring being the wide character version which is also capable of doing unicode.
Perhaps there is an issue with wxString?
Unfortunatly, wstring is not guaranteed to be unicode =(

In fact, it basically never it, since to be unicode it's have to be UTF-32 ( otherwise you'd have surrogate troubles ) and I've never seen a numeric_limits<wchar_t>::digits large enough for that to be possible.

anonuser

  • Guest
Re: Last standing unicode problem
« Reply #29 on: December 10, 2005, 09:04:40 pm »
not according to the gnu standard. wchar must be 32 bits wide. http://www.gnu.org/software/libc/manual/html_node/Extended-Char-Intro.html for more info.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Last standing unicode problem
« Reply #30 on: December 21, 2005, 09:17:27 pm »
In http://forums.codeblocks.org/index.php?topic=1693.0 280Z28 might have stated a solution for the unicode problem. Look at this:
Code
wxString str;
str.Printf(_T("MyString%d"), 5);
This should result in a unicode compatible "MyString5". Does this help?
Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Last standing unicode problem
« Reply #31 on: December 21, 2005, 10:18:02 pm »
In fact, it basically never it, since to be unicode it's have to be UTF-32 ( otherwise you'd have surrogate troubles ) and I've never seen a numeric_limits<wchar_t>::digits large enough for that to be possible.
On my FC4 box, sizeof(wchar_t) says 4.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Last standing unicode problem
« Reply #32 on: December 21, 2005, 10:22:40 pm »
Actually making a u2s (unsigned int to string) function isn't that hard... just keep dividing over 10 and concatenating to a string (it produces a reversed number). Then you just reverse the elements and ta-da :)

anonuser

  • Guest
Re: Last standing unicode problem
« Reply #33 on: December 22, 2005, 12:19:16 am »
a wchar_t will always hold a unicode character as long as you're going by GNU standards.
So there should be no problem.