38 #include "blocxx/BLOCXX_config.h"
48 namespace BLOCXX_NAMESPACE
75 shortOptIs(
char shortOpt) :
m_shortOpt(shortOpt) {}
77 bool operator()(
const CmdLineParser::Option& x)
const
93 char const*
const* argv = argv_;
94 char const*
const* argvEnd = argv + argc;
97 const Option* optionsEnd(options);
105 while (argv != argvEnd)
111 if ((arg.
length() >= 2) && (arg[0] ==
'-'))
114 bool longOpt =
false;
131 theOpt = std::find_if (options, optionsEnd, longOptIs(argNoVal));
137 theOpt = std::find_if (options, optionsEnd, shortOptIs(arg[0]));
140 if (theOpt == optionsEnd)
158 const char* p = ::strchr(arg.
c_str(),
'=');
167 if (longOpt ==
false && arg.
length() > 1)
172 else if (argv+1 != argvEnd)
175 if ( **(argv+1) !=
'-' || (**(argv+1) ==
'-' &&
String(*(argv+1)).length() == 1) )
217 const unsigned int NUM_OPTION_COLUMNS = 28;
221 for (
const Option* curOption = options; curOption->
shortopt !=
'\0' || curOption->longopt != 0; ++curOption)
225 if (curOption->shortopt !=
'\0')
228 curLine += curOption->shortopt;
229 if (curOption->longopt != 0)
234 if (curOption->longopt != 0)
237 curLine += curOption->longopt;
249 size_t bufferlen = (curLine.
length() >= NUM_OPTION_COLUMNS-1) ? 1 : (NUM_OPTION_COLUMNS - curLine.
length());
250 for (
size_t i = 0;
i < bufferlen; ++
i)
255 if (curOption->description != 0)
257 curLine += curOption->description;
260 if (curOption->defaultValue != 0)
262 curLine +=
" (default is ";
263 curLine += curOption->defaultValue;
272 size_t newlineIdx = curLineStr.
indexOf(
'\n');
275 size_t lastSpaceIdx = curLineStr.lastIndexOf(
' ', maxColumns);
278 size_t nextLineBeginIdx = 0;
279 if (newlineIdx <= maxColumns)
282 nextLineBeginIdx = newlineIdx + 1;
284 else if (lastSpaceIdx > NUM_OPTION_COLUMNS)
286 cutIdx = lastSpaceIdx;
287 nextLineBeginIdx = lastSpaceIdx + 1;
293 nextLineBeginIdx = maxColumns;
297 usage += curLineStr.substring(0, cutIdx);
302 for (
size_t i = 0;
i < NUM_OPTION_COLUMNS; ++
i)
323 return ci->second[ci->second.size()-1];
336 return ci->second[ci->second.size()-1];