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

@@ -217,22 +217,20 @@ void ShowOSErrorBox(const char *buf, bool system)
#endif
#ifndef WITH_COCOA
bool GetClipboardContents(char *buffer, const char *last)
std::optional<std::string> GetClipboardContents()
{
#ifdef WITH_SDL2
if (SDL_HasClipboardText() == SDL_FALSE) {
return false;
}
if (SDL_HasClipboardText() == SDL_FALSE) return std::nullopt;
char *clip = SDL_GetClipboardText();
if (clip != nullptr) {
strecpy(buffer, clip, last);
std::string result = clip;
SDL_free(clip);
return true;
return result;
}
#endif
return false;
return std::nullopt;
}
#endif