Author: manolo
Date: 2011-04-19 05:37:20 -0700 (Tue, 19 Apr 2011)
New Revision: 8608
Log:
Added fallback mechanism if malformed UTF-8 is used for a window title.
Modified:
branches/branch-1.3/src/Fl_cocoa.mm
Modified: branches/branch-1.3/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3/src/Fl_cocoa.mm 2011-04-19 08:22:05 UTC (rev 8607)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2011-04-19 12:37:20 UTC (rev 8608)
@@ -1623,11 +1623,16 @@
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);
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit