Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#2613 closed Bugs (fixed)

Default arguments break word-wrapping.

Reported by: Peter Simons Owned by: Vladimir Prus
Milestone: Boost 1.42.0 Component: program_options
Version: Boost 1.37.0 Severity: Problem
Keywords: Cc: simons@…, s.ochsenknecht@…

Description

The attached example program demonstrates the problem.

Attachments (2)

test.cpp​ (514 bytes ) - added by anonymous 14 years ago.
Run to see the broken help output.
patch_ticket2613.diff​ (2.7 KB ) - added by s.ochsenknecht@… 13 years ago.
patch

Download all attachments as: .zip

Change History (9)

by anonymous, 14 years ago

Attachment: test.cpp​ added

Run to see the broken help output.

comment:1 by Vladimir Prus, 14 years ago

Please specify how the produced output differs from expected output, and why you expect the output you expect.

in reply to:  1 comment:2 by Peter Simons, 14 years ago

With Boost 1.37.0, the attached program generates the following output:

$ g++ test.cpp -lboost_program_options && ./a.out
| Supported options:
|   --help                          this is a sufficiently long text to requ
|                                   ire word-wrapping

Look closely at the description of the "--help" option. You'll find that word-wrapping is performed in the middle of the word, i.e. "require" is broken apart as "requ-ire". This is contrary to what I expect because of the rules of syllabication, which you'll find described at ​http://en.wikipedia.org/wiki/Syllabification. Now, those rules are somewhat complex and might be considered beyond the scope of a command-line argument parsing library. Thus, most code that needs to perform word-wrapping opts to use a simpler approximation, i.e. to break lines apart at *whitespace*. If you check out your source code, "options_description.cpp", you'll find that you have implemented an algorithm that does this, but unfortunately it appears that your code fails to take the length of the default argument into account. I say this because the algorithm works just fine when there's no default argument. When there is one, word-wrapping does not work fine.

If you need further clarification, please don't hesitate to ask.

by s.ochsenknecht@…, 13 years ago

Attachment: patch_ticket2613.diff​ added

patch

comment:3 by s.ochsenknecht@…, 13 years ago

I just attached a patch which improves the word wrapping (small fix). I also added a test case for word wrapping.

Please comment.

comment:4 by s.ochsenknecht@…, 13 years ago

Cc: s.ochsenknecht@… added

comment:5 by Peter Simons, 13 years ago

Milestone: Boost 1.38.0 → Boost 1.41.0

The patch applies cleanly to the current SVN HEAD, and it does fix the problem in my test program. Looks good to me. Thank you very much.

comment:6 by Vladimir Prus, 13 years ago

Resolution: → fixed
Status: new → closed

(In [57517]) Fix wordwrapping in presense of default parameters.

Fixes #2613. Patch from Sascha Ochsenknecht.

comment:7 by Sascha Ochsenknecht, 13 years ago

Milestone: Boost 1.41.0 → Boost 1.42.0
Note: See TracTickets for help on using tickets.