Esempio n. 1
0
/**
 *  @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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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;
}
Esempio n. 5
0
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);
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
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);
    }
Esempio n. 8
0
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;
    }
}
Esempio n. 9
0
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;
    }
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
void WhisperTab::getAutoCompleteList(StringVect &names) const
{
    names.push_back(mNick);
}