@@ -98,7 +98,7 @@ namespace bp = boost::process;
9898
9999static std::string ensureCrLf (const std::string& utf8Str);
100100static std::wstring getClipboardData ();
101- static int setClipboardData (const std::string& acpStr );
101+ static int setClipboardData (const std::wstring& utf16Str );
102102
103103using namespace std ::literals;
104104namespace platf {
@@ -1955,14 +1955,14 @@ namespace platf {
19551955
19561956 bool
19571957 set_clipboard (const std::string& content) {
1958- std::string cpContent = convertUtf8ToCurrentCodepage (ensureCrLf (content));
1958+ std::wstring cpContent = from_utf8 (ensureCrLf (content));
19591959 return !setClipboardData (cpContent);
19601960 }
19611961} // namespace platf
19621962
19631963static std::string ensureCrLf (const std::string& utf8Str) {
19641964 std::string result;
1965- result.reserve (utf8Str.size () + utf8Str.length () / 2 ); // Reserve extra space
1965+ result.reserve (utf8Str.size () + utf8Str.size () / 2 ); // Reserve extra space
19661966
19671967 for (size_t i = 0 ; i < utf8Str.size (); ++i) {
19681968 if (utf8Str[i] == ' \n ' && (i == 0 || utf8Str[i - 1 ] != ' \r ' )) {
@@ -2002,7 +2002,7 @@ static std::wstring getClipboardData() {
20022002 return ret;
20032003}
20042004
2005- static int setClipboardData (const std::string& acpStr ) {
2005+ static int setClipboardData (const std::wstring& utf16Str ) {
20062006 if (!OpenClipboard (nullptr )) {
20072007 BOOST_LOG (warning) << " Failed to open clipboard." ;
20082008 return 1 ;
@@ -2015,7 +2015,7 @@ static int setClipboardData(const std::string& acpStr) {
20152015 }
20162016
20172017 // Allocate global memory for the clipboard text
2018- HGLOBAL hGlobal = GlobalAlloc (GMEM_MOVEABLE, acpStr .size () + 1 );
2018+ HGLOBAL hGlobal = GlobalAlloc (GMEM_MOVEABLE, utf16Str .size () * 2 + 2 );
20192019 if (hGlobal == nullptr ) {
20202020 BOOST_LOG (warning) << " Failed to allocate global memory." ;
20212021 CloseClipboard ();
@@ -2031,11 +2031,11 @@ static int setClipboardData(const std::string& acpStr) {
20312031 return 1 ;
20322032 }
20332033
2034- memcpy (pGlobal, acpStr .c_str (), acpStr .size () + 1 );
2034+ memcpy (pGlobal, utf16Str .c_str (), utf16Str .size () * 2 + 2 );
20352035 GlobalUnlock (hGlobal);
20362036
20372037 // Set the clipboard data
2038- if (SetClipboardData (CF_TEXT , hGlobal) == nullptr ) {
2038+ if (SetClipboardData (CF_UNICODETEXT , hGlobal) == nullptr ) {
20392039 BOOST_LOG (warning) << " Failed to set clipboard data." ;
20402040 GlobalFree (hGlobal);
20412041 CloseClipboard ();
0 commit comments