diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2022-08-23 06:57:00 (GMT) |
---|---|---|
committer | Alex Turbov <i.zaufi@gmail.com> | 2022-11-17 12:37:09 (GMT) |
commit | f27537ec3db3a53a83da9d9824f10f139397476e (patch) | |
tree | f8389c524f371acd1f98bd80141f7da589b66353 | |
parent | 84241189f6a68611f79e9a3d78fc0192e1008cb1 (diff) | |
download | CMake-f27537ec3db3a53a83da9d9824f10f139397476e.zip CMake-f27537ec3db3a53a83da9d9824f10f139397476e.tar.gz CMake-f27537ec3db3a53a83da9d9824f10f139397476e.tar.bz2 |
cmDocumentationFormatter: Turn `TextWidth` member into `size_t`
Cuz normally required text width can't be negative. It was `int`…
-rw-r--r-- | Source/cmDocumentationFormatter.cxx | 16 | ||||
-rw-r--r-- | Source/cmDocumentationFormatter.h | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 8f0976c..85276fc 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -80,10 +80,12 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) { // Print text arranged in an indented column of fixed width. const char* l = text; - long column = 0; bool newSentence = false; bool firstLine = true; - int width = this->TextWidth - static_cast<int>(this->TextIndent); + + assert(this->TextIndent < this->TextWidth); + const std::ptrdiff_t width = this->TextWidth - this->TextIndent; + std::ptrdiff_t column = 0; // Loop until the end of the text. while (*l) { @@ -94,7 +96,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) } // Does it fit on this line? - if (r - l < (width - column - (newSentence ? 1 : 0))) { + if (r - l < width - column - std::ptrdiff_t(newSentence)) { // Word fits on this line. if (r > l) { if (column) { @@ -114,7 +116,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) } // Print the word. - os.write(l, static_cast<long>(r - l)); + os.write(l, r - l); newSentence = (*(r - 1) == '.'); } @@ -126,7 +128,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) firstLine = false; } else { // No provided newline. Continue this line. - column += static_cast<long>(r - l); + column += r - l; } } else { // Word does not fit on this line. Start a new line. @@ -134,8 +136,8 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) firstLine = false; if (r > l) { os << std::string(this->TextIndent, ' '); - os.write(l, static_cast<long>(r - l)); - column = static_cast<long>(r - l); + os.write(l, r - l); + column = r - l; newSentence = (*(r - 1) == '.'); } else { column = 0; diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 5293033..113db1e 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -21,6 +21,6 @@ public: void SetIndent(std::size_t indent) { this->TextIndent = indent; } private: - int TextWidth = 77; + std::size_t TextWidth = 77u; std::size_t TextIndent = 0u; }; |