Пример #1
0
AnimExpression::Token AnimExpression::consumeNumber(const QString& str, QString::const_iterator& iter) const {
    assert(iter != str.end());
    assert(iter->isDigit());
    auto begin = iter;
    while (iter->isDigit() && iter != str.end()) {
        ++iter;
    }

    // parse whole integer part
    int pos = (int)(begin - str.begin());
    int len = (int)(iter - begin);
    QString sub = QStringRef(const_cast<const QString*>(&str), pos, len).toString();
    int whole = sub.toInt();

    // parse optional fractional part
    if (iter->unicode() == '.') {
        iter++;
        auto begin = iter;
        while (iter->isDigit() && iter != str.end()) {
            ++iter;
        }

        int pos = (int)(begin - str.begin());
        int len = (int)(iter - begin);
        QString sub = QStringRef(const_cast<const QString*>(&str), pos, len).toString();
        int fraction = sub.toInt();

        return Token(computeFloat(whole, fraction));

    } else {
        return Token(whole);
    }
}
Пример #2
0
ModelData* ModelComponent::getModelData(){
    ModelData *md = new ModelData();
    std::map<char,std::vector<QString>* > numbers;

    for(std::map<char, QLineEdit*>::iterator i = components.begin(); i != components.end(); i++){

        QString txt = i->second->text();
        int count = 0;

        std::vector<QString> *vecString = new std::vector<QString>();
        vecString->push_back("");
        numbers[i->first] = vecString;

        QString::iterator j = txt.begin();

        for(QString::iterator j = txt.begin(); j != txt.end(); j++){

            if(((*j) >= '0' && (*j) <= '9') || (*j) == ',' || (*j) == '.' || (*j)=='-'){ //ten warunek mozna poprawic(chodzi o wystapienie dwoch kropek albo minusow
                vecString->at(count).push_back( (*j));
            }else if((*j) == 32){
                    count++;
                    vecString->push_back("");
            }else{
                break;
                //TODO throw execption
            }
        }

        if(vecString->back() == "" ){
            vecString->pop_back();
        }
    }

    std::vector<QString>* A = numbers.at('A');
    std::vector<double> Adouble;

    for(std::vector<QString>::iterator i = A->begin(); i != A->end(); i++){
        Adouble.push_back((*i).toDouble());
    }
    md->setA(Adouble);

    std::vector<QString>* B = numbers.at('B');
    std::vector<double> Bdouble;
    for(std::vector<QString>::iterator i = B->begin(); i != B->end(); i++){
        Bdouble.push_back((*i).toDouble());
    }
    md->setB(Bdouble);

    std::vector<QString>* k = numbers.at('k');
    md->setK(k->at(0).toDouble());

    std::vector<QString>* t = numbers.at('t');
    md->setT(t->at(0).toDouble());

    std::vector<QString>* nr = numbers.at('nr');
    md->setNoiseRatio(nr->at(0).toDouble());
    return md;
}
Пример #3
0
bool MainWindow::searchInString(const QString& where, const QString& what)
{
    auto it = std::search(
        where.begin(), where.end(),
        what.begin(), what.end(),
        [](QChar ch1, QChar ch2) { return ch1.toUpper() == ch2.toUpper(); }
    );

    return it == where.begin();
}
Пример #4
0
    // TODO: directly unit test this
    bool globMatch(const QString &pattern, const QString &haystack) {
        QString::const_iterator patIt(pattern.begin());
        QString::const_iterator hayIt(haystack.begin());

        bool escaping(false);

        while (hayIt != haystack.end() && (escaping || *patIt != '%')) {

            if (!escaping && *patIt == '\\') {
                escaping = true;
                ++patIt;
                continue;
            }

            if ((patIt->toLower() != hayIt->toLower()) && (escaping || *patIt != '_'))
                return false;

            escaping = false;
            ++hayIt;
            ++patIt;
         }

        QString::const_iterator tPatIt(pattern.end());
        QString::const_iterator tHayIt(haystack.end());

        while (patIt != pattern.end() && hayIt != haystack.end()) {

            if (!escaping && *patIt == '\\') {
                escaping = true;
                ++patIt;
            } else if (!escaping && *patIt == '%') {
                if (++patIt == pattern.end())
                    return true;

                tPatIt = patIt;
                tHayIt = hayIt + 1;
            } else if (patIt->toLower() == hayIt->toLower() || (!escaping && *patIt == '_')) {
                escaping = false;
                ++patIt;
                ++hayIt;
            } else {
                escaping = false;
                patIt = tPatIt;
                hayIt = tHayIt++;
            }
        }

        // eat trailing %
        while (patIt != pattern.end() && *patIt == '%') {
            ++patIt;
        }

        return hayIt == haystack.end() && patIt == pattern.end();
    }
