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