/** * @brief: Compute all the permutations of the given string that has all * unique characters. * @param: [in] str: The given string whose permutations will be computed. * @return: StringVect * A list of all the permutations of the given string. */ StringVect permutation_str_no_dup(const std::string & str) { const int STR_SIZE = static_cast<int>(str.size()); // Handle special cases. if (STR_SIZE == 0) { // If str is empty, return an empty set. return StringVect(); } else if (STR_SIZE == 1) { // One-char string has only one permutation which is itself. return StringVect(1, str); } // Now the STR_SIZE > 1. // Compute the permutations. char ch = str[0]; StringVect sub_perms = permutation_str_no_dup(str.substr(1)); // Insert ch to every possible position of perms. StringVect perms; for (size_t i = 0; i < sub_perms.size(); ++i) { const std::string & subperm = sub_perms[i]; for (size_t j = 0; j < subperm.size(); ++j) { std::string replica(subperm); replica.insert(replica.begin() + j, ch); perms.push_back(replica); } // Finally, we need to insert ch to the end of replica. std::string replica(subperm); replica.push_back(ch); perms.push_back(replica); } return perms; }
bool SDL::getAllVideoModes(StringVect &modeList) { std::set<std::string> modes; for (int display = 0; display < 100; display ++) { const int numModes = SDL_GetNumDisplayModes(display); if (numModes > 0) { logger->log("Modes for display %d", display); for (int f = 0; f < numModes; f ++) { SDL_DisplayMode mode; SDL_GetDisplayMode(display, f, &mode); const int w = mode.w; const int h = mode.h; logger->log("%dx%dx%d", w, h, mode.refresh_rate); modes.insert(strprintf("%dx%d", w, h)); } } } FOR_EACH (std::set<std::string>::const_iterator, it, modes) modeList.push_back(*it); return true; }
void GuildChatTab::getAutoCompleteList(StringVect &names) const { if (!guildManager) return; guildManager->getNames(names); names.push_back("/notice "); }
// ---------------------------------------------------------------------------- int read_n_lines(std::fstream & fs, int N, StringVect & lines) { lines.clear(); int K = 0; while (!fs.eof() && K < N) { std::string line; std::getline(fs, line); lines.push_back(line); ++K; } return K; }
void ModeListModel::addCustomMode(std::string mode) { StringVectCIter it = mVideoModes.begin(); StringVectCIter it_end = mVideoModes.end(); while (it != it_end) { if (*it == mode) return; ++ it; } mVideoModes.push_back(mode); }
void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) { mCharCreateDialog = window; if (!mCharCreateDialog) return; StringVect attributes; attributes.push_back(_("Strength:")); attributes.push_back(_("Agility:")); attributes.push_back(_("Vitality:")); attributes.push_back(_("Intelligence:")); attributes.push_back(_("Dexterity:")); attributes.push_back(_("Luck:")); const Token &token = static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); int minStat = CharDB::getMinStat(); if (!minStat) minStat = 1; int maxStat = CharDB::getMaxStat(); if (!maxStat) maxStat = 9; int sumStat = CharDB::getSumStat(); if (!sumStat) sumStat = 30; mCharCreateDialog->setAttributes(attributes, sumStat, minStat, maxStat); mCharCreateDialog->setFixedGender(true, token.sex); }
std::string Wallpaper::getWallpaper(const int width, const int height) { WallpaperData wp; // Wallpaper filename container StringVect wallPaperVector; FOR_EACH (std::vector<WallpaperData>::const_iterator, iter, wallpaperData) { wp = *iter; if (wp.width <= width && wp.height <= height) wallPaperVector.push_back(wp.filename); }
void Guild::getNames(StringVect &names) const { names.clear(); MemberList::const_iterator it = mMembers.begin(); const MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { if (*it) names.push_back((*it)->getName()); ++it; } }
void Party::getNames(StringVect &names) const { names.clear(); MemberList::const_iterator it = mMembers.begin(); const MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { const PartyMember *const m = *it; if (m) names.push_back(m->getName()); ++it; } }
bool TranslationManager::translateFile(const std::string &fileName, PoDict *const dict, StringVect &lines) { if (!dict || fileName.empty()) return false; int contentsLength; const ResourceManager *const resman = ResourceManager::getInstance(); char *fileContents = static_cast<char*>( resman->loadFile(fileName, contentsLength)); if (!fileContents) { logger->log("Couldn't load file: %s", fileName.c_str()); return false; } std::string str = std::string(fileContents, contentsLength); size_t oldPos1 = std::string::npos; size_t pos1; while ((pos1 = str.find("<<")) != std::string::npos) { if (pos1 == oldPos1) break; // detected infinite loop const size_t pos2 = str.find(">>", pos1 + 2); if (pos2 == std::string::npos) break; const std::string key = str.substr(pos1 + 2, pos2 - pos1 - 2); const std::string key2 = "<<" + str.substr( pos1 + 2, pos2 - pos1 - 2) + ">>"; const std::string val = dict->getStr(key); // logger->log("key:" + key); replaceAll(str, key2, val); oldPos1 = pos1; } std::istringstream iss(str); std::string line; while (getline(iss, line)) lines.push_back(line); free(fileContents); return true; }
void WhisperTab::getAutoCompleteList(StringVect &names) const { names.push_back(mNick); }