C++ (Cpp) string Examples

C++ (Cpp) string - 30 examples found. These are the top rated real world C++ (Cpp) examples of string extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
vector<nColladaFileLoader::Attrib *> nColladaFileLoader::readAttribs(string str) {
    unsigned int index = 0;
    vector<Attrib *> lst;
    while(index < str.size()) {
        if(str.substr(index).find('=') == string::npos) {
            return lst;
        }
        string name;
        while(true) {
            char c = str[index++];
            if(name.size() == 0 && c == ' ') {
                continue;
            } else if(c != ' ' && c != '=') {
                name.push_back(c);
            } else {
                break;
            }
        }

        while(str[index++] != '"');

        string val;
        while(true) {
            char c = str[index++];
            if(c == '"') {
                break;
            } else {
                val.push_back(c);
            }
        }
        lst.push_back(Attrib::create(name, val));
    }
    return lst;
}
 vector<string> infix_to_postfix(string infix) {
     // delete ''
     for (string::iterator it = infix.begin() ; it != infix.end() ; ) {
         if (*it == ' ')
             it = infix.erase(it);
         else
             ++it;
     }
     // get postfix strings
     vector<string> postfix;
     stack<char> operator_chars;
     string::iterator start = infix.begin(), finish = start;
     while (finish != infix.end()) {
         if (!is_operator_char(*finish))
             ++finish;
         else {
             postfix.push_back(string(start, finish));
             while (!operator_chars.empty() && getPriority(*finish) <= getPriority(operator_chars.top())) {
                 postfix.push_back(string(1, operator_chars.top()));
                 operator_chars.pop();
             }
             operator_chars.push(*finish);
             start = finish + 1;
             finish = start;
         }
     }
     postfix.push_back(string(start, finish));
     while (!operator_chars.empty()) {
         postfix.push_back(string(1, operator_chars.top()));
         operator_chars.pop();
     }
     return postfix;
 }
Example #3
0
// Background object can be only be destroyed after jobBody() ran
void BackgroundJob::jobBody( boost::shared_ptr<JobStatus> status ) {
    LOG(1) << "BackgroundJob starting: " << name() << endl;
    {
        scoped_lock l( status->m );
        massert( 13643 , mongoutils::str::stream() << "backgroundjob already started: " << name() , status->state == NotStarted );
        status->state = Running;
    }

    const string threadName = name();
    if( ! threadName.empty() )
        setThreadName( threadName.c_str() );

    try {
        run();
    }
    catch ( std::exception& e ) {
        log( LL_ERROR ) << "backgroundjob " << name() << "error: " << e.what() << endl;
    }
    catch(...) {
        log( LL_ERROR ) << "uncaught exception in BackgroundJob " << name() << endl;
    }

    {
        scoped_lock l( status->m );
        status->state = Done;
        status->finished.notify_all();
    }

    if( status->deleteSelf )
        delete this;
}
Example #4
0
bool myEndsWith(string str, string suffix) {
    if (str.length() < suffix.length())
        return false;

    int pos = str.length() - suffix.length();
    return mySubString(str, pos, 0) == suffix;
}
string convert(string s, int numRows) {
    if(numRows < 2) return s;
    char** charQueues = new char*[numRows];
    int *ptArray = new int[numRows];
    for(int i = 0; i < numRows; i++) {
        charQueues[i] = new char[s.length()];
        ptArray[i] = 0;
    }

    int pt = 0;
    bool flag = false;
    for (int i = 0; i < s.length(); i++) {

        if(pt == 0 || pt == (numRows - 1)) flag = !flag;
        charQueues[pt][ptArray[pt]++] = s[i];

        if (flag) {
            pt++;
        } else {
            pt--;
        }

    }
    string res = "";

    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < ptArray[i]; j++) {
            res += charQueues[i][j];
        }
    }
    return res;
}
Example #6
0
bool MainWindow::load_file(string sFile)
{
    _sFileName="";
    _bMustSave=false;
    Mirror* pMirror;

    if(sFile.substr(sFile.size()-4)==".mir")
        pMirror=  MirrorIo::import(sFile);
    else
        pMirror=MirrorIo::load(sFile);

    if (pMirror==0)
    {
        QMessageBox m;
        m.setText(tr("Unable to Open file!!"));
        m.exec();
        return false;
    }

    delete _pMirror;
    _pMirror=pMirror;

    _sFileName=sFile;
    device_changed(false);
    ensure_visible(-1);
    return true;
}