From e73fca5a8505e84048af01eebf3f6892e7a71ce0 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 6 Oct 2022 18:12:26 +0200 Subject: [PATCH] Use c++20 function ends_with() Close #12294 --- PowerEditor/src/MISC/Common/Common.cpp | 12 +----------- PowerEditor/src/MISC/Common/Common.h | 1 - .../OpenSaveFileDialog/CustomFileDialog.cpp | 4 ++-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index cbf3ae825..e18b215aa 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -961,7 +961,7 @@ bool buf2Clipborad(const std::vector& buffers, bool isFullPath, HWND hw if (fileName) selection += fileName; } - if (!selection.empty() && !endsWith(selection, crlf)) + if (!selection.empty() && !selection.ends_with(crlf)) selection += crlf; } if (!selection.empty()) @@ -1373,16 +1373,6 @@ void trim(generic_string& str) else str.erase(str.begin(), str.end()); } -bool endsWith(const generic_string& s, const generic_string& suffix) -{ -#if defined(_MSVC_LANG) && (_MSVC_LANG > 201402L) - return s.ends_with(suffix); -#else - size_t pos = s.find(suffix); - return pos != s.npos && ((s.length() - pos) == suffix.length()); -#endif -} - int nbDigitsFromNbLines(size_t nbLines) { int nbDigits = 0; // minimum number of digit should be 4 diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 612f44b6a..2c673a506 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -225,7 +225,6 @@ template size_t vecRemoveDuplicates(std::vector& vec, bool isSort } void trim(generic_string& str); -bool endsWith(const generic_string& s, const generic_string& suffix); int nbDigitsFromNbLines(size_t nbLines); diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp index fe1b97cae..46e4669fb 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp @@ -457,7 +457,7 @@ private: if (extIndex >= 0 && extIndex < static_cast(_filterSpec.size())) { const generic_string ext = get1stExt(_filterSpec[extIndex].ext); - if (!endsWith(ext, _T(".*"))) + if (!ext.ends_with(_T(".*"))) return replaceExt(name, ext); } return false; @@ -707,7 +707,7 @@ public: if (!hasExt(newFileName)) { const generic_string ext = get1stExt(_filterSpec[_fileTypeIndex].ext); - if (!endsWith(ext, _T(".*"))) + if (!ext.ends_with(_T(".*"))) newFileName += ext; } }