diff options
| author | Manolo Gouy <Manolo> | 2011-04-19 12:37:20 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2011-04-19 12:37:20 +0000 |
| commit | ad50b753be9f60e06ec3059f0266a04d98f2409d (patch) | |
| tree | 86ab0bdf242cab75eb3c5a9f7ebedbd299ff3d7b /src | |
| parent | d4685c13eff068817031b768ecdf930961c361c5 (diff) | |
Added fallback mechanism if malformed UTF-8 is used for a window title.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8608 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_cocoa.mm | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 94ecc8372..721831079 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1623,11 +1623,16 @@ int Fl_X::fake_X_wm(const Fl_Window* w,int &X,int &Y, int &bt,int &bx, int &by) Fl_Window *fl_dnd_target_window = 0; static void q_set_window_title(NSWindow *nsw, const char * name ) { - CFStringRef utf8_title = CFStringCreateWithCString(NULL, (name ? name : ""), kCFStringEncodingUTF8); - if(utf8_title) { - [nsw setTitle:(NSString*)utf8_title ]; - CFRelease(utf8_title); - } + CFStringRef title = CFStringCreateWithCString(NULL, (name ? name : ""), kCFStringEncodingUTF8); + if(!title) { // fallback when name contains malformed UTF-8 + int l = strlen(name); + unsigned short* utf16 = new unsigned short[l + 1]; + l = fl_utf8toUtf16(name, l, utf16, l + 1); + title = CFStringCreateWithCharacters(NULL, utf16, l); + delete[] utf16; + } + [nsw setTitle:(NSString*)title]; + CFRelease(title); } |
