std::wstring widen_string(std::string in_str) {
				static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
				return converter.from_bytes(in_str);
			}
Example #2
0
#include "m1/utf8_decode.hpp"
#include "m1/pragma_message.hpp"
#include "utf8_test_data.hpp"
#include "catch.hpp"
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <locale>
#include <codecvt>

TEST_CASE("Test m1::utf8_decode", "[m1]")
{
    SECTION("utf8_decode_each -- test::utf8_test_data")
    {
        #pragma M1_MESSAGE("change to char32_t and u32string, this is a workaround for VS 2015 linker error")
        std::wstring_convert<std::codecvt_utf8<std::uint32_t>, std::uint32_t> utf32conv;
        std::basic_string<std::uint32_t> const utf32_test_data = utf32conv.from_bytes(reinterpret_cast<char const*>(test::utf8_test_data.begin()),
                                                                                      reinterpret_cast<char const*>(test::utf8_test_data.end()));

        std::vector<m1::code_point> utf32_decode;
        m1::utf8_decode_copy(test::utf8_test_data.begin(),
                             test::utf8_test_data.end(),
                             std::back_inserter(utf32_decode));

        CHECK(std::equal(utf32_decode.begin(), utf32_decode.end(),
                         utf32_test_data.begin(), utf32_test_data.end()));
    }
}
Example #3
0
void pal::to_palstring(const char* str, pal::string_t* out)
{
    out->assign(g_converter.from_bytes(str));
}
Example #4
0
pal::string_t pal::to_palstring(const std::string& str)
{
    return g_converter.from_bytes(str);
}
Example #5
0
std::wstring Widen( const std::string& str )
{
	static std::wstring_convert< std::codecvt_utf8< wchar_t >, wchar_t > converter;
	return converter.from_bytes( str );
}
Example #6
-1
    std::wstring RegistryByteBuffer::getUTF16String(const uint32_t offset, const uint32_t length) const {
        if (length == 0) {
            return L"";
        }

        ByteBuffer::ByteArray &data = getData(offset, length);
        // If the size of the array is not a multiple of 2 it is
        // likely to not be UTF16 encoded. The most common case is that
        // the string is simply missing a terminating null so we add it.
        if (data.size() % 2 != 0) {
            data.push_back('\0');
        }

        // Find UTF16 null terminator.
        uint32_t nullPos = 0;
        for (; nullPos < data.size(); nullPos += 2) {
            if (data[nullPos] == '\0' && data[nullPos+1] == '\0') {
                break;
            }
        }

        if (nullPos == 0) {
            return L"";
        }

        std::wstring result;

        try {
            result = conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char*>(&data[nullPos]));
        }
        catch (std::exception&)
        {
            throw RegistryParseException("Error: Failed to convert string");
        }

        return result;
    }