Skip to content

Commit 4f66447

Browse files
authored
fixed: support utf-8 path xml-file (#845)
* fixed: 1. added compile version check to support Chinese path xml-file parsing 2. cmake add msvc /utf-8 options * change cmake /utf-8 option add mode
1 parent 89dbbb7 commit 4f66447

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ else()
7474
include(cmake/conan_build.cmake)
7575
endif()
7676

77-
7877
#############################################################
7978
# LIBRARY
8079

@@ -187,6 +186,7 @@ target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${CMAK
187186
target_compile_features(${BTCPP_LIBRARY} PUBLIC cxx_std_17)
188187

189188
if(MSVC)
189+
target_compile_options(${BTCPP_LIBRARY} PRIVATE "/source-charset:utf-8")
190190
else()
191191
target_compile_options(${BTCPP_LIBRARY} PRIVATE -Wall -Wextra)
192192
endif()

src/xml_parsing.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#include <string>
2020
#include <typeindex>
2121

22+
#if defined(_MSVC_LANG) && !defined(__clang__)
23+
#define __bt_cplusplus (_MSC_VER == 1900 ? 201103L : _MSVC_LANG)
24+
#else
25+
#define __bt_cplusplus __cplusplus
26+
#endif
27+
2228
#if defined(__linux) || defined(__linux__)
2329
#pragma GCC diagnostic push
2430
#pragma GCC diagnostic ignored "-Wattributes"
@@ -254,7 +260,12 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes)
254260
break;
255261
}
256262

257-
std::filesystem::path file_path(incl_node->Attribute("path"));
263+
#if __bt_cplusplus >= 202002L
264+
auto file_path(std::filesystem::path(incl_node->Attribute("path")));
265+
#else
266+
auto file_path(std::filesystem::u8path(incl_node->Attribute("path")));
267+
#endif
268+
258269
const char* ros_pkg_relative_path = incl_node->Attribute("ros_pkg");
259270

260271
if(ros_pkg_relative_path)

0 commit comments

Comments
 (0)