Codechange: replace buffer + strecpy with std::string for getting clipboard contents

This commit is contained in:
Rubidium
2023-05-31 20:26:49 +02:00
committed by rubidium42
parent 35f7f7e8dc
commit d68b5c9162
5 changed files with 31 additions and 49 deletions

View File

@@ -183,25 +183,21 @@ const char *GetCurrentLocale(const char *)
/**
* Return the contents of the clipboard (COCOA).
*
* @param buffer Clipboard content.
* @param last The pointer to the last element of the destination buffer
* @return Whether clipboard is empty or not.
* @return The (optional) clipboard contents.
*/
bool GetClipboardContents(char *buffer, const char *last)
std::optional<std::string> GetClipboardContents()
{
NSPasteboard *pb = [ NSPasteboard generalPasteboard ];
NSArray *types = [ NSArray arrayWithObject:NSPasteboardTypeString ];
NSString *bestType = [ pb availableTypeFromArray:types ];
/* Clipboard has no text data available. */
if (bestType == nil) return false;
if (bestType == nil) return std::nullopt;
NSString *string = [ pb stringForType:NSPasteboardTypeString ];
if (string == nil || [ string length ] == 0) return false;
if (string == nil || [ string length ] == 0) return std::nullopt;
strecpy(buffer, [ string UTF8String ], last);
return true;
return [ string UTF8String ];
}
/** Set the application's bundle directory.