Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

01
Nov

Convert Unicode to Utf8

Related Blog Items

[highlight lang=”C”]

int UnicodeToUTF8(const WCHAR *Src, int SrcLen, unsigned char *Dest, int DestLen)
{
int i=0;
int outputlen=0; /*bytes */
char tchar;

if (!src || !dest)
{
return outputlen;
}

for ( i=0; i {
if ( outputlen >= DestLen )
{
//overflow detected
break;
}

if ( 0xdfff > Src[i] && 0xd800 < Src[i] )
{
tchar = (((Src[i] & 0×3c0) >> 6) + 1);
Dest[outputlen++] = (tchar >> 2 | 0xf0);
Dest[outputlen++] = ((tchar & 0×03 | 0×80) | (Src[i] & 0×3e) >> 2);
}
else if ( 0×800 > Src[i] )
{
Dest[outputlen++]= (Src[i] >> 6 | 0xc0);
Dest[outputlen++]= (Src[i] & 0×3f | 0×80);
}
else if ( 0×80 > Src[i] )
{
strDest[outputlen++] = Src[i];
}
else
{
Dest[outputlen++] = (Src[i] >> 12 | 0xe0);
Dest[outputlen++] = (Src[i] >> 6 & 0×3f | 0×80);
Dest[outputlen++] = (Src[i] & 0×3f | 0×80);
}
}

Dest[outputlen] = ?\0?;

return outputlen;
}

[/highlight]

[tags]utf8, unicode, unicode to utf8, unicode to utf8 conversion, unicode to utf8 conversion program[/tags]

Popularity: 9%

You need to log on to convert this article into PDF


Related Blog Items

2 Comments

Leave a comment

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