QString QWsServer::computeAcceptV0( QString key1, QString key2, QString key3 ) { QString numStr1; QString numStr2; QChar carac; for ( int i=0 ; i<key1.size() ; i++ ) { carac = key1[ i ]; if ( carac.isDigit() ) numStr1.append( carac ); } for ( int i=0 ; i<key2.size() ; i++ ) { carac = key2[ i ]; if ( carac.isDigit() ) numStr2.append( carac ); } quint32 num1 = numStr1.toUInt(); quint32 num2 = numStr2.toUInt(); int numSpaces1 = key1.count( ' ' ); int numSpaces2 = key2.count( ' ' ); num1 /= numSpaces1; num2 /= numSpaces2; QString concat = serializeInt( num1 ) + serializeInt( num2 ) + key3; QByteArray md5 = QCryptographicHash::hash( concat.toLatin1(), QCryptographicHash::Md5 ); return QString( md5 ); }
bool misc::naturalSort(QString left, QString right, bool &result) { // uses lessThan comparison // Return value indicates if functions was successful // result argument will contain actual comparison result if function was successful int posL = 0; int posR = 0; do { for (;;) { if (posL == left.size() || posR == right.size()) return false; // No data QChar leftChar = left.at(posL); QChar rightChar = right.at(posR); bool leftCharIsDigit = leftChar.isDigit(); bool rightCharIsDigit = rightChar.isDigit(); if (leftCharIsDigit != rightCharIsDigit) return false; // Digit positions mismatch if (leftCharIsDigit) break; // Both are digit, break this loop and compare numbers if (leftChar != rightChar) return false; // Strings' subsets before digit do not match ++posL; ++posR; } QString temp; while (posL < left.size()) { if (left.at(posL).isDigit()) temp += left.at(posL); else break; posL++; } int numL = temp.toInt(); temp.clear(); while (posR < right.size()) { if (right.at(posR).isDigit()) temp += right.at(posR); else break; posR++; } int numR = temp.toInt(); if (numL != numR) { result = (numL < numR); return true; } // Strings + digits do match and we haven't hit string end // Do another round } while (true); return false; }
/** * Returns a the complete word defined by the current cursor position. * Attempts to extract a valid C symbol from the location of the cursor, by * starting at the current line and column, and looking forward and backward * for non-symbol characters. * @return A C symbol under the cursor, if any, or QString::null otherwise */ QString EditorPage::getWordUnderCursor(uint* pPosInWord) { KTextEditor::ViewCursorInterface* pCursor; KTextEditor::EditInterface* pEditIf; QString sLine; uint nLine, nCol, nFrom, nTo, nLast, nLength; QChar ch; // Get a cursor object pCursor = dynamic_cast<KTextEditor::ViewCursorInterface*>(m_pView); if (pCursor == NULL) return QString::null; // Get a pointer to the edit interface pEditIf = dynamic_cast<KTextEditor::EditInterface*>(m_pDoc); if (!pEditIf) return QString::null; // Get the line on which the cursor is positioned pCursor->cursorPositionReal(&nLine, &nCol); sLine = pEditIf->textLine(nLine); // Find the beginning of the current word for (nFrom = nCol; nFrom > 0;) { ch = sLine.at(nFrom - 1); if (!ch.isLetter() && !ch.isDigit() && ch != '_') break; nFrom--; } // Find the end of the current word nLast = sLine.length(); for (nTo = nCol; nTo < nLast;) { ch = sLine.at(nTo); if (!ch.isLetter() && !ch.isDigit() && ch != '_') break; nTo++; } // Mark empty words nLength = nTo - nFrom; if (nLength == 0) return QString::null; // Return the in-word position, if required if (pPosInWord != NULL) *pPosInWord = nCol - nFrom; // Extract the word under the cursor from the entire line return sLine.mid(nFrom, nLength); }
QVariant parseNumber() { QVarLengthArray<QChar> str; QChar c = next(); if(c == '-') { str.append(c); c = nextNoSkip(); } for(; c.isDigit(); c = nextNoSkip()) { str.append(c); } bool hasDecimal = false; if(c == '.') { str.append(c); hasDecimal = true; c = nextNoSkip(); for(; c.isDigit(); c = nextNoSkip()) { str.append(c); } } if(c == 'e' || c == 'E') { // Exponent. str.append(c); c = nextNoSkip(); if(c == '+' || c == '-') { str.append(c); c = nextNoSkip(); } for(; c.isDigit(); c = nextNoSkip()) { str.append(c); } } // Rewind one char (the loop was broken when a non-digit was read). pos--; skipWhite(); double value = QString(str.constData(), str.size()).toDouble(); if(hasDecimal) { return QVariant(value); } else { return QVariant(int(value)); } }
//-------------------------------------------------------------------------------------------------- /// Check if a string is a valid Xml element name // /// http://www.w3schools.com/xml/xml_elements.asp /// /// XML elements must follow these naming rules: /// Names can contain letters, numbers, and other characters /// Names cannot start with a number or punctuation character /// Names cannot start with the letters xml (or XML, or Xml, etc) /// Names cannot contain spaces //-------------------------------------------------------------------------------------------------- bool PdmObject::isValidXmlElementName(const QString& name) { if (name.size() > 0) { QChar firstChar = name[0]; if (firstChar.isDigit() || firstChar == '.') { return false; } } if (name.size() >= 3) { if (name.left(3).compare("xml", Qt::CaseInsensitive) == 0) { return false; } } if (name.contains(' ')) { return false; } return true; }
EnhancedPathParameter * EnhancedPathShape::parameter(const QString & text) { Q_ASSERT(! text.isEmpty()); ParameterStore::const_iterator parameterIt = m_parameters.constFind(text); if (parameterIt != m_parameters.constEnd()) { return parameterIt.value(); } else { EnhancedPathParameter *parameter = 0; QChar c = text[0]; if (c.toAscii() == '$' || c.toAscii() == '?') { parameter = new EnhancedPathReferenceParameter(text, this); } else { if (c.isDigit()) { bool success = false; qreal constant = text.toDouble(&success); if (success) parameter = new EnhancedPathConstantParameter(constant, this); } else { Identifier identifier = EnhancedPathNamedParameter::identifierFromString(text); if (identifier != IdentifierUnknown) parameter = new EnhancedPathNamedParameter(identifier, this); } } if (parameter) m_parameters[text] = parameter; return parameter; } }
QValidator::State mdtUicNumberValidator::validate(QString &input, int &pos) const { QChar c; QString number; // Check if last char is valid if(pos > 0){ c = input.at(pos-1); if((!c.isDigit())&&(c != ' ')&&(c != '-')){ return QValidator::Invalid; } } // Try to build the number... //Remove unusable chars if(input.size() > 5){ number = input.simplified(); number.remove(" "); number.remove("-"); // Check length: // - We only know about 6 and 11 digits UIC numbers // - If we have 7 or 12 digits, the control key is given if((number.size() == 6)||(number.size() == 7)||(number.size() == 11)||(number.size() == 12)){ return QValidator::Acceptable; } } return QValidator::Intermediate; }
QValidator::State EmailValidator::checkDomain(const QString & str, int & pos)const { pos = 0; if(str.isEmpty()) { return set(tr("Domain part after @ is empty")); } if(str[0] == '-') { return set(tr("Hyphen '-' can't be at the start of domain")); } pos = str.count() - 1; if(str[pos] == '-') { return set(tr("Hyphen '-' can't be at the end of domain")); } QStringList parts = str.split('.', QString::KeepEmptyParts); if(parts.count()<2) { return set(tr("Single domain without subdomains?")); } pos = 0; for(QString part : parts) { if(part.isEmpty()) { return set(tr("empty domain part ..")); } for(int i = 0; i < part.length(); ++i, ++pos) { QChar ch = part.at(i); if(isAsciiAlpha(ch) || ch.isDigit() || ch == '-') continue; return set(tr("Unsupported character ") + ch); } pos++; } return set(QValidator::Acceptable); }
QVariant parse() { LOG_AS("JSONParser"); if(atEnd()) return QVariant(); QChar c = peek(); if(c == '{') { return parseObject(); } else if(c == '[') { return parseArray(); } else if(c == '\"') { return parseString(); } else if(c == '-' || c.isDigit()) { return parseNumber(); } else { return parseKeyword(); } }
static bool matchcharclass( uint *rxd, QChar c ) { uint *d = rxd; uint clcode = *d & MCD; bool neg = clcode == CCN; if ( clcode != CCL && clcode != CCN) qWarning("QRegExp: Internal error, please report to [email protected]"); uint numFields = *d & MVL; uint cval = (((uint)(c.row())) << 8) | ((uint)c.cell()); bool found = FALSE; for ( int i = 0; i < (int)numFields; i++ ) { d++; if ( *d == PWS && c.isSpace() ) { found = TRUE; break; } if ( *d == PDG && c.isDigit() ) { found = TRUE; break; } else { uint from = ( *d & MCD ) >> 16; uint to = *d & MVL; if ( (cval >= from) && (cval <= to) ) { found = TRUE; break; } } } return neg ? !found : found; }
QValidator::State EmailValidator::checkLocal(const QString & str, int & pos)const { pos = 0; const QString allowed = "_-.!#$%&'*" //"+-/=?^_`{|}~" //characters after + are valid but ignored ; if(str.isEmpty()) { return set(tr("Empty name before @ character")); } int i = 0; pos = 0; if(str[0] == '.') { return set(tr("Dot (.) can't be at the start of email")); } pos = str.count() - 1; if(str[pos] == '.') { return set(tr("Dot (.) can't be at the end of you email name")); } for(pos = 0; pos < str.length(); ++pos) { QChar ch = str[pos]; if(isAsciiAlpha(ch) || ch.isDigit() || allowed.contains(ch)) continue; return set(tr("Invalid character ") + ch); } return set(QValidator::Acceptable); }
int iqrfe::ClsSelectorSparse::validateCell(int iR, int iC, bool bAllowEmpty) { int iReturn = -1; //ZZZ QString qstr = qtablePoints->text( iR, iC ).stripWhiteSpace(); QTableWidgetItem *qtwi = qtablePoints->itemAt ( iR, iC); if(qtwi!=NULL){ QString qstr = qtwi->text().trimmed(); if(!qstr.length()<=0){ for(unsigned int jj=0; jj<qstr.length(); jj++) { QChar qc = qstr[jj]; if(!qc.isDigit()){ //ZZZ qtablePoints->setText(iR, iC, "invalid entry"); QTableWidgetItem *newItem= new QTableWidgetItem("invalid entry"); qtablePoints->setItem(iR, iC, newItem); return iReturn; } } try{ iReturn = iqrUtils::string2int(qstr.toStdString()); } catch(...){ //ZZZ qtablePoints->setText(iR, iC, "invalid entry"); QTableWidgetItem *newItem= new QTableWidgetItem("invalid entry"); qtablePoints->setItem(iR, iC, newItem); } } else { if(!bAllowEmpty){ //ZZZ qtablePoints->setText(iR, iC, "invalid entry"); QTableWidgetItem *newItem= new QTableWidgetItem("invalid entry"); qtablePoints->setItem(iR, iC, newItem); } } return iReturn; } }
void QuickAddCapacitorDialog::slotAttemptAutoComplete() { QString text = ui->capacitanceValueLineEdit->text().trimmed(); //We accept 3 digit value codes with an optional tolerance code if(text.length()==3 || text.length()==4){ QString multiplicandStr = text.left(2); QChar multiplierChar = text.at(2); bool multiplicandOk; int multiplicand = multiplicandStr.toInt(&multiplicandOk); if(multiplicandOk && multiplierChar.isDigit()){ double capacitance = multiplicand * pow10(-12); int multiplierIdx = to_char(multiplierChar) - '0'; if(multiplierIdx >= 0 && multiplierIdx <= 9){ capacitance = capacitance * MULTIPLIERS[multiplierIdx]; } QString capacitanceStr = UnitFormatter::format(capacitance, _capacitanceParam.unitSymbol()); ui->capacitanceValueLineEdit->setText(capacitanceStr); } if(text.length()==4){ QChar toleranceChar = text.at(3); if(toleranceChar.isLetter()){ QString tolerance = lookupTolerance(to_char(toleranceChar)); if(!tolerance.isEmpty()){ ui->toleranceLineEdit->setText(tolerance); } } } } }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void elMundo::pasteLIFE_add (QString line) { int cN = 0; for (QString::const_iterator it = line.constBegin(); it != line.constEnd(); it++) { QChar c = *it; if (c.isDigit()) cN = 10*cN + c.digitValue(); else { if (cN == 0) cN = 1; switch (c.unicode()) { case '.': cX += cN; cN = 0; break; case '*': case 'O': while (cN > 0) { add(cX, cY, elcDefault); cX++; cN--; } } } } cX = cX0; cY++; }
void Filer::generateName(bool aSmgExt) { QString s = patchedFileName; if (aSmgExt) { s.remove(".smg"); } int endString = s.size() - 1; QChar ch = patchedFileName.at(endString); if (!(ch.isDigit())) { patchedFileName = s + QString::number(generateNum(s, 0, aSmgExt)); } else { QString num; int i; for (i = endString; i >= 0; --i) { if (s.at(i).isDigit()) { num.insert(0, s.at(i)); } else { break; } } s = s.left(i + 1); patchedFileName = s + QString::number(generateNum(s, num.toInt(), aSmgExt)); } if (aSmgExt) { patchedFileName += ".smg"; } }
Token Scanner::readFloatNumber() { enum { State_INTEGER, State_FRACTION, State_EXPONENT } state; state = State_INTEGER; bool hadFraction = false; for (;;) { QChar ch = m_src.peek(); if (ch.isNull()) break; if (state == State_INTEGER) { if (ch == '.' && m_src.peek(1).isDigit() && !hadFraction) { m_src.move(); hadFraction = true; state = State_FRACTION; } else if (!ch.isDigit()) { break; } } else if (state == State_FRACTION) { if (ch == 'e' || ch == 'E') { QChar next = m_src.peek(1); QChar next2 = m_src.peek(2); bool isExp = next.isDigit() || (((next == '-') || (next == '+')) && next2.isDigit()); if (isExp) { m_src.move(); state = State_EXPONENT; } else { break; } } else if (!ch.isDigit()) { break; } } else if (!ch.isDigit()) { break; } m_src.move(); } return Token(Token::Number, m_src.anchor(), m_src.length()); }
// TODO: will be a word in two lines ? QString EditorPage::getWordUnderCursor(uint* pPosInWord) { QString sLine; int nLine, nCol, nFrom, nTo, nLast, nLength; QChar ch; const KTextEditor::Cursor c = m_pView->cursorPosition(); // Get the line on which the cursor is positioned c.position(nLine, nCol); const KTextEditor::Cursor cFrom(nLine, 0); const KTextEditor::Cursor cTo = m_pDoc->endOfLine(nLine); KTextEditor::Range range(cFrom, cTo); sLine = m_pDoc->text(range); // Find the beginning of the current word for (nFrom = nCol; nFrom > 0;) { ch = sLine.at(nFrom - 1); if (!ch.isLetter() && !ch.isDigit() && ch != '_') break; nFrom--; } // Find the end of the current word nLast = sLine.length(); for (nTo = nCol; nTo < nLast;) { ch = sLine.at(nTo); if (!ch.isLetter() && !ch.isDigit() && ch != '_') break; nTo++; } // Mark empty words nLength = nTo - nFrom; if (nLength == 0) return QString::null; // Return the in-word position, if required if (pPosInWord != NULL) *pPosInWord = nCol - nFrom; // Extract the word under the cursor from the entire line return sLine.mid(nFrom, nLength); }
static int unpackMPCNumber(QChar ch) //////////////////////////////////// { char c = ch.toLatin1(); if (ch.isDigit()) return(c - '0'); return(10 + c - 'A'); }
bool CSVWorld::IdValidator::isValid (const QChar& c, bool first) const { if (c.isLetter() || c=='_') return true; if (!first && (c.isDigit() || c.isSpace())) return true; return false; }
TokenPtr Lexer::nextToken() { while (true) { while (peek().isSpace()) { consume(); } QChar next = peek(); d->newSpan(); if (next.isNull()) { return TokenPtr(); } else if (next == '{') { consume(); return TokenPtr(new LeftBraceToken(d->currentSpan())); } else if (next == '}') { consume(); return TokenPtr(new RightBraceToken(d->currentSpan())); } else if (next == '=') { consume(); return TokenPtr(new EqualsToken(d->currentSpan())); } else if (next.isLetter()) { return lexIdentifiers(); } else if (next == '"') { return lexStrings(); } else if (next.isDigit() || next == '-') { return lexNumeric(); } else if (next == '#') { consumeToEnd(); continue; } throw exceptions::UnmatchedInputException(currentPos(), next); } }
bool XCursorThemeFX::str2num (const QString &s, quint32 &res) { quint64 n = 0; if (s.isEmpty()) return false; for (int f = 0; f < s.length(); f++) { QChar ch = s.at(f); if (!ch.isDigit()) return false; n = n*10+ch.unicode()-'0'; } //if (n >= (quint64)0x100000000LL) n = 0xffffffffLL; if (n >= (quint64)0x80000000LL) n = 0x7fffffffLL; res = n; return true; }
bool PatternFormatter::addDigit(const QChar &rDigit, int &rValue) { if (!rDigit.isDigit()) return false; int digit_value = rDigit.digitValue(); if (rValue > (INT_MAX - digit_value) / 10) rValue = INT_MAX; else rValue = rValue * 10 + digit_value; return true; }
bool databaseFile:: isNumber(QString strCheck) { int strLen = strCheck.length(); if(strLen==0) return false; for(int i=0; i<strLen; i++) { QChar ch = strCheck.at(i); if(ch.isDigit() == false) return false; } return true; }
static int hex2int( QChar hexchar ) { int v; if ( hexchar.isDigit() ) v = hexchar.digitValue(); else if ( hexchar >= 'A' && hexchar <= 'F' ) v = hexchar.cell() - 'A' + 10; else if ( hexchar >= 'a' && hexchar <= 'f' ) v = hexchar.cell() - 'a' + 10; else v = -1; return v; }
static QString strippedSmsNumber( const QString &number ) { QString result; for ( int i = 0; i < number.length(); ++i ) { const QChar character = number.at( i ); if ( character.isDigit() || ( character == QLatin1Char( '+' ) && i == 0 ) ) { result += character; } } return result; }
long LXMLVar::What( const QChar S ) // ~~~~ { for(;;) { if( S.isLetter() || (S == _T('_')) ) return 1; if( S.isDigit() || ( S == _T('-') ) || ( S == _T('.') ) ) return 2; if( S == _T(':') ) return 3; return 0; } }
QValidator::State NumberEdit::validate( QString & text, int & pos ) const { if (emptyValid && text.isEmpty()) return QValidator::Acceptable; QValidator::State state = QDoubleSpinBox::validate(text, pos); QChar decimalPoint = QLocale().decimalPoint(); text.replace(QRegExp("[\\.,]"), decimalPoint); if (state == QValidator::Invalid && pos>0 && pos-1<text.size()) { QString s(text); bool changedString=false; // Stange thing entered... QChar justEntered = s[pos-1]; if (justEntered!=decimalPoint && !justEntered.isDigit()) return state; if (s.count(decimalPoint)>1) { // has multiple decimal points int p=0; while ((p=s.indexOf(decimalPoint, p))!=-1) { if (p+1!=pos) { if (p<pos) pos--; s.remove(p, 1); changedString = true; } else { p++; } } } else { // Split at decimal point QStringList N=s.split(decimalPoint); if (N.size()==2 and N[1].size()!=decimals()) { QString frac = N[1]; while (frac.size()<decimals()) frac += "0"; while (frac.size()>decimals()) frac.chop(1); s = N[0]+decimalPoint+frac; changedString = true; } } if (changedString) { state = validate(s, pos); if (state==QValidator::Acceptable) { text = s; } } } return state; }
//auto, #000000, 78px QSharedPointer<Value> CSSParser::parseValue(){ #ifdef CSS_DEBUG qDebug() << Q_FUNC_INFO; #endif /* CSS_DEBUG */ QChar c = peekChar(); if (c.isDigit()) { return parseLength(); } else if (c == '#') { return parseColor(); } else { // QSharedPointer<KeywordValue> ret = QSharedPointer<KeywordValue>(new KeywordValue(parseIdentifier())); return QSharedPointer<KeywordValue>(new KeywordValue(parseIdentifier())); } qDebug() << Q_FUNC_INFO << "enter a dead end"; }
QString Utils::parsePhoneNumberDigits(const QString &phoneNumber) { // Only allowing + and [0..9] chars QString filteredChars; if (phoneNumber.length() > 0) { for (int i = 0; i < phoneNumber.length(); i++) { const QChar c = phoneNumber.at(i); if (c.isDigit() || c == '+') { filteredChars.append(c); } } } return filteredChars; }
uint CSVController::hexDigitToDecimalValue(const QChar& c) const { if (c.isDigit()) { return c.digitValue(); } else if ('a' <= c && c <= 'f') { return c.unicode() - 'a' + 10; } else if ('A' <= c && c <= 'F') { return c.unicode() - 'A' + 10; } return 0; }