cocoa: Report an error if SDL_SetClipboardText() isn't using UTF-8 encoding.

Fixes #4110.
This commit is contained in:
Ryan C. Gordon 2021-05-08 12:39:50 -04:00
parent 107db2d899
commit 9dc97afa71

View File

@ -32,10 +32,14 @@ Cocoa_SetClipboardText(_THIS, const char *text)
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString;
NSString *nsstr = [NSString stringWithUTF8String:text];
if (nsstr == nil) {
return SDL_SetError("Couldn't create NSString; is your string data in UTF-8 format?");
}
pasteboard = [NSPasteboard generalPasteboard];
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
[pasteboard setString:nsstr forType:format];
return 0;
}}
@ -61,7 +65,7 @@ Cocoa_GetClipboardText(_THIS)
} else {
utf8 = [string UTF8String];
}
text = SDL_strdup(utf8);
text = SDL_strdup(utf8 ? utf8 : "");
} else {
text = SDL_strdup("");
}