Revision: 8365 https://osdn.net/projects/ttssh2/scm/svn/commits/8365 Author: zmatsuo Date: 2019-11-06 22:28:02 +0900 (Wed, 06 Nov 2019) Log Message: ----------- 改行コードの変換に失敗しないよう修正 Modified Paths: -------------- branches/unicode_buf/teraterm/teraterm/sendmem.cpp -------------- next part -------------- Modified: branches/unicode_buf/teraterm/teraterm/sendmem.cpp =================================================================== --- branches/unicode_buf/teraterm/teraterm/sendmem.cpp 2019-11-06 13:27:51 UTC (rev 8364) +++ branches/unicode_buf/teraterm/teraterm/sendmem.cpp 2019-11-06 13:28:02 UTC (rev 8365) @@ -351,7 +351,7 @@ /* * \x89\xFC\x8Ds\x83R\x81[\x83h\x82\xF0LF(0x0a)\x82\xBE\x82\xAF\x82ɂ\xB7\x82\xE9 * - * @param [in] *src_ \x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^ + * @param [in] *src \x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^ * @param [in] *len \x93\xFC\x97͕\xB6\x8E\x9A\x97\xF1\x92\xB7(0\x82̂Ƃ\xAB\x93\xE0\x95\x94\x82ŕ\xB6\x8E\x9A\x97𑪂\xE9) * @param [out] *len \x8Fo\x97͕\xB6\x8E\x9A\x97\xF1\x92\xB7 * @return \x95ϊ\xB7\x8C㕶\x8E\x9A\x97\xF1(malloc\x82\xB3\x82ꂽ\x97̈\xE6) @@ -367,42 +367,28 @@ return NULL; } - // LF(0x0a),CR(0x0d)\x82\xAA\x82\xA0\x82邩\x92\xB2\x82ׂ\xE9 + // CR+LF -> LF + // CR -> LF + // LF -> LF (\x95ϊ\xB7\x95s\x97v) int cr_count = 0; int lf_count = 0; const wchar_t *p = src; - for (size_t i = 0; i < src_len; i++) { + const wchar_t *p_end = src + src_len; + wchar_t *dest = dest_top; + while (p < p_end) { wchar_t c = *p++; - if (c == CR) { // 0x0d - cr_count++; - } else if (c == LF) { // 0x0d - lf_count++; - } - } - - wchar_t *dest = dest_top; - if (lf_count == 0 && cr_count != 0) { - // LF\x82Ȃ\xB5\x81ACR\x82̂\xDD - // CR\x82\xF0LF\x82ɕϊ\xB7\x82\xB7\x82\xE9 - for (size_t i = 0; i < src_len; i++) { - wchar_t c = *src++; - *dest++ = (c == CR) ? LF : c; - } - } else if (lf_count != 0 && cr_count != 0) { - // CR\x81ALF\x82Ƃ\xE0\x82\xA0\x82\xE8 - // CR\x82\xF0\x8ÊĂ\xE9 - for (size_t i = 0; i < src_len; i++) { - wchar_t c = *src++; - if (c == CR) { - continue; + if (c == CR) { + if (*p == LF) { + // CR+LF -> LF + p++; + *dest++ = LF; + } else { + // CR -> LF + *dest++ = LF; } + } else { *dest++ = c; } - } else { - // CR\x82̂\xDD or \x89\xFC\x8Ds\x82\xAA\x91S\x82\xAD\x82Ȃ\xA2 - // \x95ϊ\xB7\x95s\x97v - memcpy(dest , src, sizeof(wchar_t) * src_len); - dest += src_len; } *len = dest - dest_top;