Skip to content

Commit d0d5073

Browse files
committed
fix bugs
1 parent 4e6ae28 commit d0d5073

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

clip/clip.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static __forceinline void _Write(DWORD handleId, const wchar_t *text, long long
4848
{
4949
char *p2 = buffer2;
5050
for (int i = 0; i < length; i++) {
51-
const unsigned short w = text[i];
51+
unsigned short w = text[i];
5252
#if USE_LOCAL_ERROR_MESSAGE
5353
if (w <= 0x7f) {
5454
*p2++ = (char)w;
@@ -58,7 +58,16 @@ static __forceinline void _Write(DWORD handleId, const wchar_t *text, long long
5858
*p2++ = 0x80 | (w & 0x3f);
5959
}
6060
else {
61-
*p2++ = 0xe0 | ((w >> 12) & 0x0f);
61+
if (0 && w >= 0xd800 && w < 0xdc00 && i < length - 1) {
62+
unsigned int point = ((w - 0xd800) << 10) | ((text[++i] - 0xdc00) & 0x3ff) + 0x10000;
63+
*p2++ = 0xf0 | ((point >> 18) & 0x08);
64+
*p2++ = 0x80 | ((point >> 12) & 0x3f);
65+
w = (unsigned short)point;
66+
}
67+
else
68+
{
69+
*p2++ = 0xe0 | ((w >> 12) & 0x0f);
70+
}
6271
*p2++ = 0x80 | ((w >> 6) & 0x3f);
6372
*p2++ = 0x80 | (w & 0x3f);
6473
}
@@ -216,13 +225,14 @@ extern "C" void cmain(void)
216225
// here strips tail /\r\n/
217226
if (dataType == DataType::ANSII) {
218227
while (*--p == '\n' || *p == '\r') {}
228+
p[1] = '\0';
219229
}
220230
else {
221231
do {
222232
p = (char*)((wchar_t *)p - 1);
223233
} while (*(wchar_t *)p == L'\n' || *(wchar_t *)p == L'\r');
234+
((wchar_t *)p)[1] = L'\0';
224235
}
225-
p[1] = '\0'; p[2] = '\0';
226236
//output[input_len] = '\0'; output[input_len + 1] = '\0';
227237
GlobalUnlock(hData);
228238
succeed = SetClipboardData(dataType == DataType::ANSII ? CF_TEXT : CF_UNICODETEXT, hData) != NULL;

0 commit comments

Comments
 (0)