Esempio n. 1
0
    /*static*/ int CStdlibClass::mblen(ScriptObject* self, Stringp s, int i)
    {
        Toplevel* toplevel = self->toplevel();

        if( !s )
        {
            toplevel->throwArgumentError(kNullArgumentError, "s");
        }

        StUTF8String sUTF8(s);
        return VMPI_mblen( sUTF8.c_str(), i );
    }
Esempio n. 2
0
    /**
    * @internal
    * @brief Convert UCS-2 to UTF-8
    * @param sSource UCS-2 String
    * @return UTF-8 String
    */
    static string UCS22UTF8( const wstring sSource )
    {
        const wchar_t* pBuffer = sSource.c_str();
        int nLength = sSource.length();

        // Convert string from Windows UNICODE (AKA UCS-2) to UTF-8
        int nUtf8Length = WideCharToMultiByte( CP_UTF8, 0, pBuffer, nLength, NULL, 0, NULL, NULL );
        char* pUtf8Buffer = new char[nUtf8Length];
        WideCharToMultiByte( CP_UTF8, 0, pBuffer, nLength, pUtf8Buffer, nUtf8Length, NULL, NULL );

        string sUTF8( pUtf8Buffer, nUtf8Length );
        delete [] pUtf8Buffer;

        return sUTF8;
    }
Esempio n. 3
0
    /**
    * @internal
    * @brief Convert Active Codepage to UTF-8
    * @param sSource ACP String
    * @return UTF-8 String
    */
    static string ACP2UTF8( const string sSource )
    {
        const char* pBuffer = sSource.c_str();
        int nLength = sSource.length();

        // Convert string from ACP to UTF-8 via the Windows UNICODE (AKA UCS-2)
        int nWideLength = MultiByteToWideChar( CP_ACP, 0, pBuffer, nLength, NULL, 0 );
        wchar_t* pWideBuffer = new wchar_t[nWideLength];
        MultiByteToWideChar( CP_ACP, 0, pBuffer, nLength, pWideBuffer, nWideLength );

        int nUtf8Length = WideCharToMultiByte( CP_UTF8, 0, pWideBuffer, nWideLength, NULL, 0, NULL, NULL );
        char* pUtf8Buffer = new char[nUtf8Length];
        WideCharToMultiByte( CP_UTF8, 0, pWideBuffer, nWideLength, pUtf8Buffer, nUtf8Length, NULL, NULL );

        string sUTF8( pUtf8Buffer, nUtf8Length );
        delete [] pWideBuffer;
        delete [] pUtf8Buffer;

        return sUTF8;
    }