Пример #5
0
QString ParameterizedCommand::Escape(const QString& rawText)
{

  QString buffer;

  for (QString::const_iterator i = rawText.begin();
      i != rawText.end(); ++i)
  {

    QString::value_type c = *i;
    if (c == CommandManager::PARAMETER_START_CHAR ||
        c == CommandManager::PARAMETER_END_CHAR ||
        c == CommandManager::ID_VALUE_CHAR ||
        c == CommandManager::PARAMETER_SEPARATOR_CHAR ||
        c == CommandManager::ESCAPE_CHAR)
    {
      buffer += CommandManager::ESCAPE_CHAR;
    }

    buffer += c;
  }

  if (buffer.isEmpty())
  {
    return rawText;
  }
  return buffer;
}
Пример #6
0
QString Util::maxSubstring(const QString &s1, const QString &s2)
{
    std::tuple<Matrix,ArrowTable> len= maxSubstringLength(s1,s2);
    QString result = maxSubstringRecur(std::get<1>(len),s1,s1.length(),s2.length(),QString(""));
    std::reverse(result.begin(),result.end());
    return result;
}
Пример #7
0
/*!
    Returns the first charset from the preferred list that is capable of encoding
    the content of \a text.

    \since 1.0
    \sa preferredCharsets(), setBody()
*/
QByteArray QMessage::preferredCharsetFor(const QString &text)
{
    QList<QTextCodec*> codecs;
    foreach (const QByteArray &name, charsets) {
        if (QTextCodec* codec = QTextCodec::codecForName(name)) {
            codecs.append(codec);
        } else {
            qWarning() << "No codec is available for:" << name;
        }
    }

    if (!codecs.isEmpty()) {
        // See if any of these codecs can encode the data
        QString::const_iterator sit = text.begin(), end = text.end();
        for ( ; sit != end; ++sit) {
            QList<QTextCodec*>::iterator cit = codecs.begin();
            if (!(*cit)->canEncode(*sit)) {
                // This codec is not acceptable
                cit = codecs.erase(cit);
                if (codecs.isEmpty()) {
                    break;
                }
            } else {
                ++cit;
            }
        }

        if (!codecs.isEmpty()) {
            // Return the first remaining codec
            return codecs.first()->name();
        }
    }

    return QByteArray();
}
Пример #8
0
void PlayListWidget::sort(const QStringList &list)
{
    static QString first;
    static QString second;
    static QStringList tmp;
    static auto comp = [](QString::value_type it) {return it.isDigit();};
    for_each(list.begin(), list.end(), [&](const QStringList::value_type & item) {
        second.clear();
        tmp = item.split("$$");
        first = tmp[0];
        auto digit_begin = find_if(first.begin(), first.end(), comp);
        auto digit_end = find_if_not(digit_begin, first.end(), comp);
        std::copy(digit_begin, digit_end, std::back_inserter(second));
        play_list.append(list_map {std::make_tuple<QString, QString, QString>(
                                       QString("%1").arg(second.toInt(), 10, 10, QChar('0')),
                                       std::move(first),
                                       std::move(tmp[1]))
                                  });
    });
    std::sort(play_list.begin(), play_list.end(),
              [](list_map::const_iterator::value_type lvalue,
    list_map::const_iterator::value_type rvalue) {
        return std::get<0>(lvalue) < std::get<0>(rvalue);
    });
}
Пример #9
0
bool ViewNewMapDialog::CheckFileName(QString fileNameWithoutExtension)
{
    if(fileNameWithoutExtension.isEmpty())
    {
        QMessageBox::warning(this, tr("Warning ..."), tr("No file name was set."));
        return false;
    }
    if(fileNameWithoutExtension.size() > GLOBAL_CONSTS::MaximumMapFileNameSizeWithoutExtension)
    {
        QMessageBox::warning(this,
                             tr("Warning ..."),
                             tr("Your file name is too long. Maximum length is %1, yours length is %2.")\
                                .arg( QString::number( GLOBAL_CONSTS::MaximumMapFileNameSizeWithoutExtension ),\
                                      QString::number( fileNameWithoutExtension.size() ) ));
        return false;
    }
    if(fileNameWithoutExtension.at(0) == '-')
    {
        QMessageBox::warning(this, tr("Warning ..."), tr("File name first charachter can not be '-'."));
        return false;
    }
    for(QString::Iterator it = fileNameWithoutExtension.begin(); it != fileNameWithoutExtension.end(); ++it)
    {
        if(!(it->isLetterOrNumber()))
        {
            if(it->cell() != '.' && it->cell() != '_' && it->cell() != '-')
            {
                QMessageBox::warning(this, tr("Warning ..."), tr("File name can not contain '%1' charachter.").arg(*it));
                return false;
            }
        }
    }
    return true;
}
Пример #10
0
static QString
escape_shell_windows(QString const &source) {
  if (!source.contains(QRegExp{"[\\w+,\\-./:=@]"}))
    return source;

  auto copy = QString{'"'};

  for (auto it = source.begin(), end = source.end() ; ; ++it) {
    QString::size_type numBackslashes = 0;

    while ((it != end) && (*it == QChar{'\\'})) {
      ++it;
      ++numBackslashes;
    }

    if (it == end) {
      copy += QString{numBackslashes * 2, QChar{'\\'}};
      break;

    } else if (*it == QChar{'"'})
      copy += QString{numBackslashes * 2 + 1, QChar{'\\'}} + *it;

    else
      copy += QString{numBackslashes, QChar{'\\'}} + *it;
  }

  copy += QChar{'"'};

  copy.replace(QRegExp{"([()%!^\"<>&|])"}, Q("^\\1"));

  return copy;
}
Пример #11
0
QString QPhoneNumberString::translatedToVanity(const QString str) {
    QString vanityString;
    for  (QString::const_iterator i = str.begin(); i != str.end(); i++) {
        vanityString.append( translatedToVanity(*i) );
    }
    return vanityString;
}
Пример #12
0
void KTextEditingPlugin::checkSection(QTextDocument *document, int startPosition, int endPosition)
{
    QTextBlock block = document->findBlock(startPosition);
    int pos = block.position();
    while (true) {
        if (!block.contains(startPosition - 1) && !block.contains(endPosition + 1)) // only parags that are completely in
            finishedParagraph(document, block.position());

        QString text = block.text();
        bool space = true;
        QString::Iterator iter = text.begin();
        while (pos < endPosition && iter != text.end()) {
            bool isSpace = iter->isSpace();
            if (pos >= startPosition && space && !isSpace) // for each word, call finishedWord
                finishedWord(document, pos);
            else if (!isSpace && pos == startPosition)
                finishedWord(document, startPosition);
            space = isSpace;
            pos++;
            iter++;
        }

        if (!(block.isValid() && block.position() + block.length() < endPosition))
            break;
        block = block.next();
    }
}
Пример #13
0
    static void validateTopicName(const QString& topic)
    {
        if (topic.isEmpty())
        {
            throw std::invalid_argument("empty topic");
        }

        // Can't start or end with a '/' but anywhere else is okay
        // Can't have "//" as that implies empty token
        if (topic.startsWith("/") || topic.endsWith("/") ||
                topic.contains("//"))
        {
            throw std::invalid_argument(QString("invalid topic: %1").arg(topic).toStdString());
        }

        QString::const_iterator topicEnd = topic.end();
        QChar A('A'), Z('Z'), a('a'), z('z'), zero('0'), nine('9');
        QChar dash('-'), slash('/'), underscore('_');
        for (QString::const_iterator i = topic.begin(); i < topicEnd; ++i)
        {
            QChar c(*i);
            if ((A <= c) && (c <= Z)) continue;
            if ((a <= c) && (c <= z)) continue;
            if ((zero <= c) && (c <= nine)) continue;
            if ((c == underscore) || (c == dash) || (c == slash)) continue;
            throw std::invalid_argument(QString("invalid topic: %1").arg(topic).toStdString());
        }
    }
