File indexing completed on 2023-03-17 11:03:25
0001
0002 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
0003
0004 #include <ostream>
0005 #include <iomanip>
0006
0007 namespace edm {
0008
0009 namespace {
0010 void wrapAndPrintLine(std::ostream& os, std::string const& text, size_t indent, size_t suggestedWidth) {
0011 char oldFill = os.fill();
0012
0013 size_t length = text.size();
0014
0015
0016 size_t startLine = 0U;
0017
0018
0019 size_t startNextSearch = 0U;
0020
0021
0022 while (true) {
0023
0024
0025 if ((length - startLine) <= suggestedWidth) {
0026 os << std::setfill(' ') << std::setw(indent) << "";
0027 if (startLine == 0)
0028 os << text;
0029 else
0030 os << text.substr(startLine);
0031 os << "\n";
0032 break;
0033 }
0034
0035
0036 size_t pos = text.find_first_of(' ', startNextSearch);
0037
0038
0039 if (pos == std::string::npos) {
0040
0041
0042
0043
0044 if (startNextSearch != startLine) {
0045 os << std::setfill(' ') << std::setw(indent) << "";
0046 os << text.substr(startLine, startNextSearch - startLine);
0047 os << "\n";
0048 startLine = startNextSearch;
0049 }
0050 os << std::setfill(' ') << std::setw(indent) << "";
0051 os << text.substr(startLine);
0052 os << "\n";
0053 break;
0054 }
0055
0056 if ((pos + 1U - startLine) > suggestedWidth) {
0057
0058
0059
0060
0061 if (startNextSearch != startLine) {
0062 os << std::setfill(' ') << std::setw(indent) << "";
0063 os << text.substr(startLine, startNextSearch - startLine);
0064 os << "\n";
0065 startLine = startNextSearch;
0066 }
0067 if ((pos + 1U - startLine) > suggestedWidth) {
0068 os << std::setfill(' ') << std::setw(indent) << "";
0069 os << text.substr(startLine, pos + 1U - startLine);
0070 os << "\n";
0071 startLine = pos + 1U;
0072 }
0073 }
0074 startNextSearch = pos + 1U;
0075 }
0076 os.fill(oldFill);
0077 }
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 void DocFormatHelper::wrapAndPrintText(std::ostream& os,
0098 std::string const& text,
0099 size_t indent,
0100 size_t suggestedWidth) {
0101 size_t pos = text.find_first_of('\n');
0102 if (pos == std::string::npos) {
0103
0104 wrapAndPrintLine(os, text, indent, suggestedWidth);
0105 } else {
0106
0107 wrapAndPrintLine(os, text.substr(0, pos), indent, suggestedWidth);
0108
0109 wrapAndPrintText(os, text.substr(pos + 1), indent, suggestedWidth);
0110 }
0111 }
0112
0113 void DocFormatHelper::init() {
0114 section_ = std::string();
0115 pass_ = 0;
0116 column1_ = 0;
0117 column2_ = 0;
0118 column3_ = 0;
0119 counter_ = 0;
0120 parent_ = OTHER;
0121 }
0122
0123 size_t DocFormatHelper::commentWidth() const {
0124
0125
0126 size_t width = 30U;
0127 if (lineWidth() > startColumn2() + 30U) {
0128 width = lineWidth() - startColumn2();
0129 }
0130 return width;
0131 }
0132
0133 void DocFormatHelper::indent(std::ostream& os) const {
0134 char oldFill = os.fill();
0135 os << std::setfill(' ') << std::setw(indentation_) << "";
0136 os.fill(oldFill);
0137 }
0138
0139 void DocFormatHelper::indent2(std::ostream& os) const {
0140 char oldFill = os.fill();
0141 os << std::setfill(' ') << std::setw(startColumn2_) << "";
0142 os.fill(oldFill);
0143 }
0144 }