• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_PLATFORM_WINDOWS_WIDE_CHAR_H_
17 #define TENSORFLOW_CORE_PLATFORM_WINDOWS_WIDE_CHAR_H_
18 
19 #include <Windows.h>
20 // Windows.h #defines ERROR, but it is also used in
21 // tensorflow/core/util/event.proto
22 #undef ERROR
23 #include <string>
24 #include "tensorflow/core/platform/types.h"
25 
26 namespace tensorflow {
27 
Utf8ToWideChar(const string & utf8str)28 inline std::wstring Utf8ToWideChar(const string& utf8str) {
29   int size_required = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(),
30                                           (int)utf8str.size(), NULL, 0);
31   std::wstring ws_translated_str(size_required, 0);
32   MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), (int)utf8str.size(),
33                       &ws_translated_str[0], size_required);
34   return ws_translated_str;
35 }
36 
WideCharToUtf8(const std::wstring & wstr)37 inline string WideCharToUtf8(const std::wstring& wstr) {
38   if (wstr.empty()) return std::string();
39   int size_required = WideCharToMultiByte(
40       CP_UTF8, 0, wstr.c_str(), (int)wstr.size(), NULL, 0, NULL, NULL);
41   string utf8_translated_str(size_required, 0);
42   WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), (int)wstr.size(),
43                       &utf8_translated_str[0], size_required, NULL, NULL);
44   return utf8_translated_str;
45 }
46 
47 }  // namespace tensorflow
48 
49 #endif  // TENSORFLOW_CORE_PLATFORM_WINDOWS_WIDE_CHAR_H_
50