Skip to content
Snippets Groups Projects
Commit ef0ad34d authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'CmdLineArgs-strings'


88d4dd4b CommandLineArguments: use std::string in GenerateHelp()

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !60
parents 7890c0cc 88d4dd4b
No related branches found
No related tags found
No related merge requests found
...@@ -529,10 +529,7 @@ void CommandLineArguments::GenerateHelp() ...@@ -529,10 +529,7 @@ void CommandLineArguments::GenerateHelp()
} }
} }
// Create format for that string CommandLineArguments::Internal::String::size_type maxstrlen = maxlen;
char format[80];
sprintf(format, " %%-%us ", static_cast<unsigned int>(maxlen));
maxlen += 4; // For the space before and after the option maxlen += 4; // For the space before and after the option
// Print help for each option // Print help for each option
...@@ -540,27 +537,24 @@ void CommandLineArguments::GenerateHelp() ...@@ -540,27 +537,24 @@ void CommandLineArguments::GenerateHelp()
CommandLineArguments::Internal::SetOfStrings::iterator sit; CommandLineArguments::Internal::SetOfStrings::iterator sit;
for (sit = mpit->second.begin(); sit != mpit->second.end(); sit++) { for (sit = mpit->second.begin(); sit != mpit->second.end(); sit++) {
str << std::endl; str << std::endl;
char argument[100]; std::string argument = *sit;
sprintf(argument, "%s", sit->c_str());
switch (this->Internals->Callbacks[*sit].ArgumentType) { switch (this->Internals->Callbacks[*sit].ArgumentType) {
case CommandLineArguments::NO_ARGUMENT: case CommandLineArguments::NO_ARGUMENT:
break; break;
case CommandLineArguments::CONCAT_ARGUMENT: case CommandLineArguments::CONCAT_ARGUMENT:
strcat(argument, "opt"); argument += "opt";
break; break;
case CommandLineArguments::SPACE_ARGUMENT: case CommandLineArguments::SPACE_ARGUMENT:
strcat(argument, " opt"); argument += " opt";
break; break;
case CommandLineArguments::EQUAL_ARGUMENT: case CommandLineArguments::EQUAL_ARGUMENT:
strcat(argument, "=opt"); argument += "=opt";
break; break;
case CommandLineArguments::MULTI_ARGUMENT: case CommandLineArguments::MULTI_ARGUMENT:
strcat(argument, " opt opt ..."); argument += " opt opt ...";
break; break;
} }
char buffer[80]; str << " " << argument.substr(0, maxstrlen) << " ";
sprintf(buffer, format, argument);
str << buffer;
} }
const char* ptr = this->Internals->Callbacks[mpit->first].Help; const char* ptr = this->Internals->Callbacks[mpit->first].Help;
size_t len = strlen(ptr); size_t len = strlen(ptr);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment