From 58f046ba26d67c6e1ceda2a20977e316f1a942ad Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Fri, 8 Oct 2021 07:54:12 -0400 Subject: KWSys 2021-10-08 (b8c734ba) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit b8c734bac4380fae3758cd34dbcc8425532e4ecf (master). Upstream Shortlog ----------------- Laurent Malka (1): 6ccbfc12 SystemTools: Add a Join function Sean McBride (2): f9e45083 CTestConfig: Always set CTEST_DROP_METHOD to https 15effd64 MD5: Fix Clang 13 Wnull-pointer-subtraction warning --- CTestConfig.cmake | 4 +--- MD5.c | 3 ++- SystemTools.cxx | 26 ++++++++++++++++++++++++++ SystemTools.hxx.in | 7 +++++++ testSystemTools.cxx | 10 ++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CTestConfig.cmake b/CTestConfig.cmake index 12347b6..6484cc2 100644 --- a/CTestConfig.cmake +++ b/CTestConfig.cmake @@ -3,9 +3,7 @@ set(CTEST_PROJECT_NAME "KWSys") set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT") -if (NOT CTEST_DROP_METHOD STREQUAL "https") - set(CTEST_DROP_METHOD "http") -endif () +set(CTEST_DROP_METHOD "https") set(CTEST_DROP_SITE "open.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard") set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/MD5.c b/MD5.c index fb18a5b..76995e2 100644 --- a/MD5.c +++ b/MD5.c @@ -10,6 +10,7 @@ #endif #include /* size_t */ +#include /* uintptr_t */ #include /* malloc, free */ #include /* memcpy, strlen */ @@ -202,7 +203,7 @@ static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/) * On little-endian machines, we can process properly aligned * data without copying it. */ - if (!((data - (const md5_byte_t*)0) & 3)) { + if (!((uintptr_t)data & 3)) { /* data are properly aligned */ X = (const md5_word_t*)data; } else { diff --git a/SystemTools.cxx b/SystemTools.cxx index 930d84c..bd900fe 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -3767,6 +3767,32 @@ bool SystemTools::Split(const std::string& str, return true; } +std::string SystemTools::Join(const std::vector& list, + const std::string& separator) +{ + std::string result; + if (list.empty()) { + return result; + } + + size_t total_size = separator.size() * (list.size() - 1); + for (const std::string& string : list) { + total_size += string.size(); + } + + result.reserve(total_size); + bool needs_separator = false; + for (const std::string& string : list) { + if (needs_separator) { + result += separator; + } + result += string; + needs_separator = true; + } + + return result; +} + /** * Return path of a full filename (no trailing slashes). * Warning: returned path is converted to Unix slashes format. diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index e5d115e..dd0cb3b 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -214,6 +214,13 @@ public: char separator); /** + * Joins a vector of strings into a single string, with separator in between + * each string. + */ + static std::string Join(const std::vector& list, + const std::string& separator); + + /** * Return string with space added between capitalized words * (i.e. EatMyShorts becomes Eat My Shorts ) * (note that IEatShorts becomes IEat Shorts) diff --git a/testSystemTools.cxx b/testSystemTools.cxx index 6ccc7a7..f96bd71 100644 --- a/testSystemTools.cxx +++ b/testSystemTools.cxx @@ -626,6 +626,16 @@ static bool CheckStringOperations() res = false; } + std::vector linesToJoin = { "Mary", "Had", "A", "Little", + "Lamb." }; + std::string joinResult = kwsys::SystemTools::Join(linesToJoin, " "); + if (joinResult != "Mary Had A Little Lamb.") { + std::cerr << "Problem with Join " + "\"Mary Had A Little Lamb.\"" + << std::endl; + res = false; + } + if (kwsys::SystemTools::ConvertToWindowsOutputPath( "L://Local Mojo/Hex Power Pack/Iffy Voodoo") != "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") { -- cgit v0.12