diff -r1.6 options_description.hpp 99c99 < --- > 144c144,145 < --- > static const unsigned m_default_line_length = 80; > 146c147 < options_description(); --- > options_description(unsigned line_length = m_default_line_length); 150c151,152 < options_description(const std::string& caption); --- > options_description(const std::string& caption, > unsigned line_length = m_default_line_length); 213a216 > const unsigned m_line_length; diff -r1.6 options_description.cpp 14a15 > #include 153c154,155 < options_description::options_description() --- > options_description::options_description(unsigned line_length) > : m_line_length(line_length) 156,157c158,160 < options_description::options_description(const string& caption) < : m_caption(caption) --- > options_description::options_description(const string& caption, > unsigned line_length) > : m_caption(caption), m_line_length(line_length) 279c282 < unsigned first_column_width) --- > unsigned first_column_width, unsigned line_length) 286,287c289,308 < < if (!opt.description().empty()) { --- > > if (!opt.description().empty()) > { > typedef boost::tokenizer > tokenizer; > > // we need to use one char less per line to work correctly if actual > // console has longer lines > assert(line_length > 1); > line_length = (line_length > 1 ? --line_length : 1); > > // line_length must be larger that first_column_width > assert(line_length > first_column_width); > > tokenizer paragraphs(opt.description(), > char_separator("\n", "", boost::keep_empty_tokens)); > > tokenizer::const_iterator pi = paragraphs.begin(); > const tokenizer::const_iterator pe = paragraphs.end(); > > bool first_descrption_line = true; 289,292c310,433 < for(int pad = first_column_width - ss.str().size(); pad > 0; --pad) { < os.put(' '); < } < os << " : " << opt.description(); --- > while (pi != pe) // paragraphs > { > string par = *pi; > > unsigned new_indent = 0; > > // only one indent per paragraph makes sens, we use the last one > string::size_type tab = par.find_last_of('\t'); > > if (tab != string::npos) > { > // leading '\t' do not count for indent length! > new_indent = tab - (count(par.begin(), par.end(), '\t') - 1); > } > > // remove all '\t' > while (tab != string::npos) > { > par.erase(tab, 1); > > tab = par.find('\t'); > } > > unsigned indent = first_column_width; > > // first line of a option description (not paragraph!) has a different indent! > if (first_descrption_line) > { > first_descrption_line = false; > > for(int pad = first_column_width - ss.str().size(); pad > 0; --pad) > { > os.put(' '); > } > } > else > { > os << '\n'; > > for(int pad = indent; pad > 0; --pad) > { > os.put(' '); > } > } > > unsigned slice = line_length - indent; > > if (par.size() < slice) > { > os << par; > } > else > { > string::const_iterator i = par.begin(); > const string::const_iterator e = par.end(); > > bool first_line = true; // of current paragraph! > > while (i < e) // paragraph lines (slice) > { > if (!first_line) > { > // trimm leading single spaces > if ((*i == ' ') && > ((i + 1 < e) && (*(i + 1) != ' '))) > { > i += 1; > > // trimm slice if out of bounds > if (i + slice > e) > { > slice -= 1; > } > } > } > > // prevent chopped words > // if (lastchar != ' ') && > // (exists(lastchar + 1) && (lastchar + 1 != ' ') > if ((*(i + (slice - 1)) != ' ') && > (((i + slice) < e) && (*(i + slice) != ' '))) > { > // find last ' ' in current paragraph slice > string::size_type ls = par.find_last_of(' ', (i - par.begin()) + slice); > > if (ls != string::npos) > { > // convert ls to iterator > string::const_iterator last_space = par.begin() + ls; > > // is last_space within the second half ot the current slice > if (last_space > i + (slice / 2)) > { > slice = last_space - i; > } > } > } // prevent chopped words > > os << string(i, i + slice); > > i += slice; > > if (first_line) > { > indent = first_column_width + new_indent; > first_line = false; > } > > if (i < e) > { > slice = min(line_length - indent, e - i); > > os << '\n'; > > for(int pad = indent; pad > 0; --pad) > { > os.put(' '); > } > } > } // paragraph lines (slice) > } > > ++pi; > } 322c463 < format_one(os, opt, width); --- > format_one(os, opt, width, m_line_length);