Пример #14
0
void WebExport::addDirComponents(const QString &dir)
{
  QString cur;

  // add the root component
  if (dm_basedirs.find(cur) == dm_basedirs.end())
    dm_basedirs[cur] = std::shared_ptr<DirEntry>(new DirEntry(cur));

  if (dir.isEmpty())
    return;   // end here, nothing more to do

  // now add all the dir compoenents
  QString::const_iterator ii=dir.begin();

  while (true) {
    if (ii == dir.end() || *ii == '/') {
      // found a component
      if (dm_basedirs.find(cur) == dm_basedirs.end())
        dm_basedirs[cur] = std::shared_ptr<DirEntry>(new DirEntry(cur));
      cur += '/';
    } else
      cur += *ii;
    if (ii == dir.end())  // are we done
      return;
    ii++;
  }
}
Пример #15
0
 void MainWindow::parseMessage(QString const& message)
 {
     std::vector<QString> stats;
     stats.push_back(QString());
     QString::const_iterator it = message.begin();
     QString::const_iterator itEnd = message.end();
     for (; it != itEnd; ++it)
         if (*it == ' ')
             stats.push_back(QString());
         else
             stats.back() += *it;
     if (stats.size() >= 6)
     {
         // uptime
         QDateTime t(QDate::currentDate());
         t = t.addMSecs(stats[0].toInt());
         this->uptimeLabel->setText("Uptime: " + t.toString("hh:mm:ss"));
         // upload
         this->_uploadGraph->addValue(static_cast<float>(stats[1].toInt()) / 1000.0f);
         // download
         this->_downloadGraph->addValue(static_cast<float>(stats[2].toInt()) / 1000.0f);
         // requests
         this->_requestsGraph->addValue(stats[3].toInt());
         // buffers
         this->_buffersGraph->addValue(stats[4].toInt());
         // memory
         this->_memoryGraph->addValue(static_cast<float>(stats[5].toInt()) / 1000.0f);
     }
 }
