From a667080d96395792cd3c6066ef0ebe6c8b508bbe Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 7 Apr 2025 11:03:34 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E4=B8=A4=E4=B8=AA=E8=B7=AF=E5=BE=84=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=98=AF=E5=90=8C=E4=B8=80=E4=B8=AA=E8=B7=AF=E5=BE=84=E5=92=8C?= =?UTF-8?q?=E6=A0=87=E5=87=86=E5=8C=96=E8=B7=AF=E5=BE=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/of_path.h | 6 ++++-- src/of_path.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) 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