cmSystemTools: Fix TrimWhitespace for non-ascii strings (#15735)
Since commit v2.8.11~59^2 (cmSystemTools: Generalize TrimWhitespace to all whitespace, 2013-03-27) we incorrectly use `c <= ' '` to determine if `c` is a whitespace character. With a signed `char` type UTF-8 encoded strings may be truncated because values above 0x7f appear negative and therefore less than 0x20. Use `isspace(c)` instead.
This commit is contained in:
parent
87a9061d57
commit
9c4a500f75
|
@ -233,13 +233,13 @@ std::string cmSystemTools::HelpFileName(std::string name)
|
||||||
std::string cmSystemTools::TrimWhitespace(const std::string& s)
|
std::string cmSystemTools::TrimWhitespace(const std::string& s)
|
||||||
{
|
{
|
||||||
std::string::const_iterator start = s.begin();
|
std::string::const_iterator start = s.begin();
|
||||||
while(start != s.end() && *start <= ' ')
|
while (start != s.end() && cm_isspace(*start))
|
||||||
++start;
|
++start;
|
||||||
if (start == s.end())
|
if (start == s.end())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::string::const_iterator stop = s.end()-1;
|
std::string::const_iterator stop = s.end()-1;
|
||||||
while(*stop <= ' ')
|
while (cm_isspace(*stop))
|
||||||
--stop;
|
--stop;
|
||||||
return std::string(start, stop+1);
|
return std::string(start, stop+1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue