From 9df0cea115f9fc9e3e6720a801b5c7a474c6c070 Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Fri, 9 May 2025 08:47:28 -0400 Subject: [PATCH] KWSys 2025-05-09 (c1e5779a) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit c1e5779a296730461dd8c8584dfb44476e8e3ccd (master). Upstream Shortlog ----------------- Daniel Pfeifer (1): c5bb3c4e SystemInformation: Strip trailing whitespace from ModelName --- SystemInformation.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SystemInformation.cxx b/SystemInformation.cxx index f277e567d3..7c7c4adc73 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -2806,14 +2806,13 @@ bool SystemInformationImplementation::RetrieveCPUPowerManagement() #if USE_CPUID // Used only in USE_CPUID implementation below. -static void SystemInformationStripLeadingSpace(std::string& str) +static void SystemInformationTrimSpace(std::string& s) { - // Because some manufacturers have leading white space - we have to - // post-process the name. - std::string::size_type pos = str.find_first_not_of(" "); - if (pos != std::string::npos) { - str.erase(0, pos); - } + // Because some manufacturers have leading and/or trailing white space, + // we have to post-process the name. + auto const not_space = [](char c) { return c != ' '; }; + s.erase(s.begin(), std::find_if(s.begin(), s.end(), not_space)); + s.erase(std::find_if(s.rbegin(), s.rend(), not_space).base(), s.end()); } #endif @@ -2859,9 +2858,10 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() this->ChipID.ProcessorName = nbuf; this->ChipID.ModelName = nbuf; - // Because some manufacturers have leading white space - we have to - // post-process the name. - SystemInformationStripLeadingSpace(this->ChipID.ProcessorName); + // Because some manufacturers have leading and/or trailing white space, + // we have to post-process the names. + SystemInformationTrimSpace(this->ChipID.ProcessorName); + SystemInformationTrimSpace(this->ChipID.ModelName); return true; #else return false;