Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

27
Dec

UTF8 To Unicode conversion program

Related Blog Items

  1. int UTF8ToUnicode(const unsigned char *Src, int SrcLen, WCHAR *strDest, int DestLen)
  2. {
  3.   int i=0;
  4.   int outputlen=0;
  5.  
  6.   for (i=0 ; i < SrcLen; )
  7.   {
  8.     if (outputlen >= DestLen)
  9.     {
  10.       //overflow detected
  11.       break;
  12.     }
  13.  
  14.     if ( 0xc0 <= Src[i] )
  15.     {
  16.       Dest[outputlen++] = (WCHAR) ((Src[i] & ~0xc0) << 6 | (Src[i+1] & ~0x80));
  17.       i+=2;
  18.     }
  19.     else if ( 0xe0 <= Src[i] )
  20.     {
  21.       strDest[outputlen++] =(WCHAR) (Src[i] << 12 | (Src[i+1] & 0x3f) << 6 | Src[i+2] & 0x3f);
  22.       i+=3;
  23.     }
  24.     else
  25.     {
  26.       Dest[outputlen++] = (WCHAR) Src[i];
  27.       ++i;
  28.     }
  29.   }
  30.  
  31.   Dest[outputlen] = ‘\0′;
  32.   return outputlen;
  33. }

Popularity: 11%

You need to log on to convert this article into PDF


Related Blog Items

1 Comment

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image