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: , , , ,


24 Comments »

« Previous321Next »
Onur On March 27th, 2011 at 6:00 am (#)

Thanjk good post.. thnx thnx

Daniel Garcia On January 9th, 2011 at 8:32 am (#)

Is there any way to turn line number off, for a single <pre> block, or start line numbers at a certain number ?

Onur On May 14th, 2010 at 11:11 pm (#)

realy good work, tnx a lot!

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 [...]

« Previous321Next »

Leave a comment


(will not be published)