Skip to content

Commit

Permalink
Add os::getClipboardTextUtf8 & getClipboardTextUtf16
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jan 2, 2025
1 parent 8a7aa4f commit e0c0bc1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions soup/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ NAMESPACE_SOUP
return copy_to_clipboard_utf16(unicode::utf8_to_utf16(text));
}

std::string os::getClipboardTextUtf8()
{
return unicode::utf16_to_utf8(getClipboardTextUtf16());
}

UTF16_STRING_TYPE os::getClipboardTextUtf16()
{
std::wstring text;
if (OpenClipboard(nullptr))
{
HANDLE hData = GetClipboardData(CF_UNICODETEXT);
if (hData != nullptr)
{
auto pszText = static_cast<wchar_t*>(GlobalLock(hData));
if (pszText != nullptr)
{
text = pszText;
GlobalUnlock(hData);
}
}
CloseClipboard();
}
return text;
}

#if !SOUP_CROSS_COMPILE
size_t os::getMemoryUsage()
{
Expand Down
2 changes: 2 additions & 0 deletions soup/os.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ NAMESPACE_SOUP

#if SOUP_WINDOWS
static bool copyToClipboard(const std::string& text);
[[nodiscard]] static std::string getClipboardTextUtf8();
[[nodiscard]] static std::wstring getClipboardTextUtf16();

#if !SOUP_CROSS_COMPILE
[[nodiscard]] static size_t getMemoryUsage();
Expand Down

0 comments on commit e0c0bc1

Please sign in to comment.