void Expressionizer::calculate_all_expressions(const std::string& i_str) { // __a_b__ -> __a_b__ // __a_b_ __a_b // _a_b__ a_b__ // _a_b_ a_b // // Store original -> __a_b__ OK // Remove leading _, store it -> _a_b__ OK // Remove trailing _, store it -> _a_b_ OK // Remove leading _, store it -> a_b_ OK // Remove trailing _, store it -> a_b OK // Repeat, starting with trailing -> __a_b_ OK, _a_b_ DUP, _a_b OK, a_b DUP if (i_str.size() < 2) // || i_str.find_first_not_of("_") == std::string::npos) { return; } StringSet permutations; generate_permutations(i_str, permutations); for (StringSet::const_iterator it = permutations.begin() ; it != permutations.end() ; ++it) { Expression e(*it); m_expression_seq.push_back(e); } }
static void generate_permutations(const std::string& i_str, StringSet& permutations) { permutations.insert(i_str); bool starts_with_wildcard(char_to_modifier(*i_str.begin()) != InvalidModifier), ends_with_wildcard(char_to_modifier(*i_str.rbegin()) != InvalidModifier); if (!starts_with_wildcard && !ends_with_wildcard) { return; } else { if (starts_with_wildcard) { generate_permutations(i_str.substr(1), permutations); // _xxxx -> xxxx } if (ends_with_wildcard) { generate_permutations(i_str.substr(0, i_str.size()-1), permutations); // xxxx_ -> xxxx } } }
int main(int argc, char *argv[]){ if (argc > 1){ generate_permutations(argv[1]); } return 1; }