bool InputMask::isValidInput( QChar key, QChar mask ) const { switch ( mask ) { case 'A': if ( key.isLetter() && key != m_blank ) return TRUE; break; case 'a': if ( key.isLetter() || key == m_blank ) return TRUE; break; case 'N': if ( key.isLetterOrNumber() && key != m_blank ) return TRUE; break; case 'n': if ( key.isLetterOrNumber() || key == m_blank ) return TRUE; break; case 'X': if ( key.isPrint() && key != m_blank ) return TRUE; break; case 'x': if ( key.isPrint() || key == m_blank ) return TRUE; break; case '9': if ( key.isNumber() && key != m_blank ) return TRUE; break; case '0': if ( key.isNumber() || key == m_blank ) return TRUE; break; case 'D': if ( key.isNumber() && key.digitValue() > 0 && key != m_blank ) return TRUE; break; case 'd': if ( ( key.isNumber() && key.digitValue() > 0 ) || key == m_blank ) return TRUE; break; case '#': if ( key.isNumber() || key == '+' || key == '-' || key == m_blank ) return TRUE; break; default: break; } return FALSE; }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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++; }
FretDiagram* FretDiagram::fromString(Score* score, const QString &s) { FretDiagram* fd = new FretDiagram(score); fd->setStrings(s.size()); fd->setFrets(4); int offset = 0; int barreString = -1; for (int i = 0; i < s.size(); i++) { QChar c = s.at(i); if (c == 'X' or c == 'O') fd->setMarker(i, c.unicode()); else if (c == '-' && barreString == -1) { fd->setBarre(1); barreString = i; } else { int fret = c.digitValue(); if (fret != -1) { fd->setDot(i, fret); if (fret - 3 > 0 && offset < fret - 3) offset = fret - 3; } } } if (offset > 0) { fd->setOffset(offset); for (int i = 0; i < fd->strings(); i++) if (fd->dot(i)) fd->setDot(i, fd->dot(i) - offset); } if (barreString >= 0) fd->setDot(barreString, 1); return fd; }
LevelFile::LevelFile(QString file) { // open file level = new QFile(file); if(!level->open(QIODevice::ReadOnly)) { throw runtime_error("Couldn't open file"); } // create stream QTextStream in(level); in.setIntegerBase(10); // read through file, put into map QChar l; int row = 0; map.append(Row()); while(!in.atEnd()) { in >> l; // read each letter if(l == QChar::Space) // ignore space continue; else if(l == QChar::LineFeed) { // new row map.append(Row()); row++; } else if(l.isNumber()) { // add number to map map[row].append(l.digitValue()); } } level->close(); }
void TagConverter::applyPatternToColumns() { QList<int> columns; //QRegularExpression re = this->generatePattern2(fileToTagLineEdit); /// QString text = fileToTagLineEdit->text(); text = text.replace(':', '_'); // Remove and convert spaces according to columns for (int i = fileToTagLineEdit->tags().count() - 1; i >= 0; i--) { TagButton *tag = fileToTagLineEdit->tags().at(i); QString substitution = ':' + QString::number(tag->column()); columns.prepend(tag->column()); text.replace(tag->position(), tag->spaceCount(), substitution); } QString pattern = "^"; QString characterClass; // Depending on which detected columns, choose a sub-regex for (int i = 0; i < text.size(); i++) { QChar c = text.at(i); if (c == ':') { c = text.at(++i); switch (c.digitValue()) { case Miam::COL_Track: case Miam::COL_Year: case Miam::COL_Disc: characterClass = "[\\d]+"; // Digits break; default: characterClass = "[\\w\\W]+"; break; } pattern += "(" + characterClass + ")"; } else { pattern += QRegularExpression::escape(text.at(i)); } } pattern += "$"; QRegularExpression re(pattern, QRegularExpression::UseUnicodePropertiesOption); for (QModelIndex index : _tagEditor->selectionModel()->selectedRows()) { QString filename = index.data().toString(); filename = filename.left(filename.lastIndexOf(".")); QRegularExpressionMatch m = re.match(filename); if (!m.hasMatch()) { continue; } // The implicit capturing group with index 0 captures the result of the whole match. for (int i = 0; i < re.captureCount(); i++) { _tagEditor->updateCellData(index.row(), columns.at(i), m.captured(i + 1)); } } this->setVisible(false); _convertButton->setChecked(false); }
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; }
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; }
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; }
QString CodeMarker::typified(const QString &string) { QString result; QString pendingWord; for (int i = 0; i <= string.size(); ++i) { QChar ch; if (i != string.size()) ch = string.at(i); QChar lower = ch.toLower(); if ((lower >= QLatin1Char('a') && lower <= QLatin1Char('z')) || ch.digitValue() >= 0 || ch == QLatin1Char('_') || ch == QLatin1Char(':')) { pendingWord += ch; } else { if (!pendingWord.isEmpty()) { bool isProbablyType = (pendingWord != QLatin1String("const")); if (isProbablyType) result += QLatin1String("<@type>"); result += pendingWord; if (isProbablyType) result += QLatin1String("</@type>"); } pendingWord.clear(); switch (ch.unicode()) { case '\0': break; case '&': result += QLatin1String("&"); break; case '<': result += QLatin1String("<"); break; case '>': result += QLatin1String(">"); break; default: result += ch; } } } return result; }
double StringBits::stringToDoubleLocaleFree(QString s, bool *ok) { int dp = 0; int sign = 1; int i = 0; double result = 0.0; int len = s.length(); result = 0.0; if (ok) *ok = true; while (i < len && s[i].isSpace()) ++i; if (i < len && s[i] == '-') sign = -1; while (i < len) { QChar c = s[i]; if (c.isDigit()) { double d = c.digitValue(); if (dp > 0) { for (int p = dp; p > 0; --p) d /= 10.0; ++dp; } else { result *= 10.0; } result += d; } else if (c == '.') { dp = 1; } else if (ok) { *ok = false; } ++i; } return result * sign; }
///////////////////////////////////////////////////////////////////////////// // CheckSum() // Calculate the check sum for a given line of TLE data, the last character // of which is the current checksum. (Although there is no check here, // the current checksum should match the one we calculate.) // The checksum algorithm: // Each number in the data line is summed, modulo 10. // Non-numeric characters are zero, except minus signs, which are 1. // int QTle::CheckSum(const QString str) { // The length is "- 1" because we don't include the current (existing) // checksum character in the checksum calculation. size_t len = str.length() - 1; int xsum = 0; for (size_t i = 0; i < len; i++) { QChar ch = str.at(i); if (ch.isDigit()) xsum += ch.digitValue(); else if (ch == '-') xsum++; } return (xsum % 10); } // CheckSum()
QString Pass2::convertedOperand(QString s) { Utils *utils= &Singleton<Utils>::Instance(); QString ret = ""; if (s.at(0) == 'C') { for (int i = 2; i < s.length() -1; ++i) { QChar c = s.at(i); ret += utils->intToHexString(c.digitValue()); } return ret; } if (s.at(0).isDigit()) { return utils->intToHexString(s.toInt()); } if (s.startsWith("X'") && s.endsWith("'")) { s = s.replace("'", ""); s = s.replace("X", ""); return s.toLower(); } return ret; }
int MainWindow::fnFindSum(QString strNumberValue) { if(strNumberValue.length()==1) { return strNumberValue.toInt(); } else { long lngValue=0; for(int i=0; i<strNumberValue.length(); i++) { //lngValue += QString::toInt(""+strNumberValue.at(i)); QChar c = strNumberValue.at(i); if(c.isDigit()) { lngValue += c.digitValue(); } } return fnFindSum(QString::number(lngValue)); } }
/** * Unfortunately QSettings does not provide a method to remove array elements. * * So, we have to read in all keys and values of the named array section, delete * the whole array section and write it out again, omitting the deleted * row. We also have to take care to adapt the array indices after the deleted * row and to write finally the new size entry. */ bool Settings::removeArrayItem(const QString& strArrayName, int iIndex) const { bool fRet = false; qSettings()->beginReadArray(strArrayName); const QStringList keys(qSettings()->allKeys()); QStringList values; if (iIndex < keys.size()) { for (int i = 0; i < keys.size(); i++) values.insert(i, qSettings()->value(keys.at(i)).toString()); qSettings()->endArray(); qSettings()->beginGroup(strArrayName); qSettings()->remove(""); const QChar cIndex2Remove(iIndex + 1 + 48); QChar cIndex2Write; for (int i = 0; i < keys.size(); i++) { const QString& strKey = keys.at(i); const QChar cIndex2Read(strKey.at(0)); if (cIndex2Read.isDigit()) { if (cIndex2Read != cIndex2Remove) { cIndex2Write = cIndex2Read > cIndex2Remove ? QChar(cIndex2Read.digitValue() - 1 + 48) : QChar(cIndex2Read.digitValue() + 48); qSettings()->setValue(cIndex2Write + strKey.mid(1), values.at(i)); } } } qSettings()->setValue("size", QString(cIndex2Write)); qSettings()->endGroup(); fRet = true; } return(fRet); }
int CardSuiteUtil::rankToInt(QChar rank){ if (rank == QChar(88)) { return 0; // X, unknown card } if (rank == QChar(65)){ return 14; // ACE } if (rank == QChar(75)) { return 13;// KING } if (rank == QChar(81)) { return 12;// QUEEN } if (rank == QChar(74)) { return 11;// JACKET } if (rank.isDigit()) { return rank.digitValue(); } qDebug() << "CardSuiteUtil::rankToInt# WARNING imposible rank " << endl; return 0; }
static QString processLocaleString(const QString &s) { QString res; uint pos = 0; while(pos < s.length()) { QChar c = s[pos++]; if(c == '<') { bool flag = false; uint hc = 0; while(pos < s.length()) { QChar cc = s[pos++]; uint _hc = 0; if(cc == '>') break; else if(cc.isDigit()) _hc = cc.digitValue(); else _hc = cc.lower().latin1() - 'a' + 10; if(flag) { hc |= _hc; res.append(QChar(hc)); hc = 0; } else hc = (_hc << 4); flag = !flag; } } else { res.append(c); } } return res; }
int Robot::moveToObjectif(Entrepot *e, Tile objectif) { int moveToX = this->getX(); int moveToY = this->getY(); int dx = objectif.getX() - this->getX(); int dy = objectif.getY() - this->getY(); RechercheCheminAStar recherche = RechercheCheminAStar(e); QString route = recherche.calculChemin(this->getX(), this->getY(), objectif.getX(), objectif.getY()); if(route.length()>0) { int j; QChar c; c =route.at(0); j=c.digitValue(); moveToX += recherche.dx[j]; moveToY += recherche.dy[j]; } this->move(*e, moveToX, moveToY); if((abs(dx) == 0 && abs(dy) ==1) || (abs(dx) == 1 && abs(dy) ==0)){ if(e->tab[objectif.getX()][objectif.getY()] == MapScene::ARMOIREPLEINE) { e->tab[objectif.getX()][objectif.getY()] = MapScene::ARMOIREVIDE; return MapScene::ARMOIREVIDE; } else if(e->tab[objectif.getX()][objectif.getY()] == MapScene::ARMOIREVIDE) { e->tab[objectif.getX()][objectif.getY()] = MapScene::ARMOIREPLEINE; return MapScene::ARMOIREPLEINE; } } return MapScene::VIDE; }
/*! Extract a class name from the type \a string and return it. */ QString Node::extractClassName(const QString &string) const { QString result; for (int i=0; i<=string.size(); ++i) { QChar ch; if (i != string.size()) ch = string.at(i); QChar lower = ch.toLower(); if ((lower >= QLatin1Char('a') && lower <= QLatin1Char('z')) || ch.digitValue() >= 0 || ch == QLatin1Char('_') || ch == QLatin1Char(':')) { result += ch; } else if (!result.isEmpty()) { if (result != QLatin1String("const")) return result; result.clear(); } } return result; }
void MainWindow::loadDevSpecMap() { QFile *f = new QFile("codEP.txt"); QString s; QStringList lstPairs; if(f->exists()) { f->open(QIODevice::ReadOnly); QTextStream str(f); while(!str.atEnd()) { s = str.readLine(); if(!s.contains("//")) lstPairs << s; } } QChar chCl; int devCls, startSmb; for(int i = 0; i < lstPairs.size(); i++) { startSmb = lstPairs.at(i).indexOf("; 0x"); if(startSmb > 1) { chCl = lstPairs.at(i).mid(startSmb, 8).at(4); if(chCl.isDigit()) { devCls = chCl.digitValue(); if(devCls >= 0 && devCls <= 4) arrDevNames[devCls].append(lstPairs.at(i)); } bool ok; devSpecificationMap.insert(lstPairs.at(i).mid(startSmb + 4, 4).toInt(&ok, 16), lstPairs.at(i).left(startSmb)); } else qDebug() << "Error. No specification in srting" << i + 1 << ". (In device specification file)/" << startSmb; //arrDevNames[devCls].append(lstPairs.at(i)); } lgWgt = new logWidget(arrDevNames); }
static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) { #ifdef DEBUG_KEY_BINDINGS qDebug("**Mapping key: %d (0x%04x) - %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); #endif if (key == kClearCharCode && virtualKey == 0x47) return Qt::Key_Clear; if (key.isDigit()) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %d", __LINE__, key.digitValue()); #endif return key.digitValue() + Qt::Key_0; } if (key.isLetter()) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %d", __LINE__, (key.toUpper().unicode() - 'A')); #endif return (key.toUpper().unicode() - 'A') + Qt::Key_A; } if (key.isSymbol()) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %d", __LINE__, (key.unicode())); #endif return key.unicode(); } for (int i = 0; qt_mac_keyboard_symbols[i].qt_code; i++) { if (qt_mac_keyboard_symbols[i].mac_code == key) { /* To work like Qt for X11 we issue Backtab when Shift + Tab are pressed */ if (qt_mac_keyboard_symbols[i].qt_code == Qt::Key_Tab && (modif & Qt::ShiftModifier)) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: Qt::Key_Backtab", __LINE__); #endif return Qt::Key_Backtab; } #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %s", __LINE__, qt_mac_keyboard_symbols[i].desc); #endif return qt_mac_keyboard_symbols[i].qt_code; } } //last ditch try to match the scan code for (int i = 0; qt_mac_keyvkey_symbols[i].qt_code; i++) { if (qt_mac_keyvkey_symbols[i].mac_code == virtualKey) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %s", __LINE__, qt_mac_keyvkey_symbols[i].desc); #endif return qt_mac_keyvkey_symbols[i].qt_code; } } // check if they belong to key codes in private unicode range if (key >= 0xf700 && key <= 0xf747) { if (key >= 0xf704 && key <= 0xf726) { return Qt::Key_F1 + (key.unicode() - 0xf704) ; } for (int i = 0; qt_mac_private_unicode[i].qt_code; i++) { if (qt_mac_private_unicode[i].mac_code == key) { return qt_mac_private_unicode[i].qt_code; } } } //oh well #ifdef DEBUG_KEY_BINDINGS qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); #endif return Qt::Key_unknown; }
//----------------------------------------------------------------------------- static bool parseBasicReal(double& out, const QString& in) { const int k = in.length(); if (k < 1) { return false; } double result = 0.0; double sign = 1.0; double exp = 1.0; int pos = 0; // Test for sign if (in[pos] == '-') { sign = -1.0; ++pos; // skip sign } else if (in[pos] == '+') { ++pos; // skip sign } // Read integer part while (pos < k) { const QChar d = in[pos]; if (!d.isDigit()) { break; } result = 10.0 * result + d.digitValue(); ++pos; } // Check for decimal part if (pos < k) { const QChar n = in[pos]; if (n == '.' || n == ',') { ++pos; // Read fractional part int dp = -1; while (pos < k) { const QChar d = in[pos]; if (!d.isDigit()) { break; } result += pow(10.0, dp) * d.digitValue(); ++pos; --dp; } } // Check for exponent if (pos < k && result != 0.0 && in[pos].toLower() == 'e') { // Parse exponent part qint64 e; if (!parseBasicLong(e, in.mid(pos + 1))) { return false; } exp = pow(10.0, static_cast<double>(e)); } } // Either we're done, or ran into something we can't parse if (pos < k) { return false; } // Success out = sign * result * exp; return true; }
void renderI2of5(OROPage * page, const QRectF &r, const QString & _str, ORBarcodeData * bc) { QString str = _str; qreal narrow_bar = bc->narrowBarWidth; qreal bar_width_mult = 2.5; // the wide bar width multiple of the narrow bar qreal wide_bar = narrow_bar * bar_width_mult; if(str.length() % 2) { str = "0" + str; // padding zero if number of characters is not even } // this is our mandatory minimum quiet zone qreal quiet_zone = narrow_bar * 10; if(quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); // how long is the value we need to encode? int val_length = str.length(); // L = (C(2N+3)+6+N)X // L length of barcode (excluding quite zone // C the number of characters in the value excluding the start/stop // N the bar width multiple for wide bars // X the width of a bar (pixels in our case) qreal L; qreal C = val_length; qreal N = bar_width_mult; qreal X = narrow_bar; L = (C * (2.0*N + 3.0) + 6.0 + N) * X; // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area) // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option if(bc->align == 1) // center { qreal nqz = (draw_width - L) / 2.0; if(nqz > quiet_zone) quiet_zone = nqz; } else if(bc->align > 1) // right quiet_zone = draw_width - (L + quiet_zone); //else if(align < 1) {} // left : do nothing QPointF pos(r.left() + quiet_zone, r.top()); // start character pos = addBar(page, r, pos, bc, narrow_bar); pos = addSpace(page, r, pos, bc, narrow_bar); pos = addBar(page, r, pos, bc, narrow_bar); pos = addSpace(page, r, pos, bc, narrow_bar); for(int i = 0; i < str.length()-1; i+=2) { for(int iElt = 0; _i2of5charmap [0][iElt] != '\0'; iElt++) { for(int offset=0; offset<=1; offset++) { QChar c = str.at(i+offset); if(!c.isDigit()) { break; // invalid character } int iChar = c.digitValue(); qreal width = _i2of5charmap[iChar][iElt] == 'W' ? wide_bar : narrow_bar; pos = addElement(page, r, pos, bc, width, offset==1); } } } // stop character pos = addBar(page, r, pos, bc, wide_bar); pos = addSpace(page, r, pos, bc, narrow_bar); pos = addBar(page, r, pos, bc, narrow_bar); return; }
static int getToken() { const char tab[] = "bfnrt\"\'\\"; const char backTab[] = "\b\f\n\r\t\"\'\\"; yyIdent.clear(); yyComment.clear(); yyString.clear(); while ( yyCh != EOF ) { yyLineNo = yyCurLineNo; if ( yyCh.isLetter() || yyCh.toLatin1() == '_' ) { do { yyIdent.append(yyCh); yyCh = getChar(); } while ( yyCh.isLetterOrNumber() || yyCh.toLatin1() == '_' ); if (yyTok != Tok_Dot) { switch ( yyIdent.at(0).toLatin1() ) { case 'r': if ( yyIdent == QLatin1String("return") ) return Tok_return; break; case 'c': if ( yyIdent == QLatin1String("class") ) return Tok_class; break; case 'n': if ( yyIdent == QLatin1String("null") ) return Tok_null; break; } } switch ( yyIdent.at(0).toLatin1() ) { case 'T': // TR() for when all else fails if ( yyIdent == QLatin1String("TR") ) return Tok_tr; break; case 'p': if( yyIdent == QLatin1String("package") ) return Tok_Package; break; case 't': if ( yyIdent == QLatin1String("tr") ) return Tok_tr; if ( yyIdent == QLatin1String("translate") ) return Tok_translate; } return Tok_Ident; } else { switch ( yyCh.toLatin1() ) { case '/': yyCh = getChar(); if ( yyCh == QLatin1Char('/') ) { do { yyCh = getChar(); if (yyCh == EOF) break; yyComment.append(yyCh); } while (yyCh != QLatin1Char('\n')); return Tok_Comment; } else if ( yyCh == QLatin1Char('*') ) { bool metAster = false; bool metAsterSlash = false; while ( !metAsterSlash ) { yyCh = getChar(); if ( yyCh == EOF ) { yyMsg() << qPrintable(LU::tr("Unterminated Java comment.\n")); return Tok_Comment; } yyComment.append( yyCh ); if ( yyCh == QLatin1Char('*') ) metAster = true; else if ( metAster && yyCh == QLatin1Char('/') ) metAsterSlash = true; else metAster = false; } yyComment.chop(2); yyCh = getChar(); return Tok_Comment; } break; case '"': yyCh = getChar(); while ( yyCh != EOF && yyCh != QLatin1Char('\n') && yyCh != QLatin1Char('"') ) { if ( yyCh == QLatin1Char('\\') ) { yyCh = getChar(); if ( yyCh == QLatin1Char('u') ) { yyCh = getChar(); uint unicode(0); for (int i = 4; i > 0; --i) { unicode = unicode << 4; if( yyCh.isDigit() ) { unicode += yyCh.digitValue(); } else { int sub(yyCh.toLower().toLatin1() - 87); if( sub > 15 || sub < 10) { yyMsg() << qPrintable(LU::tr("Invalid Unicode value.\n")); break; } unicode += sub; } yyCh = getChar(); } yyString.append(QChar(unicode)); } else if ( yyCh == QLatin1Char('\n') ) { yyCh = getChar(); } else { yyString.append( QLatin1Char(backTab[strchr( tab, yyCh.toLatin1() ) - tab]) ); yyCh = getChar(); } } else { yyString.append(yyCh); yyCh = getChar(); } } if ( yyCh != QLatin1Char('"') ) yyMsg() << qPrintable(LU::tr("Unterminated string.\n")); yyCh = getChar(); return Tok_String; case ':': yyCh = getChar(); return Tok_Colon; case '\'': yyCh = getChar(); if ( yyCh == QLatin1Char('\\') ) yyCh = getChar(); do { yyCh = getChar(); } while ( yyCh != EOF && yyCh != QLatin1Char('\'') ); yyCh = getChar(); break; case '{': yyCh = getChar(); return Tok_LeftBrace; case '}': yyCh = getChar(); return Tok_RightBrace; case '(': if (yyParenDepth == 0) yyParenLineNo = yyCurLineNo; yyParenDepth++; yyCh = getChar(); return Tok_LeftParen; case ')': if (yyParenDepth == 0) yyParenLineNo = yyCurLineNo; yyParenDepth--; yyCh = getChar(); return Tok_RightParen; case ',': yyCh = getChar(); return Tok_Comma; case '.': yyCh = getChar(); return Tok_Dot; case ';': yyCh = getChar(); return Tok_Semicolon; case '+': yyCh = getChar(); if (yyCh == QLatin1Char('+')) { yyCh = getChar(); return Tok_PlusPlus; } if( yyCh == QLatin1Char('=') ) { yyCh = getChar(); return Tok_PlusEq; } return Tok_Plus; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { QByteArray ba; ba += yyCh.toLatin1(); yyCh = getChar(); bool hex = yyCh == QLatin1Char('x'); if ( hex ) { ba += yyCh.toLatin1(); yyCh = getChar(); } while ( hex ? isxdigit(yyCh.toLatin1()) : yyCh.isDigit() ) { ba += yyCh.toLatin1(); yyCh = getChar(); } bool ok; yyInteger = ba.toLongLong(&ok); if (ok) return Tok_Integer; break; } default: yyCh = getChar(); } } } return Tok_Eof; }
/*! Load, parse, and process a qdoc configuration file. This function is only called by the other load() function, but this one is recursive, i.e., it calls itself when it sees an \c{include} statement in the qdoc configuration file. */ void Config::load(Location location, const QString& fileName) { QFileInfo fileInfo(fileName); QString path = fileInfo.canonicalPath(); pushWorkingDir(path); QDir::setCurrent(path); QRegExp keySyntax(QLatin1String("\\w+(?:\\.\\w+)*")); #define SKIP_CHAR() \ do { \ location.advance(c); \ ++i; \ c = text.at(i); \ cc = c.unicode(); \ } while (0) #define SKIP_SPACES() \ while (c.isSpace() && cc != '\n') \ SKIP_CHAR() #define PUT_CHAR() \ word += c; \ SKIP_CHAR(); if (location.depth() > 16) location.fatal(tr("Too many nested includes")); QFile fin(fileInfo.fileName()); if (!fin.open(QFile::ReadOnly | QFile::Text)) { if (!Config::installDir.isEmpty()) { int prefix = location.filePath().length() - location.fileName().length(); fin.setFileName(Config::installDir + QLatin1Char('/') + fileName.right(fileName.length() - prefix)); } if (!fin.open(QFile::ReadOnly | QFile::Text)) location.fatal(tr("Cannot open file '%1': %2").arg(fileName).arg(fin.errorString())); } QTextStream stream(&fin); #ifndef QT_NO_TEXTCODEC stream.setCodec("UTF-8"); #endif QString text = stream.readAll(); text += QLatin1String("\n\n"); text += QLatin1Char('\0'); fin.close(); location.push(fileName); location.start(); int i = 0; QChar c = text.at(0); uint cc = c.unicode(); while (i < (int) text.length()) { if (cc == 0) { ++i; } else if (c.isSpace()) { SKIP_CHAR(); } else if (cc == '#') { do { SKIP_CHAR(); } while (cc != '\n'); } else if (isMetaKeyChar(c)) { Location keyLoc = location; bool plus = false; QString stringValue; QStringList rhsValues; QString word; bool inQuote = false; bool prevWordQuoted = true; bool metWord = false; MetaStack stack; do { stack.process(c, location); SKIP_CHAR(); } while (isMetaKeyChar(c)); QStringList keys = stack.getExpanded(location); SKIP_SPACES(); if (keys.count() == 1 && keys.first() == QLatin1String("include")) { QString includeFile; if (cc != '(') location.fatal(tr("Bad include syntax")); SKIP_CHAR(); SKIP_SPACES(); while (!c.isSpace() && cc != '#' && cc != ')') { if (cc == '$') { QString var; SKIP_CHAR(); while (c.isLetterOrNumber() || cc == '_') { var += c; SKIP_CHAR(); } if (!var.isEmpty()) { const QByteArray val = qgetenv(var.toLatin1().data()); if (val.isNull()) { location.fatal(tr("Environment variable '%1' undefined").arg(var)); } else { includeFile += QString::fromLatin1(val); } } } else { includeFile += c; SKIP_CHAR(); } } SKIP_SPACES(); if (cc != ')') location.fatal(tr("Bad include syntax")); SKIP_CHAR(); SKIP_SPACES(); if (cc != '#' && cc != '\n') location.fatal(tr("Trailing garbage")); /* Here is the recursive call. */ load(location, QFileInfo(QDir(path), includeFile).filePath()); } else { /* It wasn't an include statement, so it's something else. We must see either '=' or '+=' next. If not, fatal error. */ if (cc == '+') { plus = true; SKIP_CHAR(); } if (cc != '=') location.fatal(tr("Expected '=' or '+=' after key")); SKIP_CHAR(); SKIP_SPACES(); for (;;) { if (cc == '\\') { int metaCharPos; SKIP_CHAR(); if (cc == '\n') { SKIP_CHAR(); } else if (cc > '0' && cc < '8') { word += QChar(c.digitValue()); SKIP_CHAR(); } else if ((metaCharPos = QString::fromLatin1("abfnrtv").indexOf(c)) != -1) { word += QLatin1Char("\a\b\f\n\r\t\v"[metaCharPos]); SKIP_CHAR(); } else { PUT_CHAR(); } } else if (c.isSpace() || cc == '#') { if (inQuote) { if (cc == '\n') location.fatal(tr("Unterminated string")); PUT_CHAR(); } else { if (!word.isEmpty()) { if (metWord) stringValue += QLatin1Char(' '); stringValue += word; #if 0 if (metWord) rhsValues << QString(" " + word); else #endif rhsValues << word; metWord = true; word.clear(); prevWordQuoted = false; } if (cc == '\n' || cc == '#') break; SKIP_SPACES(); } } else if (cc == '"') { if (inQuote) { if (!prevWordQuoted) stringValue += QLatin1Char(' '); stringValue += word; if (!word.isEmpty()) rhsValues << word; metWord = true; word.clear(); prevWordQuoted = true; } inQuote = !inQuote; SKIP_CHAR(); } else if (cc == '$') { QString var; SKIP_CHAR(); while (c.isLetterOrNumber() || cc == '_') { var += c; SKIP_CHAR(); } if (!var.isEmpty()) { const QByteArray val = qgetenv(var.toLatin1().constData()); if (val.isNull()) { location.fatal(tr("Environment variable '%1' undefined").arg(var)); } else { word += QString::fromLatin1(val); } } } else { if (!inQuote && cc == '=') location.fatal(tr("Unexpected '='")); PUT_CHAR(); } } QStringList::ConstIterator key = keys.constBegin(); while (key != keys.constEnd()) { if (!keySyntax.exactMatch(*key)) keyLoc.fatal(tr("Invalid key '%1'").arg(*key)); ConfigVarMultimap::Iterator i; i = configVars_.insert(*key, ConfigVar(*key, rhsValues, QDir::currentPath(), keyLoc)); i.value().plus_ = plus; ++key; } } } else { location.fatal(tr("Unexpected character '%1' at beginning of line").arg(c)); } } popWorkingDir(); if (!workingDirs_.isEmpty()) QDir::setCurrent(workingDirs_.top()); }
void Main_GUI::check_number_set() { QString text = snapping_line->text(); QString qs; // construct ASCII string from arbitrary Unicode data; // the idea is to accept, say, CJK fullwidth digits also for (int i = 0; i < text.size(); i++) { QChar c = text.at(i); int digit = c.digitValue(); if (digit >= 0) qs += QString::number(digit); else if (c.isSpace()) qs += ' '; // U+30FC KATAGANA-HIRAGANA PROLONGED SOUND MARK is assigned // to the `-' key in some Japanese input methods else if (c.category() == QChar::Punctuation_Dash || c == QChar(0x30FC)) qs += '-'; // various Unicode COMMA characters, // including representation forms else if (c == QChar(',') || c == QChar(0x055D) || c == QChar(0x060C) || c == QChar(0x07F8) || c == QChar(0x1363) || c == QChar(0x1802) || c == QChar(0x1808) || c == QChar(0x3001) || c == QChar(0xA4FE) || c == QChar(0xA60D) || c == QChar(0xA6F5) || c == QChar(0xFE10) || c == QChar(0xFE11) || c == QChar(0xFE50) || c == QChar(0xFE51) || c == QChar(0xFF0C) || c == QChar(0xFF64)) qs += ','; else qs += c; // we do error handling below } if (x_height_snapping_exceptions) number_set_free(x_height_snapping_exceptions); QByteArray str = qs.toLocal8Bit(); const char* s = number_set_parse(str.constData(), &x_height_snapping_exceptions, 6, 0x7FFF); if (s && *s) { statusBar()->setStyleSheet("color: red;"); if (x_height_snapping_exceptions == NUMBERSET_ALLOCATION_ERROR) statusBar()->showMessage( tr("allocation error")); else if (x_height_snapping_exceptions == NUMBERSET_INVALID_CHARACTER) statusBar()->showMessage( tr("invalid character (use digits, dashes, commas, and spaces)")); else if (x_height_snapping_exceptions == NUMBERSET_OVERFLOW) statusBar()->showMessage( tr("overflow")); else if (x_height_snapping_exceptions == NUMBERSET_INVALID_RANGE) statusBar()->showMessage( tr("invalid range (minimum is 6, maximum is 32767)")); else if (x_height_snapping_exceptions == NUMBERSET_OVERLAPPING_RANGES) statusBar()->showMessage( tr("overlapping ranges")); else if (x_height_snapping_exceptions == NUMBERSET_NOT_ASCENDING) statusBar()->showMessage( tr("values und ranges must be specified in ascending order")); snapping_line->setText(qs); snapping_line->setFocus(Qt::OtherFocusReason); snapping_line->setCursorPosition(s - str.constData()); x_height_snapping_exceptions = NULL; } else { // normalize if there is no error char* new_str = number_set_show(x_height_snapping_exceptions, 6, 0x7FFF); snapping_line->setText(new_str); free(new_str); } }
/*! Load, parse, and process a qdoc configuration file. This function is only called by the other load() function, but this one is recursive, i.e., it calls itself when it sees an \c{include} statement in the qdog configuration file. */ void Config::load(Location location, const QString& fileName) { QRegExp keySyntax("\\w+(?:\\.\\w+)*"); #define SKIP_CHAR() \ do { \ location.advance(c); \ ++i; \ c = text.at(i); \ cc = c.unicode(); \ } while (0) #define SKIP_SPACES() \ while (c.isSpace() && cc != '\n') \ SKIP_CHAR() #define PUT_CHAR() \ word += c; \ SKIP_CHAR(); if (location.depth() > 16) location.fatal(tr("Too many nested includes")); QFile fin(fileName); if (!fin.open(QFile::ReadOnly | QFile::Text)) { fin.setFileName(fileName + ".qdoc"); if (!fin.open(QFile::ReadOnly | QFile::Text)) location.fatal(tr("Cannot open file '%1': %2").arg(fileName).arg(fin.errorString())); } QString text = fin.readAll(); text += QLatin1String("\n\n"); text += QChar('\0'); fin.close(); location.push(fileName); location.start(); int i = 0; QChar c = text.at(0); uint cc = c.unicode(); while (i < (int) text.length()) { if (cc == 0) ++i; else if (c.isSpace()) { SKIP_CHAR(); } else if (cc == '#') { do { SKIP_CHAR(); } while (cc != '\n'); } else if (isMetaKeyChar(c)) { Location keyLoc = location; bool plus = false; QString stringValue; QStringList stringListValue; QString word; bool inQuote = false; bool prevWordQuoted = true; bool metWord = false; MetaStack stack; do { stack.process(c, location); SKIP_CHAR(); } while (isMetaKeyChar(c)); QStringList keys = stack.getExpanded(location); SKIP_SPACES(); if (keys.count() == 1 && keys.first() == "include") { QString includeFile; if (cc != '(') location.fatal(tr("Bad include syntax")); SKIP_CHAR(); SKIP_SPACES(); while (!c.isSpace() && cc != '#' && cc != ')') { includeFile += c; SKIP_CHAR(); } SKIP_SPACES(); if (cc != ')') location.fatal(tr("Bad include syntax")); SKIP_CHAR(); SKIP_SPACES(); if (cc != '#' && cc != '\n') location.fatal(tr("Trailing garbage")); /* Here is the recursive call. */ load(location, QFileInfo(QFileInfo(fileName).dir(), includeFile) .filePath()); } else { /* It wasn't an include statement, so it;s something else. */ if (cc == '+') { plus = true; SKIP_CHAR(); } if (cc != '=') location.fatal(tr("Expected '=' or '+=' after key")); SKIP_CHAR(); SKIP_SPACES(); for (;;) { if (cc == '\\') { int metaCharPos; SKIP_CHAR(); if (cc == '\n') { SKIP_CHAR(); } else if (cc > '0' && cc < '8') { word += QChar(c.digitValue()); SKIP_CHAR(); } else if ((metaCharPos = QString(QLatin1String("abfnrtv")).indexOf(c)) != -1) { word += "\a\b\f\n\r\t\v"[metaCharPos]; SKIP_CHAR(); } else { PUT_CHAR(); } } else if (c.isSpace() || cc == '#') { if (inQuote) { if (cc == '\n') location.fatal(tr("Unterminated string")); PUT_CHAR(); } else { if (!word.isEmpty()) { if (metWord) stringValue += QLatin1Char(' '); stringValue += word; stringListValue << word; metWord = true; word.clear(); prevWordQuoted = false; } if (cc == '\n' || cc == '#') break; SKIP_SPACES(); } } else if (cc == '"') { if (inQuote) { if (!prevWordQuoted) stringValue += QLatin1Char(' '); stringValue += word; if (!word.isEmpty()) stringListValue << word; metWord = true; word.clear(); prevWordQuoted = true; } inQuote = !inQuote; SKIP_CHAR(); } else if (cc == '$') { QString var; SKIP_CHAR(); while (c.isLetterOrNumber() || cc == '_') { var += c; SKIP_CHAR(); } if (!var.isEmpty()) { char *val = getenv(var.toLatin1().data()); if (val == 0) { location.fatal(tr("Environment variable '%1' undefined").arg(var)); } else { word += QString(val); } } } else { if (!inQuote && cc == '=') location.fatal(tr("Unexpected '='")); PUT_CHAR(); } } QStringList::ConstIterator key = keys.begin(); while (key != keys.end()) { if (!keySyntax.exactMatch(*key)) keyLoc.fatal(tr("Invalid key '%1'").arg(*key)); if (plus) { if (locMap[*key].isEmpty()) { locMap[*key] = keyLoc; } else { locMap[*key].setEtc(true); } if (stringValueMap[*key].isEmpty()) { stringValueMap[*key] = stringValue; } else { stringValueMap[*key] += QLatin1Char(' ') + stringValue; } stringListValueMap[*key] += stringListValue; } else { locMap[*key] = keyLoc; stringValueMap[*key] = stringValue; stringListValueMap[*key] = stringListValue; } ++key; } } } else { location.fatal(tr("Unexpected character '%1' at beginning of line") .arg(c)); } } }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool elMundo::pasteRLEX_add (QString line, elMatriz& M, int o_color) { int clr, 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 (c == '!') return true; else if (c == ' ' || c == '\t' || c == '\n') continue; else { if (cN == 0) cN = 1; switch (c.unicode()) { case 'b': cX += M.a * cN; cY += M.b * cN; cN = 0; continue; case '$': cX += M.c * cN; cY += M.d * cN; cN = 0; if (M.a) cX = cX0; else cY = cY0; continue; // // Because 'b' is already taken, we have to use Spanish name for Blue... // so adding a few other names for consistency: // case 'k': clr = elcBlack; break; case 'n': clr = elcNegro; break; case 'g': clr = elcGreen; break; case 'v': clr = elcVerde; break; case 'r': clr = elcRojo; break; case 'x': clr = elcCyan; break; case 'a': clr = elcAzul; break; case 'y': clr = elcYellow; break; case 'c': clr = elcCastano; break; case 'z': clr = elcMagenta; break; case 'o': default: clr = o_color; } while (cN > 0) { add(cX, cY, clr); cX += M.a; cY += M.b; cN--; } } } // ^ return false; // don't replace that with "while(cN--)" } // as "cN = 0" is required loop invarint
void MidiArp::updatePattern(const QString& p_pattern) { int l1; QChar c; pattern = p_pattern; patternLen = pattern.length(); patternMaxIndex = 0; minStepWidth = 1.0; minOctave = 0; maxOctave = 0; double stepwd = 1.0; double nsteps = 0.; int chordindex = 0; bool chordmd = false; int oct = 0; int npoints = 0; // strip off trailing control tokens if (patternLen) { c = (pattern.at(patternLen - 1)); while (!c.isDigit() && (c != 'p') && (c != ')')) { pattern = pattern.left(patternLen - 1); patternLen--; if (patternLen < 1) break; c = (pattern.at(patternLen - 1)); } } // determine some useful properties of the arp pattern, // number of octaves, step width and number of steps in beats and // number of points for (l1 = 0; l1 < patternLen; l1++) { c = pattern.at(l1); if (c.isDigit()) { if (!chordindex) { nsteps += stepwd; npoints++; if (chordmd) chordindex++; } if (c.digitValue() > patternMaxIndex) patternMaxIndex = c.digitValue(); } switch(c.toAscii()) { case '(': chordmd = true; chordindex = 0; break; case ')': chordmd = false; chordindex = 0; break; case '>': stepwd *= .5; if (stepwd < minStepWidth) minStepWidth *= .5; break; case '<': stepwd *= 2.0; break; case '.': stepwd = 1.0; break; case 'p': if (!chordmd) nsteps += stepwd; npoints++; break; case '+': oct++; if (oct > maxOctave) maxOctave++; break; case '-': oct--; if (oct < minOctave) minOctave--; break; case '=': oct=0; break; default: ; } } patternIndex = 0; grooveIndex = 0; noteOfs = 0; nSteps = nsteps; nPoints = npoints; }
/*! Returns a Qt version of the given \a sys_fmt Symbian locale format string. */ static QString s60ToQtFormat(const QString &sys_fmt) { TLocale *locale = _s60Locale.GetLocale(); QString result; QString other; QString qtformatchars = QString::fromLatin1("adhmsyzAHM"); QChar c; int i = 0; bool open_escape = false; bool abbrev_next = false; bool locale_indep_ordering = false; bool minus_mode = false; bool plus_mode = false; bool n_mode = false; TTimeFormat tf = locale->TimeFormat(); while (i < sys_fmt.size()) { c = sys_fmt.at(i); // let formatting thru if (c.unicode() == '%') { // if we have gathered string, concat it if (!other.isEmpty()) { result += other; other.clear(); } // if we have open escape, end it if (open_escape) { result += QLatin1Char('\''); open_escape = false; } ++i; if (i >= sys_fmt.size()) break; c = sys_fmt.at(i); // process specials abbrev_next = c.unicode() == '*'; plus_mode = c.unicode() == '+'; minus_mode = c.unicode() == '-'; if (abbrev_next || plus_mode || minus_mode) { ++i; if (i >= sys_fmt.size()) break; c = sys_fmt.at(i); if (plus_mode || minus_mode) { // break on undefined plus/minus mode if (c.unicode() != 'A' && c.unicode() != 'B') break; } } switch (c.unicode()) { case 'F': { // locale indep mode on locale_indep_ordering = true; break; } case '/': { // date sep 0-3 ++i; if (i >= sys_fmt.size()) break; c = sys_fmt.at(i); if (c.isDigit() && c.digitValue() <= 3) { TChar s = locale->DateSeparator(c.digitValue()); TUint val = s; // some indexes return zero for empty if (val > 0) result += QChar(val); } break; } case 'D': { if (!locale_indep_ordering) break; if (!abbrev_next) result += QLatin1String("dd"); else result += QLatin1Char('d'); break; } case 'M': { if (!locale_indep_ordering) break; if (!n_mode) { if (!abbrev_next) result += QLatin1String("MM"); else result += QLatin1String("M"); } else { if (!abbrev_next) result += QLatin1String("MMMM"); else result += QLatin1String("MMM"); } break; } case 'N': { n_mode = true; if (!locale_indep_ordering) break; if (!abbrev_next) result += QLatin1String("MMMM"); else result += QLatin1String("MMM"); break; } case 'Y': { if (!locale_indep_ordering) break; if (!abbrev_next) result += QLatin1String("yyyy"); else result += QLatin1String("yy"); break; } case 'E': { if (!abbrev_next) result += QLatin1String("dddd"); else result += QLatin1String("ddd"); break; } case ':': { // timesep 0-3 ++i; if (i >= sys_fmt.size()) break; c = sys_fmt.at(i); if (c.isDigit() && c.digitValue() <= 3) { TChar s = locale->TimeSeparator(c.digitValue()); TUint val = s; // some indexes return zero for empty if (val > 0) result += QChar(val); } break; } case 'J': { if (tf == ETime24 && !abbrev_next) result += QLatin1String("hh"); else result += QLatin1Char('h'); break; } case 'H': { if (!abbrev_next) result += QLatin1String("hh"); else result += QLatin1Char('h'); break; } case 'I': { result += QLatin1Char('h'); break; } case 'T': { if (!abbrev_next) result += QLatin1String("mm"); else result += QLatin1Char('m'); break; } case 'S': { if (!abbrev_next) result += QLatin1String("ss"); else result += QLatin1Char('s'); break; } case 'B': { // only done for 12h clock if (tf == ETime24) break; } // fallthru to A case 'A': { // quickie to get capitalization, can't use s60 string as is because Qt 'hh' format's am/pm logic TAmPmName ampm = TAmPmName(); TChar first(ampm[0]); QString qtampm = QString::fromLatin1(first.IsUpper() ? "AP" : "ap"); int pos = locale->AmPmSymbolPosition(); if ((minus_mode && pos != ELocaleBefore) || (plus_mode && pos != ELocaleAfter)) break; if (!abbrev_next && locale->AmPmSpaceBetween()) { if (pos == ELocaleBefore) qtampm.append(QLatin1Char(' ')); else qtampm.prepend(QLatin1Char(' ')); } result += qtampm; } break; case '.': { // decimal sep TChar s = locale->DecimalSeparator(); TUint val = s; if (val > 0) result += QChar(val); } break; case 'C': { // six digits in s60, three digits in qt if (!abbrev_next) { result += QLatin1String("zzz"); } else { // next char is number from 0-6, how many digits to display ++i; if (i >= sys_fmt.size()) break; c = sys_fmt.at(i); if (c.isDigit()) { // try to match wanted digits QChar val(c.digitValue()); if (val >= 3) { result += QLatin1String("zzz"); } else if (val > 0) { result += QLatin1Char('z'); } } } break; } // these cases fallthru case '1': case '2': case '3': case '4': case '5': { // shouldn't parse these with %F if (locale_indep_ordering) break; TDateFormat df = locale->DateFormat(); const char **locale_dep; switch (df) { default: // fallthru to american case EDateAmerican: locale_dep = us_locale_dep; break; case EDateEuropean: locale_dep = eu_locale_dep; break; case EDateJapanese: locale_dep = jp_locale_dep; break; } int offset = 0; if (abbrev_next) offset += 5; if (n_mode) offset += 10; result += QLatin1String(locale_dep[offset + (c.digitValue()-1)]); break; } case '%': // fallthru percent { // any junk gets copied as is } default: { result += c; break; } case 'Z': // Qt doesn't support these :( case 'X': case 'W': { break; } } } else { // double any single quotes, don't begin escape if (c.unicode() == '\'') { // end open escape if (open_escape) { result += other; other.clear(); result += QLatin1Char('\''); open_escape = false; } other += c; } // gather chars and escape them in one go if any format chars are found if (!open_escape && qtformatchars.indexOf(c) != -1) { result += QLatin1Char('\''); open_escape = true; } other += c; } ++i; } if (!other.isEmpty()) result += other; if (open_escape) result += QLatin1Char('\''); return result; }
void PatternFormatter::parse() { enum State { LITERAL_STATE, ESCAPE_STATE, MIN_STATE, DOT_STATE, MAX_STATE, CHARACTER_STATE, POSSIBLEOPTION_STATE, OPTION_STATE }; int i = 0; QChar c; char ch; State state = LITERAL_STATE; FormattingInfo formatting_info; QString literal; int converter_start; int option_start; while (i < mPattern.length()) { // i points to the current character // c contains the current character // ch contains the Latin1 equivalent of the current character // i is incremented at the end of the loop to consume the character // continue is used to change state without consuming the character c = mPattern.at(i); ch = c.toLatin1(); switch (state) { case LITERAL_STATE: if (ch == '%') { formatting_info.clear(); converter_start = i; state = ESCAPE_STATE; } else literal += c; break; case ESCAPE_STATE: if (ch == '%') { literal += c; state = LITERAL_STATE; } else if (ch == 'n') { literal += Layout::endOfLine(); state = LITERAL_STATE; } else { if (!literal.isEmpty()) { createLiteralConverter(literal); literal.clear(); } if (ch == '-') formatting_info.mLeftAligned = true; else if (c.isDigit()) { formatting_info.mMinLength = c.digitValue(); state = MIN_STATE; } else if (ch == '.') state = DOT_STATE; else { state = CHARACTER_STATE; continue; } } break; case MIN_STATE: if (!addDigit(c, formatting_info.mMinLength)) { if (ch == '.') state = DOT_STATE; else { state = CHARACTER_STATE; continue; } } break; case DOT_STATE: if (c.isDigit()) { formatting_info.mMaxLength = c.digitValue(); state = MAX_STATE; } else { LogError e = LOG4QT_ERROR(QT_TR_NOOP("Found character '%1' where digit was expected."), LAYOUT_EXPECTED_DIGIT_ERROR, "Log4Qt::PatternFormatter"); e << QString(c); logger()->error(e); } break; case MAX_STATE: if (!addDigit(c, formatting_info.mMaxLength)) { state = CHARACTER_STATE; continue; } break; case CHARACTER_STATE: if (mIgnoreCharacters.indexOf(c) >= 0) state = LITERAL_STATE; else if (mOptionCharacters.indexOf(c) >= 0) state = POSSIBLEOPTION_STATE; else if (mConversionCharacters.indexOf(c) >= 0) { createConverter(c, formatting_info); state = LITERAL_STATE; } else { logger()->warn("Invalid conversion character '%1' at %2 in pattern '%3'", c, i, mPattern); createLiteralConverter(mPattern.mid(converter_start, i - converter_start + 1)); state = LITERAL_STATE; } break; case POSSIBLEOPTION_STATE: if (ch == '{') { option_start = i; state = OPTION_STATE; } else { createConverter(mPattern.at(i - 1), formatting_info); state = LITERAL_STATE; continue; } break; case OPTION_STATE: if (ch == '}') { createConverter(mPattern.at(option_start - 1), formatting_info, mPattern.mid(option_start + 1, i - option_start - 1)); state = LITERAL_STATE; } break; default: Q_ASSERT_X(false, "PatternFormatter::parse()", "Unknown parsing state constant"); state = LITERAL_STATE; } i++; } if (state != LITERAL_STATE) { logger()->warn("Unexptected end of pattern '%1'", mPattern); if (state == ESCAPE_STATE) literal += c; else literal += mPattern.mid(converter_start); } if (!literal.isEmpty()) createLiteralConverter(literal); }