Index: options_description.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/program_options/src/options_description.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -p -r1.14 -r1.15 --- options_description.cpp 13 Jul 2005 16:32:40 -0000 1.14 +++ options_description.cpp 22 Dec 2005 09:29:14 -0000 1.15 @@ -291,11 +291,26 @@ namespace boost { namespace program_opti namespace { + /* Given a string 'par', that contains no newline characters + outputs it to 'os' with wordwrapping, that is, as several + line. + + Each output line starts with 'indent' space characters, + following by characters from 'par'. The total length of + line is no longer than 'line_length'. + + */ void format_paragraph(std::ostream& os, std::string par, - unsigned first_column_width, + unsigned indent, unsigned line_length) { + // Through reminder of this function, 'line_length' will + // be the length available for characters, not including + // indent. + assert(indent < line_length); + line_length -= indent; + // index of tab (if present) is used as additional indent relative // to first_column_width if paragrapth is spanned over multiple // lines if tab is not on first line it is ignored @@ -319,16 +334,16 @@ namespace boost { namespace program_opti // this assert may fail due to user error or // environment conditions! - assert(par_indent < (line_length - first_column_width)); + assert(par_indent < line_length); // ignore tab if not on first line - if (par_indent >= (line_length - first_column_width)) + if (par_indent >= line_length) { par_indent = 0; } } - if (par.size() < (line_length - first_column_width)) + if (par.size() < line_length) { os << par; } @@ -337,17 +352,16 @@ namespace boost { namespace program_opti string::const_iterator line_begin = par.begin(); const string::const_iterator par_end = par.end(); - bool first_line = true; // of current paragraph! - - unsigned indent = first_column_width; + bool first_line = true; // of current paragraph! while (line_begin < par_end) // paragraph lines { if (!first_line) { - // trimm leading single spaces - // if (firstchar == ' ') && - // ((exists(firstchar + 1) && (firstchar + 1 != ' ')) + // If line starts with space, but second character + // is not space, remove the leading space. + // We don't remove double spaces because those + // might be intentianal. if ((*line_begin == ' ') && ((line_begin + 1 < par_end) && (*(line_begin + 1) != ' '))) @@ -357,30 +371,26 @@ namespace boost { namespace program_opti } string::const_iterator line_end; - - if (line_begin + (line_length - indent) > par_end) + + line_end = line_begin + line_length; + if (line_end > par_end) { line_end = par_end; } - else - { - line_end = line_begin + (line_length - indent); - } // prevent chopped words - // if (lastchar != ' ') && - // ((exists(lastchar + 1) && (lastchar + 1 != ' ')) + // Is line_end between two non-space characters? if ((*(line_end - 1) != ' ') && ((line_end < par_end) && (*line_end != ' '))) { // find last ' ' in the second half of the current paragraph line string::const_iterator last_space = - find(reverse_iterator(line_end - 1), - reverse_iterator(line_begin - 1), + find(reverse_iterator(line_end), + reverse_iterator(line_begin), ' ') .base(); - if (last_space != line_begin - 1) + if (last_space != line_begin) { // is last_space within the second half ot the // current line @@ -397,7 +407,7 @@ namespace boost { namespace program_opti if (first_line) { - indent = first_column_width + par_indent; + indent += par_indent; first_line = false; } @@ -436,7 +446,7 @@ namespace boost { namespace program_opti assert(line_length > first_column_width); // Note: can't use 'tokenizer' as name of typedef -- borland - // will consider subsequence uses of 'tokenizer' as uses of + // will consider uses of 'tokenizer' below as uses of // boost::tokenizer, not typedef. typedef boost::tokenizer > tok;