]>
cygwin.com Git - cygwin-apps/setup.git/blob - libgetopt++/include/getopt++/DefaultFormatter.h
b73481627163faf0ae2ca6b8d4d7c707816b39ba
2 * Copyright (c) 2003 Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <robertc@hotmail.com>
16 #ifndef _GETOPT___DEFAULTFORMATTER_H_
17 #define _GETOPT___DEFAULTFORMATTER_H_
21 #include "getopt++/Option.h"
23 /* Show the options on the left, the short description on the right.
24 * Option display must be < o_len characters in length.
25 * Descriptions must be < h_len characters in length.
26 * For compatibility with default terminal width o_len + h_len <= 80.
28 class DefaultFormatter
{
30 const unsigned int o_len
;
31 const unsigned int h_len
;
32 const std::string s_lead
;
33 const std::string l_lead
;
34 std::ostream
&theStream
;
37 DefaultFormatter (std::ostream
&aStream
, StrLookup aLookup
)
38 : o_len(35), h_len(45),
39 s_lead(" -"), l_lead(" --"),
40 theStream(aStream
), strLookup(aLookup
)
42 DefaultFormatter (std::ostream
&aStream
, StrLookup aLookup
,
43 unsigned int o_len
, unsigned int h_len
,
44 std::string s_lead
, std::string l_lead
)
45 : o_len(o_len
), h_len(h_len
),
46 s_lead(s_lead
), l_lead(l_lead
),
47 theStream(aStream
), strLookup(aLookup
)
49 void operator () (Option
*anOption
) {
50 if (anOption
->shortOption ()[0] == '\0')
53 theStream
<< s_lead
<< anOption
->shortOption ()[0];
55 std::string longOption
= anOption
->longOptionPrefixes ()[0] +
56 anOption
->longOption ();
58 theStream
<< l_lead
<< longOption
60 - s_lead
.size () - 1 - l_lead
.size ()
61 - longOption
.size (), ' ');
62 std::string helpmsg
= strLookup(anOption
->shortHelp());
63 while (helpmsg
.size() > h_len
)
65 size_t pos
= helpmsg
.substr(0,h_len
).find_last_of(" ");
66 // if there's no space character, working out where to line-break
67 // composing UTF-8 characters is hard, so don't bother trying...
68 if (pos
== std::string::npos
)
70 theStream
<< helpmsg
.substr(0,pos
)
71 << std::endl
<< std::string (o_len
, ' ');
72 helpmsg
.erase (0,pos
+1);
74 theStream
<< helpmsg
<< std::endl
;
78 #endif // _GETOPT___DEFAULTFORMATTER_H_
This page took 0.047894 seconds and 6 git commands to generate.