27
Dec
UTF8 To Unicode conversion program
Related Blog Items
- Convert Unicode to Utf8
- Little, big endianess explained -- part2
- Binary to decimal
- Binary decimal conversion....
- Implicit Type Conversions - part 2
-
int UTF8ToUnicode(const unsigned char *Src, int SrcLen, WCHAR *strDest, int DestLen)
-
{
-
int i=0;
-
int outputlen=0;
-
-
for (i=0 ; i < SrcLen; )
-
{
-
if (outputlen >= DestLen)
-
{
-
//overflow detected
-
break;
-
}
-
-
if ( 0xc0 <= Src[i] )
-
{
-
Dest[outputlen++] = (WCHAR) ((Src[i] & ~0xc0) << 6 | (Src[i+1] & ~0x80));
-
i+=2;
-
}
-
else if ( 0xe0 <= Src[i] )
-
{
-
strDest[outputlen++] =(WCHAR) (Src[i] << 12 | (Src[i+1] & 0x3f) << 6 | Src[i+2] & 0x3f);
-
i+=3;
-
}
-
else
-
{
-
Dest[outputlen++] = (WCHAR) Src[i];
-
++i;
-
}
-
}
-
-
Dest[outputlen] = ‘\0′;
-
return outputlen;
-
}
Popularity: 11%
You need to log on to convert this article into PDF
Related Blog Items - Convert Unicode to Utf8
- Little, big endianess explained -- part2
- Binary to decimal
- Binary decimal conversion....
- Implicit Type Conversions - part 2
Related Blog Items
- Convert Unicode to Utf8
- Little, big endianess explained -- part2
- Binary to decimal
- Binary decimal conversion....
- Implicit Type Conversions - part 2
It would be useful if you explain what is UTF8 and unicode before giving the code snippet.
January 3rd, 2007 at 11:37 am