Proposal: cmStringAlgorithms: Add cmToStr class for formatted numeric to string conversion
The new class cmToStr
in cmStringAlgorithms.h
allows to convert numeric types to a formatted std::string
.
Its purpose is to replace std::ostringstream
for formatting numbers in CMake.
Example 1: Single formatted number
std::ostringstream v;
v << std::setfill('0') << std::setw(4) << this->XcodeVersion * 10;
return v.str();
can be replaced by
return cmToStr().Fill('0').Width(4).Get(this->XcodeVersion * 10);
Example 2: Hexadecimal number
std::ostringstream v;
v << std::setbase(16) << std::setfill('0') << " "
<< "0x" << std::setw(8) << number;
return v.str()
can be replaced by
return cmToStr().Hex().Fill('0').ShowBase().Width(8).Get(number);