Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/sentencepiece.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaku Kudo <taku@google.com>2018-08-03 08:36:46 +0300
committerTaku Kudo <taku@google.com>2018-08-03 08:36:46 +0300
commit1caa5fb76eb41c7ce8bf17a67a1db7024d82e788 (patch)
tree9cd94115261e3927391561957315d194679be887 /src/util.cc
parenta0b734a4a2a2259e346f5b602ba807c5deef2f0b (diff)
Added JoinPath and StrCat
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index 5dbdd72..4bf3550 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -283,6 +283,44 @@ std::string StrError(int errnum) {
os << str << " Error #" << errnum;
return os.str();
}
-
} // namespace util
+
+#ifdef OS_WIN
+namespace win32 {
+std::wstring Utf8ToWide(const std::string &input) {
+ int output_length =
+ ::MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, nullptr, 0);
+ output_length = output_length <= 0 ? 0 : output_length - 1;
+ if (output_length == 0) {
+ return L"";
+ }
+ std::unique_ptr<wchar_t[]> input_wide(new wchar_t[output_length + 1]);
+ const int result = ::MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1,
+ input_wide.get(), output_length + 1);
+ std::wstring output;
+ if (result > 0) {
+ output.assign(input_wide.get());
+ }
+ return output;
+}
+
+std::string WideToUtf8(const std::wstring &input) {
+ const int output_length = ::WideCharToMultiByte(CP_UTF8, 0, input.c_str(), -1,
+ nullptr, 0, nullptr, nullptr);
+ if (output_length == 0) {
+ return "";
+ }
+
+ std::unique_ptr<char[]> input_encoded(new char[output_length + 1]);
+ const int result =
+ ::WideCharToMultiByte(CP_UTF8, 0, input.c_str(), -1, input_encoded.get(),
+ output_length + 1, nullptr, nullptr);
+ std::string output;
+ if (result > 0) {
+ output.assign(input_encoded.get());
+ }
+ return output;
+}
+} // namespace win32
+#endif
} // namespace sentencepiece