MCPcopy Create free account
hub / github.com/SFML/SFML / getString

Method getString

src/SFML/Window/Win32/ClipboardImpl.cpp:44–75  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

42{
43////////////////////////////////////////////////////////////
44String ClipboardImpl::getString()
45{
46 String text;
47
48 if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
49 {
50 err() << "Failed to get the clipboard data in Unicode format: " << getErrorString(GetLastError()) << std::endl;
51 return text;
52 }
53
54 if (!OpenClipboard(nullptr))
55 {
56 err() << "Failed to open the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl;
57 return text;
58 }
59
60 HANDLE clipboardHandle = GetClipboardData(CF_UNICODETEXT);
61
62 if (!clipboardHandle)
63 {
64 err() << "Failed to get Win32 handle for clipboard content: " << getErrorString(GetLastError()) << std::endl;
65 CloseClipboard();
66 return text;
67 }
68
69 const std::u16string_view string(static_cast<const char16_t*>(GlobalLock(clipboardHandle)));
70 text = String::fromUtf16(string.begin(), string.end());
71 GlobalUnlock(clipboardHandle);
72
73 CloseClipboard();
74 return text;
75}
76
77
78////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

getErrorStringFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected