File indexing completed on 2025-09-16 09:00:13
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <string>
0010 #ifdef _WIN32
0011
0012
0013 #ifndef NOMINMAX
0014 #define NOMINMAX
0015 #endif
0016 #include <windows.h>
0017
0018 #include <filesystem>
0019
0020 #include "onnx/checker.h"
0021 #endif
0022
0023 namespace ONNX_NAMESPACE {
0024
0025 #ifdef _WIN32
0026 constexpr const char k_preferred_path_separator = '\\';
0027 #else
0028 constexpr const char k_preferred_path_separator = '/';
0029 #endif
0030
0031 #ifdef _WIN32
0032 inline std::wstring path_join(const std::wstring& origin, const std::wstring& append) {
0033 return (std::filesystem::path(origin) / std::filesystem::path(append)).wstring();
0034 }
0035 inline std::wstring utf8str_to_wstring(const std::string& utf8str) {
0036 if (utf8str.size() > INT_MAX) {
0037 fail_check("utf8str_to_wstring: string is too long for converting to wstring.");
0038 }
0039 int size_required = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), static_cast<int>(utf8str.size()), NULL, 0);
0040 std::wstring ws_str(size_required, 0);
0041 MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), static_cast<int>(utf8str.size()), &ws_str[0], size_required);
0042 return ws_str;
0043 }
0044 inline std::string wstring_to_utf8str(const std::wstring& ws_str) {
0045 if (ws_str.size() > INT_MAX) {
0046 fail_check("wstring_to_utf8str: string is too long for converting to UTF-8.");
0047 }
0048 int size_required =
0049 WideCharToMultiByte(CP_UTF8, 0, ws_str.c_str(), static_cast<int>(ws_str.size()), NULL, 0, NULL, NULL);
0050 std::string utf8str(size_required, 0);
0051 WideCharToMultiByte(
0052 CP_UTF8, 0, ws_str.c_str(), static_cast<int>(ws_str.size()), &utf8str[0], size_required, NULL, NULL);
0053 return utf8str;
0054 }
0055
0056 #else
0057 std::string path_join(const std::string& origin, const std::string& append);
0058
0059
0060
0061 std::string clean_relative_path(const std::string& path);
0062 #endif
0063
0064 }