Пример #16
0
bool todosAscii(const QString& s)
{
    for (QString::const_iterator it = s.begin(); it != s.end(); ++it)
        if (it->unicode() > 127)
            return false;
    return true;
}
Пример #17
0
QString HttpRequest::encode( const QString& str ) const
{
  QString encodedStr;

  for ( QString::const_iterator it = str.begin(); it != str.end(); ++it )
  {
    char c = *it;
    if ( ( c >= 'a' && c <= 'z' ) ||
        ( c >= 'A' && c <= 'Z' ) ||
        ( c >= '0' && c <= '9' ) ||
        c == '-' || c == '_' ||
        c == '.' || c == '~' )
    {
      encodedStr += c;
    }
    else if ( c <= 0x20 || c >= 0x7F ||
      ILLEGAL.find(c) != QString::npos || '#' == c )
    {
      encodedStr += '%';
      toHex( (unsigned) (unsigned char) c, 2, encodedStr );
    }
    else encodedStr += c;
  }

  return encodedStr;
}
Пример #18
0
void ReverseDictionary::translate(const QString & what) {
	QString result;
	QString::const_iterator e = what.end();
	for (QString::const_iterator i = what.begin(); i != e; ++i) {
		result.prepend(*i);
	}
	emit hitFound(what, result);
}
Пример #19
0
AnimExpression::AnimExpression(const QString& str) :
    _expression(str) {
    auto iter = str.begin();
    parseExpr(_expression, iter);
    while(!_tokenStack.empty()) {
        _tokenStack.pop();
    }
}
Пример #20
0
bool            LibraryHandler::comparePath(QString str1, QString str2)
{
    QString::Iterator it = str1.begin();
    QString::Iterator it2 = str2.begin();

    for (;(it != str1.end()) && (it2 != str2.end()); ++it)
    {
        if ((*it) != '/' && (*it) != '\\' && (*it2) != '/' && (*it2) != '\\')
        {
            if ((*it) != (*it2))
               return false;
        }
        ++it2;
    }
    if (it == str1.end() && it2 == str2.end())
        return true;
    return false;
}
Пример #21
0
// Finds how many spaces the given string has at one end.
// direction=+1 -> left end of the string, -1 for right end.
int spacesAtCorner(const QString& string, int direction = +1) {
    int spaces = 0;
    QString::const_iterator it;
    for ( it = direction == 1 ? string.begin() : string.end()-1 ; it != string.end(); it += direction ) {
        if ( ! it->isSpace() ) break;
        spaces += 1;
    }
    return spaces;
}
Пример #22
0
QStringList Core::splitLine(QString line){

    QStringList FieldList;

    line.begin();
    FieldList=line.split(",");

    FieldList.replaceInStrings(QChar('"'), "");
    return FieldList;
}
Пример #23
0
Amount StringToAmount(QString const& string)
{
	if (string == QString() || string == QString(""))
		throw std::runtime_error("Cannot convert empty string");
	QString str = string.trimmed();
	str = RemoveCurrencySymbol(str);
	str = str.trimmed();

	return AcceptString(str.begin(), str.end());
}
Пример #24
0
void WordSuffixTree::addWord(QString word, map<size_t, size_t> tagFreqs)
{
	// We will traverse the suffix tree by reverse suffix order.
	reverse(word.begin(), word.end());

	// Chop the suffix to the length we are interested in.
	if (static_cast<size_t>(word.size()) > d_maxLength)
		word = word.left(d_maxLength);

	d_rootNode->addSuffix(word, tagFreqs);
}
Пример #25
0
QHash<size_t, double> WordSuffixTree::suffixTagProbs(QString word)
{
	// We will search the tree by reverse suffix order.
	reverse(word.begin(), word.end());

	// Chop to the length we are interested in.
	if (static_cast<size_t>(word.size()) > d_maxLength)
		word = word.left(d_maxLength);

	return d_rootNode->suffixTagProbs(word, QHash<size_t, double>());
}
Пример #26
0
/*
 * Removes bad characters
 */
