fix:修正utf环境编译。
This commit is contained in:
		
							parent
							
								
									3b5afa0661
								
							
						
					
					
						commit
						c9ab756852
					
				@ -204,52 +204,55 @@ ofString COfPath::to_full(const ofString& path)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ofStrVec COfPath::match_files(const ofString& path)
 | 
					ofStrVec COfPath::match_files(const ofString& path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					#ifdef UNICODE_OFSTR
 | 
				
			||||||
    ofStrVec ret;
 | 
					    ofStrVec ret;
 | 
				
			||||||
 | 
					    fs::path in(path);
 | 
				
			||||||
    // 使用宽字符版本的 fs::path
 | 
					    fs::path parent_path = in.parent_path();
 | 
				
			||||||
    std::filesystem::path in(path);
 | 
					    ofString filename_pattern = in.filename().wstring();
 | 
				
			||||||
    std::filesystem::path parent_path = in.parent_path();
 | 
					 | 
				
			||||||
    ofString filename_pattern = in.filename().native();   // 使用 native() 获取正确的字符类型
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (parent_path.empty()) {
 | 
					    if (parent_path.empty()) {
 | 
				
			||||||
        parent_path = std::filesystem::current_path();
 | 
					        parent_path = fs::current_path();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 根据 UNICODE_OFSTR 选择正确的正则表达式类型
 | 
					 | 
				
			||||||
#ifdef UNICODE_OFSTR
 | 
					 | 
				
			||||||
    std::wregex file_regex;
 | 
					    std::wregex file_regex;
 | 
				
			||||||
    ofString regex_pattern = std::regex_replace(filename_pattern, std::wregex(ofT(R"(\*)")), ofT(".*"));
 | 
					    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("."));
 | 
					    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 {
 | 
					    try {
 | 
				
			||||||
#ifdef UNICODE_OFSTR
 | 
					 | 
				
			||||||
        file_regex = std::wregex(regex_pattern);
 | 
					        file_regex = std::wregex(regex_pattern);
 | 
				
			||||||
#else
 | 
					        for (const auto& entry : fs::directory_iterator(parent_path)) {
 | 
				
			||||||
        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)) {
 | 
					            if (std::regex_match(entry.path().filename().wstring(), file_regex)) {
 | 
				
			||||||
                ret.push_back(entry.path().wstring());
 | 
					                ret.push_back(entry.path().wstring());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
            if (std::regex_match(entry.path().filename().string(), file_regex)) {
 | 
					 | 
				
			||||||
                ret.push_back(entry.path().string());
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
    } catch (const std::exception& e) {
 | 
					    } catch (const std::exception& e) {
 | 
				
			||||||
        ret.clear();
 | 
					        ret.clear();
 | 
				
			||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    ofStrVec ret;
 | 
				
			||||||
 | 
					    fs::path in(path);
 | 
				
			||||||
 | 
					    fs::path parent_path = in.parent_path();
 | 
				
			||||||
 | 
					    ofString filename_pattern = in.filename().string();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (parent_path.empty()) {
 | 
				
			||||||
 | 
					        parent_path = fs::current_path();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    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"(\?)"), ".");
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        file_regex = std::regex(regex_pattern);
 | 
				
			||||||
 | 
					        for (const auto& entry : fs::directory_iterator(parent_path)) {
 | 
				
			||||||
 | 
					            if (std::regex_match(entry.path().filename().string(), file_regex)) {
 | 
				
			||||||
 | 
					                ret.push_back(entry.path().string());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    } catch (const std::exception& e) {
 | 
				
			||||||
 | 
					        ret.clear();
 | 
				
			||||||
 | 
					        return ret;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}   // namespace ofen
 | 
					}   // namespace ofen
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user