diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/cmDocumentationFormatter.cxx | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Source/cmDocumentationFormatter.cxx')
-rw-r--r-- | Source/cmDocumentationFormatter.cxx | 169 |
1 files changed, 68 insertions, 101 deletions
diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 6869e2f..4816bb9 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -13,8 +13,9 @@ #include "cmDocumentationSection.h" -cmDocumentationFormatter::cmDocumentationFormatter(): - TextWidth(77), TextIndent("") +cmDocumentationFormatter::cmDocumentationFormatter() + : TextWidth(77) + , TextIndent("") { } @@ -25,67 +26,55 @@ cmDocumentationFormatter::~cmDocumentationFormatter() void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) { - if(!text) - { + if (!text) { return; - } + } const char* ptr = text; - while(*ptr) - { + while (*ptr) { // Any ptrs starting in a space are treated as preformatted text. std::string preformatted; - while(*ptr == ' ') - { - for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr) - { + while (*ptr == ' ') { + for (char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr) { preformatted.append(1, ch); - } - if(*ptr) - { + } + if (*ptr) { ++ptr; preformatted.append(1, '\n'); - } } - if(!preformatted.empty()) - { + } + if (!preformatted.empty()) { this->PrintPreformatted(os, preformatted.c_str()); - } + } // Other ptrs are treated as paragraphs. std::string paragraph; - for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr) - { + for (char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr) { paragraph.append(1, ch); - } - if(*ptr) - { + } + if (*ptr) { ++ptr; paragraph.append(1, '\n'); - } - if(!paragraph.empty()) - { + } + if (!paragraph.empty()) { this->PrintParagraph(os, paragraph.c_str()); - } } + } } void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, - const char* text) + const char* text) { bool newline = true; - for(const char* ptr = text; *ptr; ++ptr) - { - if(newline && *ptr != '\n') - { + for (const char* ptr = text; *ptr; ++ptr) { + if (newline && *ptr != '\n') { os << this->TextIndent; newline = false; - } + } os << *ptr; - if(*ptr == '\n') - { + if (*ptr == '\n') { newline = true; - } } + } os << "\n"; } @@ -102,8 +91,7 @@ void cmDocumentationFormatter::SetIndent(const char* indent) this->TextIndent = indent; } -void cmDocumentationFormatter::PrintColumn(std::ostream& os, - const char* text) +void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) { // Print text arranged in an indented column of fixed witdh. const char* l = text; @@ -113,118 +101,97 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent)); // Loop until the end of the text. - while(*l) - { + while (*l) { // Parse the next word. const char* r = l; - while(*r && (*r != '\n') && (*r != ' ')) { ++r; } + while (*r && (*r != '\n') && (*r != ' ')) { + ++r; + } // Does it fit on this line? - if(r-l < (width-column-(newSentence?1:0))) - { + if (r - l < (width - column - (newSentence ? 1 : 0))) { // Word fits on this line. - if(r > l) - { - if(column) - { + if (r > l) { + if (column) { // Not first word on line. Separate from the previous word // by a space, or two if this is a new sentence. - if(newSentence) - { + if (newSentence) { os << " "; column += 2; - } - else - { + } else { os << " "; column += 1; - } } - else - { + } else { // First word on line. Print indentation unless this is the // first line. - os << (firstLine?"":this->TextIndent); - } + os << (firstLine ? "" : this->TextIndent); + } // Print the word. - os.write(l, static_cast<long>(r-l)); - newSentence = (*(r-1) == '.'); - } + os.write(l, static_cast<long>(r - l)); + newSentence = (*(r - 1) == '.'); + } - if(*r == '\n') - { + if (*r == '\n') { // Text provided a newline. Start a new line. os << "\n"; ++r; column = 0; firstLine = false; - } - else - { + } else { // No provided newline. Continue this line. - column += static_cast<long>(r-l); - } + column += static_cast<long>(r - l); } - else - { + } else { // Word does not fit on this line. Start a new line. os << "\n"; firstLine = false; - if(r > l) - { + if (r > l) { os << this->TextIndent; - os.write(l, static_cast<long>(r-l)); - column = static_cast<long>(r-l); - newSentence = (*(r-1) == '.'); - } - else - { + os.write(l, static_cast<long>(r - l)); + column = static_cast<long>(r - l); + newSentence = (*(r - 1) == '.'); + } else { column = 0; - } } + } // Move to beginning of next word. Skip over whitespace. l = r; - while(*l && (*l == ' ')) { ++l; } + while (*l && (*l == ' ')) { + ++l; } + } } -void cmDocumentationFormatter -::PrintSection(std::ostream& os, - cmDocumentationSection const& section) +void cmDocumentationFormatter::PrintSection( + std::ostream& os, cmDocumentationSection const& section) { os << section.GetName() << "\n"; - const std::vector<cmDocumentationEntry> &entries = - section.GetEntries(); - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end(); ++op) - { - if(!op->Name.empty()) - { + const std::vector<cmDocumentationEntry>& entries = section.GetEntries(); + for (std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); + op != entries.end(); ++op) { + if (!op->Name.empty()) { os << " " << op->Name; this->TextIndent = " "; - int align = static_cast<int>(strlen(this->TextIndent))-4; - for(int i = static_cast<int>(op->Name.size()); i < align; ++i) - { + int align = static_cast<int>(strlen(this->TextIndent)) - 4; + for (int i = static_cast<int>(op->Name.size()); i < align; ++i) { os << " "; - } - if (op->Name.size() > strlen(this->TextIndent)-4 ) - { + } + if (op->Name.size() > strlen(this->TextIndent) - 4) { os << "\n"; - os.write(this->TextIndent, strlen(this->TextIndent)-2); - } + os.write(this->TextIndent, strlen(this->TextIndent) - 2); + } os << "= "; this->PrintColumn(os, op->Brief.c_str()); os << "\n"; - } - else - { + } else { os << "\n"; this->TextIndent = ""; this->PrintFormatted(os, op->Brief.c_str()); - } } + } os << "\n"; } |