Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » charset conversion
charset conversion [message #26011] Thu, 25 March 2010 19:20 Go to next message
abductee is currently offline  abductee
Messages: 22
Registered: June 2007
Location: Germany
Promising Member
hi,
ich have the problem that stuff i derive from a line edit seems to be utf8, but i'd like to have it in unicode... can't i tell string shomehow easly to reencode itself?
( because it breaks german "umlauts" )

a littele example to show the problem:

#include <CtrlLib/CtrlLib.h>
#include <windows.h>

using namespace Upp;
struct MyAppWindow : TopWindow {
    Button button;
    LineEdit ed;
    void Click() { 
    		String s = ~ed;
		const char *t = s;
		MessageBox(0,t,"text as char",MB_OK);
    }
    typedef MyAppWindow CLASSNAME;
    MyAppWindow() {
        Title("My application with button");
	Add(ed.TopPos(20,100).LeftPos(100,100));
        Add(button.LeftPos(100, 100).TopPos(120, 30));
        button.SetLabel("Render Text");
	Sizeable();
        button <<= THISBACK(Click);
    }
};


GUI_APP_MAIN
{
    MyAppWindow app;
    app.Run();
}



p.s.: please don't tell me to use PromtOK insted of MessageBox, this is just en example to illustrate the problem Smile

index.php?t=getfile&id=2436&private=0
  • Attachment: conv.jpg
    (Size: 20.33KB, Downloaded 422 times)
Re: charset conversion [message #26013 is a reply to message #26011] Thu, 25 March 2010 22:09 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

You may use function FromUtf8 to convert from UTF8 to Unicode.

You may see all FromUtf8 functions using Ctrl-J combination which calls dialog. Typing function name part into the dialog entry, you may see ALL available functions containing it's name (i.e. all FromUtf8() functions).
Re: charset conversion [message #26023 is a reply to message #26013] Fri, 26 March 2010 13:56 Go to previous messageGo to next message
abductee is currently offline  abductee
Messages: 22
Registered: June 2007
Location: Germany
Promising Member
aaaaaaand how do i go from WString to char* ? Smile
Re: charset conversion [message #26030 is a reply to message #26023] Fri, 26 March 2010 16:55 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
ToUtf8 and other To/From pairs.
Re: charset conversion [message #26031 is a reply to message #26030] Fri, 26 March 2010 16:58 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
BTW, you are mixing Windows API with U++. This is the source of your problems. PromptOk is the equivalent function for MessageBox.
Re: charset conversion [message #26034 is a reply to message #26011] Fri, 26 March 2010 17:25 Go to previous messageGo to next message
abductee is currently offline  abductee
Messages: 22
Registered: June 2007
Location: Germany
Promising Member
to claryfy:
lets take the string "Bär"

(middle charakter is german umlaut a)

i get:

42 C3 A4 72 00
B ä r (null)

i want to get:

42 E4 72 00
B ä r (null)

cant i tell the String(s) or the LeineEdit to behave in a way that they produce the desired result(Unicode)?

Re: charset conversion [message #26037 is a reply to message #26034] Fri, 26 March 2010 18:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
U++ and Windows encoding do not need to be the same.

U++ works in utf-8 by default for 8bit chars. Your German windows in Win 1252. You are calling Win32 API for 8-bit chars.

One way around is to use MessageBoxW and covert utf-8 to WString.

Other way around is to use

String ToSystemCharset(const String& src)

which would convert to actual 8-bit encoding.

Best way here is probably to use PromptOK. But above methods are fine if you need to use API directly.
Re: charset conversion [message #26040 is a reply to message #26037] Fri, 26 March 2010 19:19 Go to previous message
abductee is currently offline  abductee
Messages: 22
Registered: June 2007
Location: Germany
Promising Member
thanks!! ToSystemCharset was exactly what i was looking for.
Previous Topic: CParser enhancements
Next Topic: Xmlize hates spaces
Goto Forum:
  


Current Time: Sat Apr 20 02:53:21 CEST 2024

Total time taken to generate the page: 0.06897 seconds