--- np2/codecnv/sjiseuc.c 2005/02/12 12:13:56 1.1 +++ np2/codecnv/sjiseuc.c 2005/04/01 15:35:48 1.2 @@ -5,23 +5,30 @@ UINT codecnv_sjistoeuc(char *dst, UINT dcnt, const char *src, UINT scnt) { UINT orgdcnt; + BOOL stringmode; int s; int c; - (void)scnt; // 判定してないのかよ if (src == NULL) { return(0); } - - orgdcnt = dcnt; if (dcnt == 0) { dst = NULL; + dcnt = (UINT)-1; } - dcnt--; - while(dcnt) { + orgdcnt = dcnt; + stringmode = (((SINT)scnt) < 0); + if (stringmode) { + dcnt--; + } + while(scnt > 0) { + scnt--; s = (UINT8)*src++; - if (s < 0x80) { // ascii - if (!s) { + if ((s == '\0') && (stringmode)) { + break; + } + else if (s < 0x80) { // ascii + if (dcnt == 0) { break; } dcnt--; @@ -31,8 +38,12 @@ UINT codecnv_sjistoeuc(char *dst, UINT d } } else if ((((s ^ 0x20) - 0xa1) & 0xff) < 0x2f) { + if (scnt == 0) { + break; + } + scnt--; c = (UINT8)*src++; - if (!c) { + if (c == '\0') { break; } if (dcnt < 2) { @@ -62,8 +73,15 @@ UINT codecnv_sjistoeuc(char *dst, UINT d } } } - if (dst) { - dst[0] = '\0'; + if (dst != NULL) { + if (stringmode) { + *dst = '\0'; + } +#if 1 // 一応互換の為に NULLつける + else if (dcnt) { + *dst = '\0'; + } +#endif } return((UINT)(orgdcnt - dcnt)); }