This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, master has been updated via 7bacf0233be03100b830e65cdd02a0d1fb2c2a13 (commit) via 94f7d19a983a4d5d9efc5e21d167a0a6a4ba18fa (commit) via a693e875db5d0939a316955f513396e533153b6d (commit) via 4aa555f9da5541d6b1f13b0cd3ec3e7387c75c89 (commit) via 75cf7ec263034e0212554f373bb6fd02d351163f (commit) via e5d3ea22d49e6d85082306d1f73d0689a3fbca81 (commit) via a7d0fe9c24e111bc4f325d608b31fdf394c24602 (commit) via 541361a58bae487956c5b50d475edc4fcb453030 (commit) from 97d9876c78803879f3cd08a65dec9420873fcc92 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7bacf0233be03100b830e65cdd02a0d1fb2c2a13 commit 7bacf0233be03100b830e65cdd02a0d1fb2c2a13 Merge: 94f7d19 a693e87 Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Aug 2 14:56:50 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Aug 2 10:56:59 2019 -0400 Merge topic 'use_cmHasPrefix' a693e875db Cleanups: Use cmHas{Prefix,Suffix} instead of String{Starts,Ends}With Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3637 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=94f7d19a983a4d5d9efc5e21d167a0a6a4ba18fa commit 94f7d19a983a4d5d9efc5e21d167a0a6a4ba18fa Merge: 97d9876 4aa555f Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Aug 2 14:55:11 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Aug 2 10:55:39 2019 -0400 Merge topic 'cmStringAlgorithms_modernize' 4aa555f9da Tests: Add CMakeLib.testStringAlgorithms test 75cf7ec263 cmStringAlgorithms: Modernize cmWrap using cm::string_view e5d3ea22d4 cmStringAlgorithms: Add cmCatViews and cmStrCat functions a7d0fe9c24 cmStringAlgorithms: Simplify cmJoin using cm::string_view 541361a58b cmStringAlgorithms: Simplify cmStrCmp using cm::string_view Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3628 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a693e875db5d0939a316955f513396e533153b6d commit a693e875db5d0939a316955f513396e533153b6d Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Thu Aug 1 12:57:18 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Thu Aug 1 13:33:00 2019 +0200 Cleanups: Use cmHas{Prefix,Suffix} instead of String{Starts,Ends}With diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 512ac7a..3fd124b 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -21,6 +21,7 @@ #include "cmMakefile.h" #include "cmState.h" #include "cmStateSnapshot.h" +#include "cmStringAlgorithms.h" #include "cmVersion.h" #include "cmWorkingDirectory.h" #include "cmXMLSafe.h" @@ -772,7 +773,7 @@ int cmCPackGenerator::InstallCMakeProject( // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory // exists: // - if (cmSystemTools::StringStartsWith(dir.c_str(), "/")) { + if (cmHasLiteralPrefix(dir, "/")) { dir = tempInstallDirectory + dir; } else { dir = tempInstallDirectory + "/" + dir; diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index f6028c4..54fe612 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -13,6 +13,7 @@ #include "cmParseGTMCoverage.h" #include "cmParseJacocoCoverage.h" #include "cmParsePHPCoverage.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" #include "cmXMLWriter.h" @@ -1181,7 +1182,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( // gcov 4.7 can have output lines saying "No executable lines" and // "Removing 'filename.gcov'"... Don't log those as "errors." if (line != "No executable lines" && - !cmSystemTools::StringStartsWith(line.c_str(), "Removing ")) { + !cmHasLiteralPrefix(line, "Removing ")) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output line: [" << line << "]" << std::endl); diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 237ca82..bbf490e 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -16,6 +16,7 @@ #include "cmProcessOutput.h" #include "cmState.h" #include "cmStateSnapshot.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmXMLWriter.h" #include "cmake.h" @@ -594,7 +595,7 @@ bool cmCTestLaunch::Match(std::string const& line, bool cmCTestLaunch::MatchesFilterPrefix(std::string const& line) const { return !this->OptionFilterPrefix.empty() && - cmSystemTools::StringStartsWith(line, this->OptionFilterPrefix.c_str()); + cmHasPrefix(line, this->OptionFilterPrefix); } int cmCTestLaunch::Main(int argc, const char* const argv[]) diff --git a/Source/CTest/cmParseJacocoCoverage.cxx b/Source/CTest/cmParseJacocoCoverage.cxx index b78142a..5f1e712 100644 --- a/Source/CTest/cmParseJacocoCoverage.cxx +++ b/Source/CTest/cmParseJacocoCoverage.cxx @@ -2,6 +2,7 @@ #include "cmCTest.h" #include "cmCTestCoverageHandler.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmXMLParser.h" @@ -118,7 +119,7 @@ protected: // Check if any of the locations found match our package. for (std::string const& f : files) { std::string dir = cmsys::SystemTools::GetParentDirectory(f); - if (cmsys::SystemTools::StringEndsWith(dir, this->PackageName.c_str())) { + if (cmHasSuffix(dir, this->PackageName)) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Found package directory for " << fileName << ": " << dir << std::endl, diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 610e9f9..026250d 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1965,7 +1965,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "-N", "--show-only")) { this->Impl->ShowOnly = true; } - if (cmSystemTools::StringStartsWith(arg.c_str(), "--show-only=")) { + if (cmHasLiteralPrefix(arg, "--show-only=")) { this->Impl->ShowOnly = true; // Check if a specific format is requested. Defaults to human readable @@ -2227,7 +2227,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) // attempts are simply ignored since previous ctest versions ignore // this too. (As well as many other unknown command line args.) // - if (arg != "-D" && cmSystemTools::StringStartsWith(arg.c_str(), "-D")) { + if (arg != "-D" && cmHasLiteralPrefix(arg, "-D")) { std::string input = arg.substr(2); this->AddVariableDefinition(input); } diff --git a/Source/cmCallVisualStudioMacro.cxx b/Source/cmCallVisualStudioMacro.cxx index f7a2244..9e152ff 100644 --- a/Source/cmCallVisualStudioMacro.cxx +++ b/Source/cmCallVisualStudioMacro.cxx @@ -4,6 +4,7 @@ #include <sstream> +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #if defined(_MSC_VER) @@ -328,8 +329,7 @@ HRESULT FindVisualStudioInstances(const std::string& slnFile, if (SUCCEEDED(hr)) { std::map<std::string, IUnknownPtr>::iterator it; for (it = mrot.begin(); it != mrot.end(); ++it) { - if (cmSystemTools::StringStartsWith(it->first.c_str(), - "!VisualStudio.DTE.")) { + if (cmHasLiteralPrefix(it->first, "!VisualStudio.DTE.")) { IDispatchPtr disp(it->second); if (disp != (IDispatch*)0) { std::string slnName; diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 8fd2947..87f9b4c 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -1209,8 +1209,8 @@ bool cmExportFileGenerator::PopulateExportProperties( targetProperties.GetPropertyValue("EXPORT_PROPERTIES")) { for (auto& prop : cmSystemTools::ExpandedListArgument(exportProperties)) { /* Black list reserved properties */ - if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") || - cmSystemTools::StringStartsWith(prop, "INTERFACE_")) { + if (cmHasLiteralPrefix(prop, "IMPORTED_") || + cmHasLiteralPrefix(prop, "INTERFACE_")) { std::ostringstream e; e << "Target \"" << gte->Target->GetName() << "\" contains property \"" << prop << "\" in EXPORT_PROPERTIES but IMPORTED_* and INTERFACE_* " diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 782f746..8fcf1ac 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -4,6 +4,7 @@ #include "cmMakefile.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" class cmExecutionStatus; @@ -71,7 +72,7 @@ struct cmFindProgramHelper bool CheckDirectoryForName(std::string const& path, std::string const& name) { for (std::string const& ext : this->Extensions) { - if (!ext.empty() && cmSystemTools::StringEndsWith(name, ext.c_str())) { + if (!ext.empty() && cmHasSuffix(name, ext)) { continue; } this->TestNameExt = name; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 38f34ac..7340bc2 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4192,7 +4192,7 @@ cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const if (stripResources) { flags.MacFolder = ""; } - } else if (cmSystemTools::StringStartsWith(location, "Resources/")) { + } else if (cmHasLiteralPrefix(location, "Resources/")) { flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource; if (stripResources) { flags.MacFolder += strlen("Resources/"); diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 8401efb..bead0e3 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -8,7 +8,9 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmState.h" +#include "cmStringAlgorithms.h" #include "cmUuid.h" +#include "cm_string_view.hxx" #include "cmake.h" #include "cmsys/Encoding.hxx" @@ -432,16 +434,15 @@ void cmGlobalVisualStudio7Generator::WriteTargetDepends( void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout) { - const char* prefix = "CMAKE_FOLDER_GUID_"; - const std::string::size_type skip_prefix = strlen(prefix); + cm::string_view const prefix = "CMAKE_FOLDER_GUID_"; std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8"; for (auto const& iter : VisualStudioFolders) { std::string fullName = iter.first; std::string guid = this->GetGUID(fullName); std::replace(fullName.begin(), fullName.end(), '/', '\\'); - if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) { - fullName = fullName.substr(skip_prefix); + if (cmHasPrefix(fullName, prefix)) { + fullName = fullName.substr(prefix.size()); } std::string nameOnly = cmSystemTools::GetFilenameName(fullName); diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx index 2aefe8f..0801c24 100644 --- a/Source/cmQtAutoMocUic.cxx +++ b/Source/cmQtAutoMocUic.cxx @@ -1894,7 +1894,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile) std::list<std::string>::iterator it = includes.begin(); while (it != includes.end()) { std::string const& path = *it; - if (cmSystemTools::StringStartsWith(path, ppath->c_str())) { + if (cmHasPrefix(path, *ppath)) { MocConst_.IncludePaths.push_back(path); it = includes.erase(it); } else { diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 04b4d72..ffdd0ce 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -9,6 +9,7 @@ #include "cmMakefile.h" #include "cmSourceGroup.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" namespace { @@ -54,7 +55,7 @@ bool rootIsPrefix(const std::string& root, const std::vector<std::string>& files, std::string& error) { for (std::string const& file : files) { - if (!cmSystemTools::StringStartsWith(file, root.c_str())) { + if (!cmHasPrefix(file, root)) { error = "ROOT: " + root + " is not a prefix of file: " + file; return false; } diff --git a/Source/cmVisualStudioSlnParser.cxx b/Source/cmVisualStudioSlnParser.cxx index 9353276..3e7e142 100644 --- a/Source/cmVisualStudioSlnParser.cxx +++ b/Source/cmVisualStudioSlnParser.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmVisualStudioSlnParser.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmVisualStudioSlnData.h" #include "cmsys/FStream.hxx" @@ -192,8 +193,8 @@ bool cmVisualStudioSlnParser::State::Process( assert(!line.IsComment()); switch (this->Stack.top()) { case FileStateStart: - if (!cmSystemTools::StringStartsWith( - line.GetTag().c_str(), "Microsoft Visual Studio Solution File")) { + if (!cmHasLiteralPrefix(line.GetTag(), + "Microsoft Visual Studio Solution File")) { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; } diff --git a/Source/cmake.cxx b/Source/cmake.cxx index b97152f..309efd3 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2031,8 +2031,7 @@ void cmake::AppendGlobalGeneratorsDocumentation( for (cmGlobalGeneratorFactory* g : this->Generators) { cmDocumentationEntry e; g->GetDocumentation(e); - if (!foundDefaultOne && - cmSystemTools::StringStartsWith(e.Name, defaultName.c_str())) { + if (!foundDefaultOne && cmHasPrefix(e.Name, defaultName)) { e.CustomNamePrefix = '*'; foundDefaultOne = true; } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4aa555f9da5541d6b1f13b0cd3ec3e7387c75c89 commit 4aa555f9da5541d6b1f13b0cd3ec3e7387c75c89 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Wed Jul 31 12:44:51 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Thu Aug 1 11:45:04 2019 +0200 Tests: Add CMakeLib.testStringAlgorithms test diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt index a25f25a..cd4dbc8 100644 --- a/Tests/CMakeLib/CMakeLists.txt +++ b/Tests/CMakeLib/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMakeLib_TESTS testRST.cxx testRange.cxx testString.cxx + testStringAlgorithms.cxx testSystemTools.cxx testUTF8.cxx testXMLParser.cxx diff --git a/Tests/CMakeLib/testStringAlgorithms.cxx b/Tests/CMakeLib/testStringAlgorithms.cxx new file mode 100644 index 0000000..95616ff --- /dev/null +++ b/Tests/CMakeLib/testStringAlgorithms.cxx @@ -0,0 +1,134 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#include <cmConfigure.h> // IWYU pragma: keep + +#include "cm_string_view.hxx" +#include <iostream> +#include <sstream> +#include <string> +#include <vector> + +#include "cmStringAlgorithms.h" + +int testStringAlgorithms(int /*unused*/, char* /*unused*/ []) +{ + int failed = 0; + + auto assert_ok = [&failed](bool test, cm::string_view title) { + if (test) { + std::cout << "Passed: " << title << "\n"; + } else { + std::cout << "Failed: " << title << "\n"; + ++failed; + } + }; + + auto assert_string = [&failed](cm::string_view generated, + cm::string_view expected, + cm::string_view title) { + if (generated == expected) { + std::cout << "Passed: " << title << "\n"; + } else { + std::cout << "Failed: " << title << "\n"; + std::cout << "Expected: " << expected << "\n"; + std::cout << "Got: " << generated << "\n"; + ++failed; + } + }; + + // ---------------------------------------------------------------------- + // Test cmJoin + { + typedef std::string ST; + typedef std::vector<std::string> VT; + assert_string(cmJoin(ST("abc"), ";"), "a;b;c", "cmJoin std::string"); + assert_string(cmJoin(VT{}, ";"), "", "cmJoin std::vector empty"); + assert_string(cmJoin(VT{ "a" }, ";"), "a", "cmJoin std::vector single"); + assert_string(cmJoin(VT{ "a", "b", "c" }, ";"), "a;b;c", + "cmJoin std::vector multiple"); + assert_string(cmJoin(VT{ "a", "b", "c" }, "<=>"), "a<=>b<=>c", + "cmJoin std::vector long sep"); + } + + // ---------------------------------------------------------------------- + // Test cmStrCat + { + int ni = -1100; + unsigned int nui = 1100u; + long int nli = -12000l; + unsigned long int nuli = 12000ul; + long long int nlli = -130000ll; + unsigned long long int nulli = 130000ull; + std::string val = + cmStrCat("<test>", ni, ',', nui, ',', nli, ",", nuli, ", ", nlli, + std::string(", "), nulli, cm::string_view("</test>")); + std::string expect = + "<test>-1100,1100,-12000,12000, -130000, 130000</test>"; + assert_string(val, expect, "cmStrCat strings and integers"); + } + { + float const val = 1.5f; + float const div = 0.00001f; + float f = 0.0f; + std::istringstream(cmStrCat("", val)) >> f; + f -= val; + assert_ok((f < div) && (f > -div), "cmStrCat float"); + } + { + double const val = 1.5; + double const div = 0.00001; + double d = 0.0; + std::istringstream(cmStrCat("", val)) >> d; + d -= val; + assert_ok((d < div) && (d > -div), "cmStrCat double"); + } + + // ---------------------------------------------------------------------- + // Test cmWrap + { + typedef std::vector<std::string> VT; + assert_string(cmWrap("<", VT{}, ">", "; "), // + "", // + "cmWrap empty, string prefix and suffix"); + assert_string(cmWrap("<", VT{ "abc" }, ">", "; "), // + "<abc>", // + "cmWrap single, string prefix and suffix"); + assert_string(cmWrap("<", VT{ "a1", "a2", "a3" }, ">", "; "), // + "<a1>; <a2>; <a3>", // + "cmWrap multiple, string prefix and suffix"); + + assert_string(cmWrap('<', VT{}, '>', "; "), // + "", // + "cmWrap empty, char prefix and suffix"); + assert_string(cmWrap('<', VT{ "abc" }, '>', "; "), // + "<abc>", // + "cmWrap single, char prefix and suffix"); + assert_string(cmWrap('<', VT{ "a1", "a2", "a3" }, '>', "; "), // + "<a1>; <a2>; <a3>", // + "cmWrap multiple, char prefix and suffix"); + } + + // ---------------------------------------------------------------------- + // Test cmHas(Literal)Prefix and cmHas(Literal)Suffix + { + std::string str("abc"); + assert_ok(cmHasPrefix(str, 'a'), "cmHasPrefix char"); + assert_ok(!cmHasPrefix(str, 'c'), "cmHasPrefix char not"); + assert_ok(cmHasPrefix(str, "ab"), "cmHasPrefix string"); + assert_ok(!cmHasPrefix(str, "bc"), "cmHasPrefix string not"); + assert_ok(cmHasPrefix(str, str), "cmHasPrefix complete string"); + assert_ok(cmHasLiteralPrefix(str, "ab"), "cmHasLiteralPrefix string"); + assert_ok(!cmHasLiteralPrefix(str, "bc"), "cmHasLiteralPrefix string not"); + + assert_ok(cmHasSuffix(str, 'c'), "cmHasSuffix char"); + assert_ok(!cmHasSuffix(str, 'a'), "cmHasSuffix char not"); + assert_ok(cmHasSuffix(str, "bc"), "cmHasSuffix string"); + assert_ok(!cmHasSuffix(str, "ab"), "cmHasSuffix string not"); + assert_ok(cmHasSuffix(str, str), "cmHasSuffix complete string"); + assert_ok(cmHasLiteralSuffix(str, "bc"), "cmHasLiteralSuffix string"); + assert_ok(!cmHasLiteralSuffix(str, "ab"), "cmHasLiteralPrefix string not"); + } + + return failed; +} https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=75cf7ec263034e0212554f373bb6fd02d351163f commit 75cf7ec263034e0212554f373bb6fd02d351163f Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Wed Jul 31 22:07:05 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Thu Aug 1 11:45:04 2019 +0200 cmStringAlgorithms: Modernize cmWrap using cm::string_view diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 3037bef..cdb494f 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -98,21 +98,25 @@ inline std::string cmStrCat(cmAlphaNum const& a, cmAlphaNum const& b, { a.View(), b.View(), static_cast<cmAlphaNum const&>(args).View()... }); } +/** Joins wrapped elements of a range with separator into a single string. */ template <typename Range> -std::string cmWrap(std::string const& prefix, Range const& r, - std::string const& suffix, std::string const& sep) +std::string cmWrap(cm::string_view prefix, Range const& rng, + cm::string_view suffix, cm::string_view sep) { - if (r.empty()) { + if (rng.empty()) { return std::string(); } - return prefix + cmJoin(r, suffix + sep + prefix) + suffix; + return cmCatViews( + { prefix, cmJoin(rng, cmCatViews({ suffix, sep, prefix })), suffix }); } +/** Joins wrapped elements of a range with separator into a single string. */ template <typename Range> -std::string cmWrap(char prefix, Range const& r, char suffix, - std::string const& sep) +std::string cmWrap(char prefix, Range const& rng, char suffix, + cm::string_view sep) { - return cmWrap(std::string(1, prefix), r, std::string(1, suffix), sep); + return cmWrap(cm::string_view(&prefix, 1), rng, cm::string_view(&suffix, 1), + sep); } /** Returns true if string @a str starts with the character @a prefix. */ https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e5d3ea22d49e6d85082306d1f73d0689a3fbca81 commit e5d3ea22d49e6d85082306d1f73d0689a3fbca81 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Mon Jul 29 17:34:54 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Thu Aug 1 11:45:04 2019 +0200 cmStringAlgorithms: Add cmCatViews and cmStrCat functions diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 041c606..fe40af3 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -404,6 +404,7 @@ set(SRCS cmStateSnapshot.cxx cmStateSnapshot.h cmStateTypes.h + cmStringAlgorithms.cxx cmStringAlgorithms.h cmSystemTools.cxx cmSystemTools.h diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx new file mode 100644 index 0000000..5deb9b0 --- /dev/null +++ b/Source/cmStringAlgorithms.cxx @@ -0,0 +1,73 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmStringAlgorithms.h" + +#include <algorithm> +#include <cstdio> + +namespace { +template <std::size_t N, typename T> +inline void MakeDigits(cm::string_view& view, char (&digits)[N], + const char* pattern, T value) +{ + int res = std::snprintf(digits, N, pattern, value); + if (res > 0 && res < static_cast<int>(N)) { + view = cm::string_view(digits, static_cast<std::size_t>(res)); + } +} +} // unnamed namespace + +cmAlphaNum::cmAlphaNum(int val) +{ + MakeDigits(View_, Digits_, "%i", val); +} + +cmAlphaNum::cmAlphaNum(unsigned int val) +{ + MakeDigits(View_, Digits_, "%u", val); +} + +cmAlphaNum::cmAlphaNum(long int val) +{ + MakeDigits(View_, Digits_, "%li", val); +} + +cmAlphaNum::cmAlphaNum(unsigned long int val) +{ + MakeDigits(View_, Digits_, "%lu", val); +} + +cmAlphaNum::cmAlphaNum(long long int val) +{ + MakeDigits(View_, Digits_, "%lli", val); +} + +cmAlphaNum::cmAlphaNum(unsigned long long int val) +{ + MakeDigits(View_, Digits_, "%llu", val); +} + +cmAlphaNum::cmAlphaNum(float val) +{ + MakeDigits(View_, Digits_, "%g", static_cast<double>(val)); +} + +cmAlphaNum::cmAlphaNum(double val) +{ + MakeDigits(View_, Digits_, "%g", val); +} + +std::string cmCatViews(std::initializer_list<cm::string_view> views) +{ + std::size_t total_size = 0; + for (cm::string_view const& view : views) { + total_size += view.size(); + } + + std::string result(total_size, '\0'); + std::string::iterator sit = result.begin(); + for (cm::string_view const& view : views) { + sit = std::copy_n(view.data(), view.size(), sit); + } + return result; +} diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 8d6aec6..3037bef 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -7,6 +7,7 @@ #include "cmRange.h" #include "cm_string_view.hxx" +#include <initializer_list> #include <sstream> #include <string.h> #include <string> @@ -48,6 +49,55 @@ std::string cmJoin(Range const& rng, cm::string_view separator) return os.str(); } +/** Concatenate string pieces into a single string. */ +std::string cmCatViews(std::initializer_list<cm::string_view> views); + +/** Utility class for cmStrCat. */ +class cmAlphaNum +{ +public: + cmAlphaNum(cm::string_view view) + : View_(view) + { + } + cmAlphaNum(std::string const& str) + : View_(str) + { + } + cmAlphaNum(const char* str) + : View_(str) + { + } + cmAlphaNum(char ch) + : View_(Digits_, 1) + { + Digits_[0] = ch; + } + cmAlphaNum(int val); + cmAlphaNum(unsigned int val); + cmAlphaNum(long int val); + cmAlphaNum(unsigned long int val); + cmAlphaNum(long long int val); + cmAlphaNum(unsigned long long int val); + cmAlphaNum(float val); + cmAlphaNum(double val); + + cm::string_view View() const { return View_; } + +private: + cm::string_view View_; + char Digits_[32]; +}; + +/** Concatenate string pieces and numbers into a single string. */ +template <typename... AV> +inline std::string cmStrCat(cmAlphaNum const& a, cmAlphaNum const& b, + AV const&... args) +{ + return cmCatViews( + { a.View(), b.View(), static_cast<cmAlphaNum const&>(args).View()... }); +} + template <typename Range> std::string cmWrap(std::string const& prefix, Range const& r, std::string const& suffix, std::string const& sep) diff --git a/bootstrap b/bootstrap index 7d9631c..ac5adc8 100755 --- a/bootstrap +++ b/bootstrap @@ -422,6 +422,7 @@ CMAKE_CXX_SOURCES="\ cmState \ cmStateDirectory \ cmStateSnapshot \ + cmStringAlgorithms \ cmStringReplaceHelper \ cmStringCommand \ cmSubdirCommand \ https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a7d0fe9c24e111bc4f325d608b31fdf394c24602 commit a7d0fe9c24e111bc4f325d608b31fdf394c24602 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Mon Jul 29 15:15:00 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Thu Aug 1 10:38:12 2019 +0200 cmStringAlgorithms: Simplify cmJoin using cm::string_view diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 3f88692..8d6aec6 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -7,8 +7,6 @@ #include "cmRange.h" #include "cm_string_view.hxx" -#include <algorithm> -#include <iterator> #include <sstream> #include <string.h> #include <string> @@ -32,32 +30,25 @@ private: std::string const Test_; }; +/** Joins elements of a range with separator into a single string. */ template <typename Range> -std::string cmJoin(Range const& r, const char* delimiter) +std::string cmJoin(Range const& rng, cm::string_view separator) { - if (r.empty()) { + if (rng.empty()) { return std::string(); } - std::ostringstream os; - typedef typename Range::value_type ValueType; - typedef typename Range::const_iterator InputIt; - const InputIt first = r.begin(); - InputIt last = r.end(); - --last; - std::copy(first, last, std::ostream_iterator<ValueType>(os, delimiter)); - - os << *last; + std::ostringstream os; + auto it = rng.begin(); + auto const end = rng.end(); + os << *it; + while (++it != end) { + os << separator << *it; + } return os.str(); } template <typename Range> -std::string cmJoin(Range const& r, std::string const& delimiter) -{ - return cmJoin(r, delimiter.c_str()); -} - -template <typename Range> std::string cmWrap(std::string const& prefix, Range const& r, std::string const& suffix, std::string const& sep) { https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=541361a58bae487956c5b50d475edc4fcb453030 commit 541361a58bae487956c5b50d475edc4fcb453030 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Mon Jul 29 14:47:10 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Thu Aug 1 10:38:12 2019 +0200 cmStringAlgorithms: Simplify cmStrCmp using cm::string_view diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 149e0ad..3f88692 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -15,28 +15,21 @@ #include <utility> #include <vector> +/** String range type. */ typedef cmRange<std::vector<std::string>::const_iterator> cmStringRange; +/** Callable string comparison struct. */ struct cmStrCmp { - cmStrCmp(const char* test) - : m_test(test) + cmStrCmp(std::string str) + : Test_(std::move(str)) { } - cmStrCmp(std::string test) - : m_test(std::move(test)) - { - } - - bool operator()(const std::string& input) const { return m_test == input; } - bool operator()(const char* input) const - { - return strcmp(input, m_test.c_str()) == 0; - } + bool operator()(cm::string_view sv) const { return Test_ == sv; } private: - const std::string m_test; + std::string const Test_; }; template <typename Range> @@ -81,46 +74,46 @@ std::string cmWrap(char prefix, Range const& r, char suffix, return cmWrap(std::string(1, prefix), r, std::string(1, suffix), sep); } -/** Returns true if string @a str starts with the character @a prefix. **/ +/** Returns true if string @a str starts with the character @a prefix. */ inline bool cmHasPrefix(cm::string_view str, char prefix) { return !str.empty() && (str.front() == prefix); } -/** Returns true if string @a str starts with string @a prefix. **/ +/** Returns true if string @a str starts with string @a prefix. */ inline bool cmHasPrefix(cm::string_view str, cm::string_view prefix) { return str.compare(0, prefix.size(), prefix) == 0; } -/** Returns true if string @a str starts with string @a prefix. **/ +/** Returns true if string @a str starts with string @a prefix. */ template <size_t N> inline bool cmHasLiteralPrefix(cm::string_view str, const char (&prefix)[N]) { return cmHasPrefix(str, cm::string_view(prefix, N - 1)); } -/** Returns true if string @a str ends with the character @a suffix. **/ +/** Returns true if string @a str ends with the character @a suffix. */ inline bool cmHasSuffix(cm::string_view str, char suffix) { return !str.empty() && (str.back() == suffix); } -/** Returns true if string @a str ends with string @a suffix. **/ +/** Returns true if string @a str ends with string @a suffix. */ inline bool cmHasSuffix(cm::string_view str, cm::string_view suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } -/** Returns true if string @a str ends with string @a suffix. **/ +/** Returns true if string @a str ends with string @a suffix. */ template <size_t N> inline bool cmHasLiteralSuffix(cm::string_view str, const char (&suffix)[N]) { return cmHasSuffix(str, cm::string_view(suffix, N - 1)); } -/** Removes an existing suffix character of from the string @a str. **/ +/** Removes an existing suffix character of from the string @a str. */ inline void cmStripSuffixIfExists(std::string& str, char suffix) { if (cmHasSuffix(str, suffix)) { @@ -128,7 +121,7 @@ inline void cmStripSuffixIfExists(std::string& str, char suffix) } } -/** Removes an existing suffix string of from the string @a str. **/ +/** Removes an existing suffix string of from the string @a str. */ inline void cmStripSuffixIfExists(std::string& str, cm::string_view suffix) { if (cmHasSuffix(str, suffix)) { ----------------------------------------------------------------------- Summary of changes: Source/CMakeLists.txt | 1 + Source/CPack/cmCPackGenerator.cxx | 3 +- Source/CTest/cmCTestCoverageHandler.cxx | 3 +- Source/CTest/cmCTestLaunch.cxx | 3 +- Source/CTest/cmParseJacocoCoverage.cxx | 3 +- Source/cmCTest.cxx | 4 +- Source/cmCallVisualStudioMacro.cxx | 4 +- Source/cmExportFileGenerator.cxx | 4 +- Source/cmFindProgramCommand.cxx | 3 +- Source/cmGeneratorTarget.cxx | 2 +- Source/cmGlobalVisualStudio7Generator.cxx | 9 +- Source/cmQtAutoMocUic.cxx | 2 +- Source/cmSourceGroupCommand.cxx | 3 +- Source/cmStringAlgorithms.cxx | 73 ++++++++++++++++ Source/cmStringAlgorithms.h | 126 ++++++++++++++++++---------- Source/cmVisualStudioSlnParser.cxx | 5 +- Source/cmake.cxx | 3 +- Tests/CMakeLib/CMakeLists.txt | 1 + Tests/CMakeLib/testStringAlgorithms.cxx | 134 ++++++++++++++++++++++++++++++ bootstrap | 1 + 20 files changed, 321 insertions(+), 66 deletions(-) create mode 100644 Source/cmStringAlgorithms.cxx create mode 100644 Tests/CMakeLib/testStringAlgorithms.cxx hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org https://cmake.org/mailman/listinfo/cmake-commits