Skip to content

Commit 0a7005d

Browse files
committed
Merge branch 'develop'
2 parents fb4f36f + 6bf4607 commit 0a7005d

File tree

9 files changed

+51
-3415
lines changed

9 files changed

+51
-3415
lines changed

include/boost/program_options.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef PROGRAM_OPTIONS_VP_2003_05_19
99
#define PROGRAM_OPTIONS_VP_2003_05_19
1010

11-
#if _MSC_VER >= 1020
11+
#if defined(_MSC_VER)
1212
#pragma once
1313
#endif
1414

include/boost/program_options/detail/value_semantic.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,9 @@ namespace boost { namespace program_options {
105105
int);
106106
#endif
107107
// For some reason, this declaration, which is require by the standard,
108-
// cause gcc 3.2 to not generate code to specialization defined in
108+
// cause msvc 7.1 to not generate code to specialization defined in
109109
// value_semantic.cpp
110-
#if ! ( ( BOOST_WORKAROUND(__GNUC__, <= 3) &&\
111-
BOOST_WORKAROUND(__GNUC_MINOR__, < 3) ) || \
112-
( BOOST_WORKAROUND(BOOST_MSVC, == 1310) ) \
113-
)
110+
#if ! ( BOOST_WORKAROUND(BOOST_MSVC, == 1310) )
114111
BOOST_PROGRAM_OPTIONS_DECL void validate(boost::any& v,
115112
const std::vector<std::string>& xs,
116113
std::string*,

include/boost/program_options/errors.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace boost { namespace program_options {
2525

2626
inline std::string strip_prefixes(const std::string& text)
2727
{
28-
return text.substr(text.find_last_of("-/") + 1);
28+
// "--foo-bar" -> "foo-bar"
29+
return text.substr(text.find_first_not_of("-/"));
2930
}
3031

3132
/** Base class for all errors in the library. */

include/boost/program_options/options_description.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ namespace program_options {
199199
*/
200200
options_description& add(const options_description& desc);
201201

202+
/** Find the maximum width of the option column, including options
203+
in groups. */
204+
unsigned get_option_column_width() const;
205+
202206
public:
203207
/** Returns an object of implementation-defined type suitable for adding
204208
options to options_description. The returned object will
@@ -229,7 +233,7 @@ namespace program_options {
229233

230234
/** Outputs 'desc' to the specified stream, calling 'f' to output each
231235
option_description element. */
232-
void print(std::ostream& os) const;
236+
void print(std::ostream& os, unsigned width = 0) const;
233237

234238
private:
235239
typedef std::map<std::string, int>::const_iterator name2index_iterator;

include/boost/program_options/variables_map.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace boost { namespace program_options {
9898
void store(const basic_parsed_options<char>& options,
9999
variables_map& m, bool);
100100

101-
friend BOOST_PROGRAM_OPTIONS_DECL class variables_map;
101+
friend class BOOST_PROGRAM_OPTIONS_DECL variables_map;
102102
};
103103

104104
/** Implements string->string mapping with convenient value casting

src/cmdline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ namespace boost { namespace program_options { namespace detail {
455455
// if they look like options
456456
if (opt.value.size() <= min_tokens)
457457
{
458-
min_tokens -= static_cast<unsigned>(opt.value.size());
458+
min_tokens -= static_cast<unsigned>(opt.value.size());
459459
}
460460
else
461461
{

src/options_description.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,9 @@ namespace boost { namespace program_options {
604604
}
605605
}
606606

607-
void
608-
options_description::print(std::ostream& os) const
607+
unsigned
608+
options_description::get_option_column_width() const
609609
{
610-
if (!m_caption.empty())
611-
os << m_caption << ":\n";
612-
613610
/* Find the maximum width of the option column */
614611
unsigned width(23);
615612
unsigned i; // vc6 has broken for loop scoping
@@ -620,6 +617,11 @@ namespace boost { namespace program_options {
620617
ss << " " << opt.format_name() << ' ' << opt.format_parameter();
621618
width = (max)(width, static_cast<unsigned>(ss.str().size()));
622619
}
620+
621+
/* Get width of groups as well*/
622+
for (unsigned j = 0; j < groups.size(); ++j)
623+
width = max(width, groups[j]->get_option_column_width());
624+
623625
/* this is the column were description should start, if first
624626
column is longer, we go to a new line */
625627
const unsigned start_of_description_column = m_line_length - m_min_description_length;
@@ -628,9 +630,20 @@ namespace boost { namespace program_options {
628630

629631
/* add an additional space to improve readability */
630632
++width;
631-
633+
return width;
634+
}
635+
636+
void
637+
options_description::print(std::ostream& os, unsigned width) const
638+
{
639+
if (!m_caption.empty())
640+
os << m_caption << ":\n";
641+
642+
if (!width)
643+
width = get_option_column_width();
644+
632645
/* The options formatting style is stolen from Subversion. */
633-
for (i = 0; i < m_options.size(); ++i)
646+
for (unsigned i = 0; i < m_options.size(); ++i)
634647
{
635648
if (belong_to_group[i])
636649
continue;
@@ -643,7 +656,8 @@ namespace boost { namespace program_options {
643656
}
644657

645658
for (unsigned j = 0; j < groups.size(); ++j) {
646-
os << "\n" << *groups[j];
659+
os << "\n";
660+
groups[j]->print(os, width);
647661
}
648662
}
649663

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ test-suite program_options :
3232
[ po-test split_test.cpp ]
3333
[ po-test unrecognized_test.cpp ]
3434
[ po-test required_test.cpp : required_test.cfg ]
35+
[ po-test exception_txt_test.cpp ]
3536
;
3637

3738
exe test_convert : test_convert.cpp ;

0 commit comments

Comments
 (0)