diff --git a/include/of_path.h b/include/of_path.h index d01a0ec..0821ea1 100644 --- a/include/of_path.h +++ b/include/of_path.h @@ -20,10 +20,12 @@ public: static bool exist(const ofString& path); static bool write(const ofString& path, const char* data, int len); static ofString to_full(const ofString& path); + static ofString standardize(const ofString& path); + static bool is_same_dir(const ofString& pa, const ofString& pb); /// @brief 根据通配符获取内容,仅支持通配文件,仅支持 *? 两种通配符。 - /// @param path - /// @return + /// @param path + /// @return static ofStrVec match_files(const ofString& path); }; }; // namespace ofen diff --git a/src/of_path.cpp b/src/of_path.cpp index ec282aa..689f2af 100644 --- a/src/of_path.cpp +++ b/src/of_path.cpp @@ -202,6 +202,56 @@ ofString COfPath::to_full(const ofString& path) #endif } +ofString COfPath::standardize(const ofString& path) +{ + fs::path p(path); + auto ret = p.lexically_normal(); +#ifdef UNICODE_OFSTR + return ofString(ret.wstring()); +#else + return ofString(ret.string()); +#endif +} + +bool COfPath::is_same_dir(const ofString& pa, const ofString& pb) +{ + fs::path a(pa); + fs::path b(pb); + + ofString stra; + ofString strb; + + if (fs::is_regular_file(a)) { +#ifdef UNICODE_OFSTR + stra = a.parent_path().wstring(); +#else + stra = a.parent_path().string(); +#endif + } else { +#ifdef UNICODE_OFSTR + stra = a.wstring(); +#else + stra = a.string(); +#endif + } + + if (fs::is_regular_file(b)) { +#ifdef UNICODE_OFSTR + strb = b.parent_path().wstring(); +#else + strb = b.parent_path().string(); +#endif + } else { +#ifdef UNICODE_OFSTR + strb = b.wstring(); +#else + strb = b.string(); +#endif + } + + return is_same_path(stra, strb); +} + ofStrVec COfPath::match_files(const ofString& path) { #ifdef UNICODE_OFSTR