Beispiel #1
0
size_t utf8towide(const char* input, size_t inputSize, wchar_t* target, size_t targetSize, int32_t* errors)
{
#if UTF8_WCHAR_UTF16
	return utf8toutf16(input, inputSize, (utf16_t*)target, targetSize, errors);
#elif UTF8_WCHAR_UTF32
	return utf8toutf32(input, inputSize, (unicode_t*)target, targetSize, errors);
#else
	return SIZE_MAX;
#endif
}
PERF_TEST_F(BigConversion, Utf16)
{
	int32_t e;

	size_t ol = utf8toutf16(m_contents.c_str(), m_contents.length(), nullptr, 0, &e);

	PERF_ASSERT(ol > 0);
	PERF_ASSERT(e == UTF8_ERR_NONE);

	if (ol > 0 &&
		e == UTF8_ERR_NONE)
	{
		utf16_t* o = new utf16_t[(ol / sizeof(utf16_t)) + 1];
		memset(o, 0, ol + sizeof(utf16_t));

		utf8toutf16(m_contents.c_str(), m_contents.length(), o, ol, nullptr);

		delete [] o;
	}
}
Beispiel #3
0
wchar_t* MimeHeaders::decode(const char* val)
{
	size_t ssz = strlen(val) * 2 + 1;
	char* tbuf = (char*)alloca(ssz);
	memcpy(tbuf, val, ssz);

	wchar_t* res = (wchar_t*)mir_alloc(ssz * sizeof(wchar_t));
	wchar_t* resp = res;

	char *p = tbuf;
	while (*p)
	{
		char *cp = strstr(p, "=?");
		if (cp == NULL) break;
		*cp = 0;

		size_t sz = utf8toutf16(p, resp);
		ssz -= sz; resp += sz; 
		cp += 2; 

		char *enc = strchr(cp, '?');
		if (enc == NULL) break;
		*(enc++) = 0;

		char *fld = strchr(enc, '?');
		if (fld == NULL) break;
		*(fld++) = 0;

		char *pe = strstr(fld, "?=");
		if (pe == NULL) break;
		*pe = 0;

		switch (*enc)
		{
			case 'b':
			case 'B':
			{
				char* dec = MSN_Base64Decode(fld);
				strcpy(fld, dec);
				mir_free(dec);
				break;
			}

			case 'q':
			case 'Q':
				PQDecode(fld);
				break;
		}
		
		if (_stricmp(cp, "UTF-8") == 0)
		{
			sz = utf8toutf16(fld, resp);
			ssz -= sz; resp += sz;
		}
		else
		{
			int sz = MultiByteToWideChar(FindCP(cp), 0, fld, -1, resp, (int)ssz);
			if (sz == 0)
				sz = MultiByteToWideChar(CP_ACP, 0, fld, -1, resp, (int)ssz);
			ssz -= --sz; resp += sz;
		}
		p = pe + 2;
	}

	utf8toutf16(p, resp); 

	return res;
}
Beispiel #4
0
/**
 * Write the header information. 
 * @param arg ignored optional user param
 * @param style the name of the format style (for transformation)
 * @param dst the destination markup file handle
 * @return 1 if successful, 0 otherwise
 */
int STIL_write_header( void *arg, dest_file *dst, UChar *style )
{
    int res = 1;
    U_COMMA = utf8toutf16(",");
    U_COMMANL = utf8toutf16(",\n");
    U_LF = utf8toutf16("\n");
    U_HEAD = utf8toutf16( "{\n");
    U_TAIL = utf8toutf16( "\n  ]\n}\n");
    U_STYLE = utf8toutf16("  \"style\": ");
    U_RANGES_START = utf8toutf16("  \"ranges\": [\n");
	U_RANGE_START = utf8toutf16("  {\n");
    U_RANGE_END = utf8toutf16("  }");
    U_NAME = utf8toutf16("    \"name\": ");
    U_RELOFF = utf8toutf16("    \"reloff\": ");
    U_LEN = utf8toutf16("    \"len\": ");
    U_REMOVED = utf8toutf16("    \"removed\": ");
    U_CONTENT = utf8toutf16("    \"content\": ");
    U_ANNOTATIONS = utf8toutf16("    \"annotations\": [ ");
    U_ANNOTATIONS_END = utf8toutf16(" ]\n");
    U_ANNOTATION = utf8toutf16("{ ");
    U_ANNOTATION_END = utf8toutf16(" }");
    U_TRUE = utf8toutf16("true");
    U_COLON = utf8toutf16(": ");
    // write header
    UChar **items = calloc(5,sizeof(UChar*));
    if ( items != NULL )
    {
        items[0] = U_HEAD;
        items[1] = U_STYLE;
        items[2] = quote_string(style,u_strlen(style));
        items[3] = U_COMMANL;
        items[4] = U_RANGES_START;
        res = write_utf16_array( items, 5, dst );
        if ( items[2] != NULL )
            free( items[2] );
        free( items );
    }
    else
        res = 0;
	return res;
}
Beispiel #5
0
	void Window::initialize()
	{
		m_info.window = this;
		m_info.silent = m_silent;
		m_info.client_methodlist = &client_main_methodlist;
		if( !m_silent )
		{
#if defined( _WIN32 ) || defined( _WIN64 )
			String rpath = utils::MainConf->string( "renderer", nullptr );
			Ref< DataBuffer > wrpath = utf8toutf16( rpath );
			m_renderermodule = LoadLibraryW( ( wchar_t* )wrpath->m_data );
			if( !m_renderermodule )
			{
				throw StrException(
					"cannot load renderer %s", rpath.getchars() );
			}
			m_renderer_connect = renderer_connect_t(
				GetProcAddress( m_renderermodule, "renderer_connect" ) );
			m_renderer_display_create = renderer_display_create_t(
				GetProcAddress( m_renderermodule, "renderer_display_create" ) );
			m_renderer_display_destroy = renderer_display_destroy_t(
				GetProcAddress( m_renderermodule, "renderer_display_destroy" ) );
			m_renderer_display_paint = renderer_display_paint_t(
				GetProcAddress( m_renderermodule, "renderer_display_paint" ) );
			m_renderer_display_setshape = renderer_display_setshape_t(
				GetProcAddress( m_renderermodule, "renderer_display_setshape" ) );
			if(
				!m_renderer_connect ||
				!m_renderer_display_create ||
				!m_renderer_display_destroy ||
				!m_renderer_display_paint ||
				!m_renderer_display_setshape )
			{
				FreeLibrary( m_renderermodule );
				throw StrException(
					"%s is not a valid Mist renderer", rpath.getchars() );
			}
			m_renderer_connect( &m_info );
			if( !m_renderer_display_create( m_hwnd, &m_display ) )
			{
				throw StrException(
					"%s", utils::cbase::geterror() );
			}
			m_info.acceleratorinput = false;
			m_info.pointinput = true;
			m_info.keyboardinput = true;
#elif defined( __ANDROID__ )
			m_info.acceleratorinput = false;
			m_info.pointinput = true;
			m_info.keyboardinput = false;
#endif
		}
		else
		{
			m_info.width = 0;
			m_info.height = 0;
			m_info.texelsoffset = 0;
			m_info.texeltoffset = 0;
			m_info.renderer_methodlist = 0;
			m_info.renderer_module = 0;
			m_info.acceleratorinput = false;
			m_info.pointinput = false;
			m_info.keyboardinput = false;
		}
		m_fpstime = clock() + CLOCKS_PER_SEC;
		initlstate();
	}