Diff for /np2/codecnv/utf8ucs2.c between versions 1.1 and 1.2

version 1.1, 2005/02/12 12:13:56 version 1.2, 2005/04/01 15:35:48
Line 5 Line 5
 UINT codecnv_utf8toucs2(UINT16 *dst, UINT dcnt, const char *src, UINT scnt) {  UINT codecnv_utf8toucs2(UINT16 *dst, UINT dcnt, const char *src, UINT scnt) {
   
         UINT    orgdcnt;          UINT    orgdcnt;
           BOOL    stringmode;
         UINT    c;          UINT    c;
   
         (void)scnt;  
         if (src == NULL) {          if (src == NULL) {
                 return(0);                  return(0);
         }          }
   
         orgdcnt = dcnt;  
         if (dcnt == 0) {          if (dcnt == 0) {
                 dst = NULL;                  dst = NULL;
                   dcnt = (UINT)-1;
           }
           orgdcnt = dcnt;
           stringmode = (((SINT)scnt) < 0);
           if (stringmode) {
                   dcnt--;
         }          }
         dcnt--;          while(scnt > 0) {
         while(dcnt) {                  if ((src[0] == '\0') && (stringmode)) {
                 if (src[0] == '\0') {  
                         break;                          break;
                 }                  }
                 else if (!(src[0] & 0x80)) {                  else if (!(src[0] & 0x80)) {
                         c = src[0];                          c = src[0];
                         src += 1;                          src += 1;
                           scnt -= 1;
                 }                  }
                 else if ((src[0] & 0xe0) == 0xc0) {                  else if ((src[0] & 0xe0) == 0xc0) {
                         if ((src[1] & 0xc0) != 0x80) {                          if ((scnt < 2) ||
                                   ((src[1] & 0xc0) != 0x80)) {
                                 break;                                  break;
                         }                          }
                         c = ((src[0] & 0x1f) << 6) + (src[1] & 0x3f);                          c = ((src[0] & 0x1f) << 6) + (src[1] & 0x3f);
                         src += 2;                          src += 2;
                           scnt -= 2;
                 }                  }
                 else if ((src[0] & 0xf0) == 0xe0) {                  else if ((src[0] & 0xf0) == 0xe0) {
                         if (((src[1] & 0xc0) != 0x80) ||                          if ((scnt < 3) ||
                                   ((src[1] & 0xc0) != 0x80) ||
                                 ((src[2] & 0xc0) != 0x80)) {                                  ((src[2] & 0xc0) != 0x80)) {
                                 break;                                  break;
                         }                          }
                         c = ((src[0] & 0x0f) << 12) +                          c = ((src[0] & 0x0f) << 12) +
                                                                 ((src[1] & 0x3f) << 6) + (src[2] & 0x3f);                                                                  ((src[1] & 0x3f) << 6) + (src[2] & 0x3f);
                         src += 3;                          src += 3;
                           scnt -= 3;
                 }                  }
                 else {                  else {
                         break;                          break;
                 }                  }
                   if (dcnt == 0) {
                           break;
                   }
                 dcnt--;                  dcnt--;
                 if (dst) {                  if (dst) {
                         dst[0] = (UINT16)c;                          dst[0] = (UINT16)c;
                         dst += 1;                          dst += 1;
                 }                  }
         }          }
         if (dst) {          if (dst != NULL) {
                 dst[0] = '\0';                  if (stringmode) {
                           *dst = '\0';
                   }
   #if 1   // 一応互換の為に NULLつける
                   else if (dcnt) {
                           *dst = '\0';
                   }
   #endif
         }          }
         return((UINT)(orgdcnt - dcnt));          return((UINT)(orgdcnt - dcnt));
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.2


RetroPC.NET-CVS <cvs@retropc.net>