Merge branch 'main' of https://www.sinxmiao.cn/taynpg/ofen
This commit is contained in:
commit
3b5afa0661
@ -4,15 +4,16 @@ project(ofen LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(NOT DEFINED USE_UTF8_ALL)
|
||||
if (MSVC)
|
||||
add_compile_options(/source-charset:utf-8)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
MESSAGE(STATUS "ofen Add MinGW Param.")
|
||||
add_compile_options(-finput-charset=utf-8)
|
||||
add_compile_options(-fexec-charset=gbk)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
|
||||
@ -36,8 +37,8 @@ include_directories(${MBOOST_INCLUDE_DIR})
|
||||
link_directories(${MBOOST_LIB_DIR})
|
||||
endif()
|
||||
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
|
||||
|
||||
add_library(ofen STATIC ${SRC_FILES})
|
||||
target_include_directories(ofen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/3rd)
|
||||
|
@ -206,20 +206,35 @@ ofStrVec COfPath::match_files(const ofString& path)
|
||||
{
|
||||
ofStrVec ret;
|
||||
|
||||
fs::path in(path);
|
||||
fs::path parent_path = in.parent_path();
|
||||
std::string filename_pattern = in.filename().string();
|
||||
// 使用宽字符版本的 fs::path
|
||||
std::filesystem::path in(path);
|
||||
std::filesystem::path parent_path = in.parent_path();
|
||||
ofString filename_pattern = in.filename().native(); // 使用 native() 获取正确的字符类型
|
||||
|
||||
if (parent_path.empty()) {
|
||||
parent_path = fs::current_path();
|
||||
parent_path = std::filesystem::current_path();
|
||||
}
|
||||
|
||||
// 根据 UNICODE_OFSTR 选择正确的正则表达式类型
|
||||
#ifdef UNICODE_OFSTR
|
||||
std::wregex file_regex;
|
||||
ofString regex_pattern = std::regex_replace(filename_pattern, std::wregex(ofT(R"(\*)")), ofT(".*"));
|
||||
regex_pattern = std::regex_replace(regex_pattern, std::wregex(ofT(R"(\?)")), ofT("."));
|
||||
#else
|
||||
std::regex file_regex;
|
||||
std::string regex_pattern = std::regex_replace(filename_pattern, std::regex(R"(\*)"), ".*");
|
||||
regex_pattern = std::regex_replace(regex_pattern, std::regex(R"(\?)"), ".");
|
||||
#endif
|
||||
|
||||
try {
|
||||
std::regex file_regex(regex_pattern);
|
||||
for (const auto& entry : fs::directory_iterator(parent_path)) {
|
||||
#ifdef UNICODE_OFSTR
|
||||
file_regex = std::wregex(regex_pattern);
|
||||
#else
|
||||
file_regex = std::regex(regex_pattern);
|
||||
#endif
|
||||
|
||||
// 遍历目录
|
||||
for (const auto& entry : std::filesystem::directory_iterator(parent_path)) {
|
||||
#ifdef UNICODE_OFSTR
|
||||
if (std::regex_match(entry.path().filename().wstring(), file_regex)) {
|
||||
ret.push_back(entry.path().wstring());
|
||||
|
Loading…
x
Reference in New Issue
Block a user