~kiwec/ke

ke/src/Conversion.cc -rw-r--r-- 581 bytes
1cc8481d — Wolf Clément Fix compilation 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "Conversion.h"

namespace Convert {
	std::unique_ptr<char[]> from_wide_string(const wchar_t* wide_string) {
		auto len = wcstombs(NULL, wide_string, 0) + 1;
		std::unique_ptr<char[]> multibyte_string(new char[len]);
		wcstombs(multibyte_string.get(), wide_string, len);
		return multibyte_string;
	}

	std::unique_ptr<wchar_t[]> to_wide_string(const char* multibyte_string) {
		auto max_len = strlen(multibyte_string) + 1;
		std::unique_ptr<wchar_t[]> wide_string(new wchar_t[max_len]);
		mbstowcs(wide_string.get(), multibyte_string, max_len);
		return wide_string;
	}
}