Example #1
0
std::vector<std::string> ConvertArgumentsIntoUtf8(int argc, char* argv[])
{
	// In Win32, argc and argv are in the current codepage
	// Best to ignore them and use GetCommandLineW, this will get
	// the arguments in unicode

	// Get arguments
	std::vector<std::string> arguments;
	int numberArgs = 0;
	LPWSTR* listArgs = ::CommandLineToArgvW(::GetCommandLineW(), &numberArgs);
	if (listArgs == NULL)
	{
		return arguments;
	}


	// Convert to UTF-8
	for (int i=0; i < numberArgs; ++i)
	{
		std::wstring utf16Str(listArgs[i]);
		std::string  utf8Str;
		
		utf8::utf16to8(utf16Str.begin(), utf16Str.end(), std::back_inserter(utf8Str));
		arguments.push_back(utf8Str);
	}

	return arguments;

}
bool TestExtIcu_ucsdet::test_utf16() {
  // The detector only handles UTF-16 if there's a BOM at the front.
  char utf16[] =
    "\xff\xfeH\x00" "e\x00l\x00l\x00o\x00,\x00 \x00w\x00o\x00r\x00l\x00"
    "d\x00!\x00";

  // Take off 1 byte for the NUL at the end of the char[].
  String utf16Str(utf16, sizeof utf16 - 1, AttachLiteral);
  VERIFY(detect_and_convert_to_utf8(
    utf16Str,
    "\ufeffHello, world!") == true);

  return Count(true);
}