diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2022-08-23 07:38:45 (GMT) |
---|---|---|
committer | Alex Turbov <i.zaufi@gmail.com> | 2022-11-17 12:37:09 (GMT) |
commit | 21c3e2107d101954d6e2e60bbd2d660c6d95a455 (patch) | |
tree | e29dedfbb6ecb724b567aa42fee910bb43336570 | |
parent | c802bfc548c82e13c916b7e14fc81daa1c733213 (diff) | |
download | CMake-21c3e2107d101954d6e2e60bbd2d660c6d95a455.zip CMake-21c3e2107d101954d6e2e60bbd2d660c6d95a455.tar.gz CMake-21c3e2107d101954d6e2e60bbd2d660c6d95a455.tar.bz2 |
cmDocumentationFormatter: Turn `while ()` into `for ()` loop
-rw-r--r-- | Source/cmDocumentationFormatter.cxx | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 9d773e9..daa78f1 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -14,14 +14,33 @@ #include "cmDocumentationSection.h" #include "cmSystemTools.h" +namespace { +const char* skipSpaces(const char* ptr) +{ + assert(ptr); + for (; *ptr == ' '; ++ptr) { + ; + } + return ptr; +} +const char* skipToSpace(const char* ptr) +{ + assert(ptr); + for (; *ptr && (*ptr != '\n') && (*ptr != ' '); ++ptr) { + ; + } + return ptr; +} +} + void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) { if (!text) { return; } - const char* ptr = text; - while (*ptr) { + + for (const char* ptr = text; *ptr;) { // Any ptrs starting in a space are treated as preformatted text. std::string preformatted; while (*ptr == ' ') { @@ -79,7 +98,6 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os, void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) { // Print text arranged in an indented column of fixed width. - const char* l = text; bool newSentence = false; bool firstLine = true; @@ -88,13 +106,8 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) std::ptrdiff_t column = 0; // Loop until the end of the text. - while (*l) { - // Parse the next word. - const char* r = l; - while (*r && (*r != '\n') && (*r != ' ')) { - ++r; - } - + for (const char *l = text, *r = skipToSpace(text); *l; + l = skipSpaces(r), r = skipToSpace(l)) { // Does it fit on this line? if (r - l < width - column - std::ptrdiff_t(newSentence)) { // Word fits on this line. @@ -138,12 +151,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) column = 0; } } - // Move to beginning of next word. Skip over whitespace. - l = r; - while (*l == ' ') { - ++l; - } } } |