QString InstrumentData::cleanWord(QString data)
{
    QString out;
    QChar c;

    for(auto i = data.begin(); i != data.end(); ++i){
        c = *i;
        if(c.isLetterOrNumber()||c.isPunct()) out.append(c);
    }

    return out;
}
Пример #27
0
void Autocorrect::uppercaseFirstCharOfSentence()
{
    if (! m_uppercaseFirstCharOfSentence) return;

    int startPos = m_cursor.selectionStart();
    QTextBlock block = m_cursor.block();

    m_cursor.setPosition(block.position());
    m_cursor.setPosition(startPos, QTextCursor::KeepAnchor);

    int position = m_cursor.selectionEnd();

    QString text = m_cursor.selectedText();

    if (text.isEmpty()) // start of a paragraph
        m_word.replace(0, 1, m_word.at(0).toUpper());
    else {
        QString::ConstIterator constIter = text.constEnd();
        constIter--;

        while (constIter != text.constBegin()) {
            while (constIter != text.begin() && constIter->isSpace()) {
                constIter--;
                position--;
            }

            if (constIter != text.constBegin() && (*constIter == QChar('.') || *constIter == QChar('!') || *constIter == QChar('?'))) {
                constIter--;
                while (constIter != text.constBegin() && !(constIter->isLetter())) {
                    position--;
                    constIter--;
                }
                bool replace = true;
                selectWord(m_cursor, --position);
                QString prevWord = m_cursor.selectedText();

                // search for exception
                if (m_upperCaseExceptions.contains(prevWord.trimmed()))
                    replace = false;

                if (replace)
                    m_word.replace(0, 1, m_word.at(0).toUpper());
                break;
            }
            else
                break;
        }
    }

    m_cursor.setPosition(startPos);
    m_cursor.setPosition(startPos + m_word.length(), QTextCursor::KeepAnchor);
}
Пример #28
0
bool Atome::isValidAtomeName(QString s){
    QString::iterator it = s.begin();
    //Avant de vérifier quoi que ce soit on vérifie le la string ne désigne pas un opérateur
    if(OperateurFactory::getMap().find(s)!=OperateurFactory::getMap().end())
        return false;

    //On vérifie que le premier caractère est une majuscule;
    if(s.begin()!=s.end() && *it<='Z' && *it>='A'){
        //On doit alors vérifier que tout les caractères ne sont que des lettres majuscules ou des chiffres
        while(it!=s.end()){
            if(('A'<=*it && *it<='Z') || ('0'<=*it && *it<='9')){
                it++;
                continue;
            }
            else
                return false;
        }
        return true;
    }
    //Si le premier caractère n'est pas une lettre majuscule, alors ce ne peut pas être un nom d'atome
    else
        return false;
}
Пример #29
0
double Core::extractRTT(QString line){

    int pos = -1;
    double RTT =-1;
    QStringList wordList;
    QString temp;

    line.begin();
    wordList=line.split(",");
    temp = wordList.at(2);
    temp.remove(QChar('"'));
    QStringList FieldList;

    return RTT = temp.toDouble();
}
Пример #30
0
bool UUID::parse( const QString& uuid )
{
  if ( uuid.size() < 32 ) return false;

  bool haveHyphens = false;
  if ( uuid[8] == '-' && uuid[13] == '-' && uuid[18] == '-' && uuid[23] == '-' )
  {
    if ( uuid.size() >= 36 )  haveHyphens = true;
    else return false;
  }
  
  QString::const_iterator it = uuid.begin();
  timeLow = 0;

  for ( int i = 0; i < 8; ++i )
  {
    timeLow = (timeLow << 4) | nibble(*it++);
  }
  if ( haveHyphens ) ++it;

  timeMid = 0;
  for ( int i = 0; i < 4; ++i )
  {
    timeMid = (timeMid << 4) | nibble(*it++);
  }
  if ( haveHyphens ) ++it;

  timeHiAndVersion = 0;
  for ( int i = 0; i < 4; ++i )
  {
    timeHiAndVersion = (timeHiAndVersion << 4) | nibble(*it++);
  }
  if ( haveHyphens ) ++it;

  clockSeq = 0;
  for ( int i = 0; i < 4; ++i )
  {
    clockSeq = (clockSeq << 4) | nibble(*it++);
  }
  if ( haveHyphens ) ++it;

  for ( int i = 0; i < 6; ++i )
  {
    node[i] = (nibble(*it++) << 4) | nibble(*it++) ;
  }

  return true;
}