Files
openvino/inference-engine/include/ie_unicode.hpp
Ilya Lavrenov 6a5993fb36 Implement unicode conversion using Windows native functions (#1590)
* Implement unicode conversion using Windows native functions

* NOCPPLINT

* Fixed deprecated c++ api usage in tests

* Moved impl to cpp

* Moved Unicode utils to Plugin API

* Added missed include for Windows

* Fixes for unit tests; CentOS fixes

* Fixed Windows compilation

* Fixed unit tests on Unix

* Fixed unix 2
2020-08-06 12:01:34 +03:00

66 lines
1.6 KiB
C++

// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief This is a header file with common inference engine definitions
*
* @file ie_unicode.hpp
*/
#pragma once
#include <algorithm>
#include <cstdlib>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#ifdef UNICODE
typedef wchar_t tchar;
typedef std::wstring file_name_t;
#else
typedef char tchar;
typedef std::string file_name_t;
#endif
namespace InferenceEngine {
/**
* @deprecated Use OS-native conversion utilities
* @brief Conversion from possibly-wide character string to a single-byte chain.
*/
INFERENCE_ENGINE_DEPRECATED("Use OS-native conversion utilities")
inline std::string fileNameToString(const file_name_t& str) {
#ifdef UNICODE
size_t maxlen = (str.length() + 1) * sizeof(wchar_t) / sizeof(char);
std::vector<char> mbstr(maxlen);
mbstr[0] = 0;
std::wcstombs(&mbstr[0], str.c_str(), maxlen);
std::string res = std::string(&mbstr[0]);
return res;
#else
return str;
#endif
}
/**
* @deprecated Use OS-native conversion utilities
* @brief Conversion from single-byte character string to a possibly-wide one
*/
INFERENCE_ENGINE_DEPRECATED("Use OS-native conversion utilities")
inline file_name_t stringToFileName(const std::string& str) {
#ifdef UNICODE
size_t maxlen = str.length() + 1;
std::vector<wchar_t> wcstr(maxlen);
wcstr[0] = 0;
std::mbstowcs(&wcstr[0], str.c_str(), maxlen);
file_name_t res = file_name_t(&wcstr[0]);
return res;
#else
return str;
#endif
}
} // namespace InferenceEngine