Convert Unicode To UTF8

char* __stdcall UnicodeToUtf8( const WCHAR* wstr )
{
    const WCHAR* w;
    // Convert unicode to utf8
    int len = 0;
    for ( w = wstr; *w; w++ ) {

        if ( *w < 0×0080 ) len++;
        else if ( *w < 0×0800 ) len += 2;
        else len += 3;
    }

    unsigned char* szOut = ( unsigned char* )malloc( len+1 );

    if ( szOut == NULL )
        return NULL;

    int i = 0;
    for ( w = wstr; *w; w++ ) {
        if ( *w < 0×0080 )
            szOut[i++] = ( unsigned char ) *w;
        else if ( *w < 0×0800 ) {
            szOut[i++] = 0xc0 | (( *w ) >> 6 );
            szOut[i++] = 0×80 | (( *w ) &amp; 0×3f );
        }
        else {
            szOut[i++] = 0xe0 | (( *w ) >> 12 );
            szOut[i++] = 0×80 | (( ( *w ) >> 6 ) &amp; 0×3f );
            szOut[i++] = 0×80 | (( *w ) &amp; 0×3f );
        }    }

    szOut[ i ] = \0;
    return ( char* )szOut;
}

Related posts:

TAGS: , , , ,


21 Comments »

« Previous321Next »
test On August 26th, 2009 at 12:47 pm (#)

function num2str($inn, $stripkop=0) {
return implode(‘ ‘,$out);
}

test On February 26th, 2009 at 8:48 am (#)
vnh On November 22nd, 2008 at 10:41 pm (#)

hfıy

Daniel On June 17th, 2008 at 6:39 pm (#)

let’s test it:

<?
$var = “10″;
for($i=0;$i

End!

hepnet On March 28th, 2008 at 8:41 am (#)

Web sitenizde CSS, PHP, JS kod parçaları yayınlıyorsanız, bu kodların tek renk olarak görünmesinden sıkılmış olabilirsiniz. Özellikle uzun kod parçalarıyla verilen örneklerde kodların tek renkte olması, okunabilirliği ve kodun anlaşılabilirliğini oldukça azaltıyor.

qeremy On March 21st, 2008 at 4:41 am (#)

realy good work, tnx a lot!

Kod Renklendirme » opereysin.com - Seviyeli, kaliteli… On March 17th, 2008 at 12:02 pm (#)

[...] Şu adreste çalışan halini [...]

Syntax Highlighters | Genç Haritacı'nın Günlüğü On March 3rd, 2008 at 5:38 pm (#)

[...] örneğini buradan [...]

Syntax Highlighter | StylizedWeb.com On March 2nd, 2008 at 4:19 am (#)

[...] Use the “pre” tag and add the programming language you want to use as a parameter. Example:. < pre lang=”php” > your code here … < /pre >. for example: <pre lang=”php”> function hello_world(){ echo “hello world” }</pre> after highlighting: You can see a Living demo at here. [...]

  Source Code syntax highlighting plugin for WordPress (V1.2) by YangTx 仰天啸 On November 25th, 2007 at 8:12 am (#)

[...] can see a Living demo at here. Share and Enjoy: These icons link to social bookmarking sites where readers can share and [...]

« Previous321Next »

Leave a comment


(will not be published)