Skip to content

Commit

Permalink
Clean up mod command-line parsing
Browse files Browse the repository at this point in the history
The test executable had custom string splitting code.  Use the generic
string_split instead.
  • Loading branch information
jbytheway committed Dec 15, 2019
1 parent 0ad5ea7 commit 8d06ce0
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "worldfactory.h"
#include "color.h"
#include "options.h"
#include "output.h"
#include "pldata.h"
#include "rng.h"
#include "type_id.h"
Expand Down Expand Up @@ -68,26 +69,15 @@ static std::string extract_argument( std::vector<const char *> &arg_vec, const s

static std::vector<mod_id> extract_mod_selection( std::vector<const char *> &arg_vec )
{
std::vector<mod_id> ret;
std::string mod_string = extract_argument( arg_vec, "--mods=" );

const char delim = ',';
size_t i = 0;
size_t pos = mod_string.find( delim );
if( pos == std::string::npos && !mod_string.empty() ) {
ret.emplace_back( mod_string );
}

while( pos != std::string::npos ) {
ret.emplace_back( mod_string.substr( i, pos - i ) );
i = ++pos;
pos = mod_string.find( delim, pos );

if( pos == std::string::npos ) {
ret.emplace_back( mod_string.substr( i, mod_string.length() ) );
std::vector<std::string> mod_names = string_split( mod_string, ',' );
std::vector<mod_id> ret;
for( const std::string mod_name : mod_names ) {
if( !mod_name.empty() ) {
ret.emplace_back( mod_name );
}
}

return ret;
}

Expand Down

0 comments on commit 8d06ce0

Please sign in to comment.