This is an automated email from the ASF dual-hosted git repository. szaszm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit f223ba5aa9d7be5835925f0eae4c98760d716a0e Author: Martin Zink <[email protected]> AuthorDate: Mon Apr 17 15:54:26 2023 +0200 MINIFICPP-2083 case-insensitive workaround is needed for <= GCC 12.1 (not simply <= GCC 12) Closes #1550 Signed-off-by: Marton Szasz <[email protected]> --- libminifi/src/utils/Cron.cpp | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/libminifi/src/utils/Cron.cpp b/libminifi/src/utils/Cron.cpp index 5409765f9..9961669a2 100644 --- a/libminifi/src/utils/Cron.cpp +++ b/libminifi/src/utils/Cron.cpp @@ -45,6 +45,22 @@ using date::Sunday; namespace org::apache::nifi::minifi::utils { namespace { +// https://github.com/HowardHinnant/date/issues/550 +// Due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78714 +// the month parsing with '%b' and the weekday parsing with '%a' is case-sensitive in gcc11 +// This has been fixed in gcc12.2 +std::stringstream getCaseInsensitiveStream(const std::string& str) { +#if defined(__GNUC__) && (__GNUC__ < 12 || (__GNUC__ == 12 && __GNUC_MINOR__ < 2)) + auto patched_str = StringUtils::toLower(str); + if (!patched_str.empty()) + patched_str[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(patched_str[0]))); + return std::stringstream{patched_str}; +#else + return std::stringstream{str}; +#endif +} + + template<class T> std::optional<T> fromChars(const std::string& input) { T t{}; @@ -98,18 +114,7 @@ day parse<day>(const std::string& day_str) { template <> month parse<month>(const std::string& month_str) { -// https://github.com/HowardHinnant/date/issues/550 -// Due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78714 -// the month parsing with '%b' is case sensitive in gcc11 -// This has been fixed in gcc12 -#if defined(__GNUC__) && __GNUC__ < 12 - auto patched_month_str = StringUtils::toLower(month_str); - if (!patched_month_str.empty()) - patched_month_str[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(patched_month_str[0]))); - std::stringstream stream(patched_month_str); -#else - std::stringstream stream(month_str); -#endif + std::stringstream stream = getCaseInsensitiveStream(month_str); stream.imbue(std::locale("en_US.UTF-8")); month parsed_month{}; @@ -128,19 +133,7 @@ month parse<month>(const std::string& month_str) { template <> weekday parse<weekday>(const std::string& weekday_str) { -// https://github.com/HowardHinnant/date/issues/550 -// Due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78714 -// the weekday parsing with '%a' is case sensitive in gcc11 -// This has been fixed in gcc12 -#if defined(__GNUC__) && __GNUC__ < 12 - auto patched_weekday_str = StringUtils::toLower(weekday_str); - if (!patched_weekday_str.empty()) - patched_weekday_str[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(patched_weekday_str[0]))); - std::stringstream stream(patched_weekday_str); -#else - std::stringstream stream(weekday_str); -#endif - stream.imbue(std::locale("en_US.UTF-8")); + std::stringstream stream = getCaseInsensitiveStream(weekday_str); if (weekday_str.size() > 2) { weekday parsed_weekday{};
