diff options
author | 2019-09-11 14:16:02 -0400 | |
---|---|---|
committer | 2019-09-11 14:16:02 -0400 | |
commit | bc15184c90a7eaf4cf16ea060916346e390a7c3b (patch) | |
tree | bdf475c68602c37cba55338702343f572bbed6ee /src/osd/modules/lib/osdlib_macosx.cpp | |
parent | 4f8928432a9db8cd46cfd5c6e2cb262eafaed9d2 (diff) |
Changed osd_get_clipboard_text() to return std::string (#5615)
* Changed osd_get_clipboard_text() to return std::string
This change has only been tested on Windows. The Un*x/Mac versions were
made blindly; they might not even build. This needs to be checked prior
to merging.
* Fixing Mac OS X build (hopefully)
Diffstat (limited to 'src/osd/modules/lib/osdlib_macosx.cpp')
-rw-r--r-- | src/osd/modules/lib/osdlib_macosx.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp index b476261df41..372293ec1a3 100644 --- a/src/osd/modules/lib/osdlib_macosx.cpp +++ b/src/osd/modules/lib/osdlib_macosx.cpp @@ -116,22 +116,23 @@ void osd_break_into_debugger(const char *message) // osd_get_clipboard_text //============================================================ -char *osd_get_clipboard_text(void) +std::string osd_get_clipboard_text(void) { + std::string result; + bool has_result = false; OSStatus err; PasteboardRef pasteboard_ref; err = PasteboardCreate(kPasteboardClipboard, &pasteboard_ref); if (err) - return nullptr; + return result; PasteboardSynchronize(pasteboard_ref); ItemCount item_count; err = PasteboardGetItemCount(pasteboard_ref, &item_count); - char *result = nullptr; // core expects a malloced C string of uft8 data - for (UInt32 item_index = 1; (item_index <= item_count) && !result; item_index++) + for (UInt32 item_index = 1; (item_index <= item_count) && !has_result; item_index++) { PasteboardItemID item_id; err = PasteboardGetItemIdentifier(pasteboard_ref, item_index, &item_id); @@ -144,7 +145,7 @@ char *osd_get_clipboard_text(void) continue; CFIndex const flavor_count = CFArrayGetCount(flavor_type_array); - for (CFIndex flavor_index = 0; (flavor_index < flavor_count) && !result; flavor_index++) + for (CFIndex flavor_index = 0; (flavor_index < flavor_count) && !has_result; flavor_index++) { CFStringRef const flavor_type = (CFStringRef)CFArrayGetValueAtIndex(flavor_type_array, flavor_index); @@ -171,12 +172,9 @@ char *osd_get_clipboard_text(void) CFIndex const length = CFDataGetLength(data_ref); CFRange const range = CFRangeMake(0, length); - result = reinterpret_cast<char *>(malloc(length + 1)); - if (result) - { - CFDataGetBytes(data_ref, range, reinterpret_cast<unsigned char *>(result)); - result[length] = 0; - } + result.resize(length); + CFDataGetBytes(data_ref, range, reinterpret_cast<unsigned char *>(&result[0])); + has_result = true; CFRelease(data_ref); } |