Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Jan 16, 2020
1 parent 4e6ae28 commit d0d5073
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions clip/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static __forceinline void _Write(DWORD handleId, const wchar_t *text, long long
{
char *p2 = buffer2;
for (int i = 0; i < length; i++) {
const unsigned short w = text[i];
unsigned short w = text[i];
#if USE_LOCAL_ERROR_MESSAGE
if (w <= 0x7f) {
*p2++ = (char)w;
Expand All @@ -58,7 +58,16 @@ static __forceinline void _Write(DWORD handleId, const wchar_t *text, long long
*p2++ = 0x80 | (w & 0x3f);
}
else {
*p2++ = 0xe0 | ((w >> 12) & 0x0f);
if (0 && w >= 0xd800 && w < 0xdc00 && i < length - 1) {
unsigned int point = ((w - 0xd800) << 10) | ((text[++i] - 0xdc00) & 0x3ff) + 0x10000;
*p2++ = 0xf0 | ((point >> 18) & 0x08);
*p2++ = 0x80 | ((point >> 12) & 0x3f);
w = (unsigned short)point;
}
else
{
*p2++ = 0xe0 | ((w >> 12) & 0x0f);
}
*p2++ = 0x80 | ((w >> 6) & 0x3f);
*p2++ = 0x80 | (w & 0x3f);
}
Expand Down Expand Up @@ -216,13 +225,14 @@ extern "C" void cmain(void)
// here strips tail /\r\n/
if (dataType == DataType::ANSII) {
while (*--p == '\n' || *p == '\r') {}
p[1] = '\0';
}
else {
do {
p = (char*)((wchar_t *)p - 1);
} while (*(wchar_t *)p == L'\n' || *(wchar_t *)p == L'\r');
((wchar_t *)p)[1] = L'\0';
}
p[1] = '\0'; p[2] = '\0';
//output[input_len] = '\0'; output[input_len + 1] = '\0';
GlobalUnlock(hData);
succeed = SetClipboardData(dataType == DataType::ANSII ? CF_TEXT : CF_UNICODETEXT, hData) != NULL;
Expand Down

0 comments on commit d0d5073

Please sign in to comment.