Go to the documentation of this file.00001
00002 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
00003
00004 #include <ostream>
00005 #include <iomanip>
00006
00007 namespace edm {
00008
00009 namespace {
00010 void wrapAndPrintLine(std::ostream& os, std::string const& text, size_t indent, size_t suggestedWidth) {
00011
00012 char oldFill = os.fill();
00013
00014 size_t length = text.size();
00015
00016
00017 size_t startLine = 0U;
00018
00019
00020 size_t startNextSearch = 0U;
00021
00022
00023 while (true) {
00024
00025
00026
00027 if ((length - startLine) <= suggestedWidth) {
00028 os << std::setfill(' ') << std::setw(indent) << "";
00029 if (startLine == 0) os << text;
00030 else os << text.substr(startLine);
00031 os << "\n";
00032 break;
00033 }
00034
00035
00036 size_t pos = text.find_first_of(' ', startNextSearch);
00037
00038
00039 if (pos == std::string::npos) {
00040
00041
00042
00043
00044 if (startNextSearch != startLine) {
00045 os << std::setfill(' ') << std::setw(indent) << "";
00046 os << text.substr(startLine, startNextSearch - startLine);
00047 os << "\n";
00048 startLine = startNextSearch;
00049 }
00050 os << std::setfill(' ') << std::setw(indent) << "";
00051 os << text.substr(startLine);
00052 os << "\n";
00053 break;
00054 }
00055
00056 if ((pos + 1U - startLine) > suggestedWidth) {
00057
00058
00059
00060
00061
00062 if (startNextSearch != startLine) {
00063 os << std::setfill(' ') << std::setw(indent) << "";
00064 os << text.substr(startLine, startNextSearch - startLine);
00065 os << "\n";
00066 startLine = startNextSearch;
00067 }
00068 if ((pos + 1U - startLine) > suggestedWidth) {
00069 os << std::setfill(' ') << std::setw(indent) << "";
00070 os << text.substr(startLine, pos + 1U - startLine);
00071 os << "\n";
00072 startLine = pos + 1U;
00073 }
00074 }
00075 startNextSearch = pos + 1U;
00076 }
00077 os.fill(oldFill);
00078 }
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 void DocFormatHelper::wrapAndPrintText(std::ostream& os,
00099 std::string const& text,
00100 size_t indent,
00101 size_t suggestedWidth) {
00102
00103 size_t pos = text.find_first_of('\n');
00104 if (pos == std::string::npos) {
00105
00106 wrapAndPrintLine(os, text, indent, suggestedWidth);
00107 } else {
00108
00109 wrapAndPrintLine(os, text.substr(0, pos), indent, suggestedWidth);
00110
00111 wrapAndPrintText(os, text.substr(pos + 1), indent, suggestedWidth);
00112 }
00113 }
00114
00115 void DocFormatHelper::init() {
00116 section_ = std::string();
00117 pass_ = 0;
00118 column1_ = 0;
00119 column2_ = 0;
00120 column3_ = 0;
00121 counter_ = 0;
00122 parent_ = OTHER;
00123 }
00124
00125 size_t DocFormatHelper::commentWidth() const {
00126
00127
00128
00129 size_t width = 30U;
00130 if (lineWidth() > startColumn2() + 30U) {
00131 width = lineWidth() - startColumn2();
00132 }
00133 return width;
00134 }
00135
00136 void DocFormatHelper::indent(std::ostream& os) const {
00137 char oldFill = os.fill();
00138 os << std::setfill(' ') << std::setw(indentation_) << "";
00139 os.fill(oldFill);
00140 }
00141
00142 void DocFormatHelper::indent2(std::ostream& os) const {
00143 char oldFill = os.fill();
00144 os << std::setfill(' ') << std::setw(startColumn2_) << "";
00145 os.fill(oldFill);
00146 }
00147 }