static void extractKeywords(const QByteArray &input, QStringList *destination) { if (!destination) return; QString keyword; int ignoreZone = 0; for (int i = 0; i < input.count(); ++i) { const QChar chr = QLatin1Char(input.at(i)); if (chr == QLatin1Char('{')) ++ignoreZone; if (chr == QLatin1Char('}')) --ignoreZone; if (ignoreZone == 0) { if ((chr.isLetterOrNumber() && chr.isUpper()) || chr == QLatin1Char('_')) { keyword += chr; } else { if (!keyword.isEmpty()) { if (keyword.size() > 1) *destination << keyword; keyword.clear(); } } } } if (keyword.size() > 1) *destination << keyword; }
void Autocorrect::fixTwoUppercaseChars() { if (! m_fixTwoUppercaseChars) return; if (m_word.length() <= 2) return; if (m_twoUpperLetterExceptions.contains(m_word.trimmed())) return; QChar firstChar = m_word.at(0); QChar secondChar = m_word.at(1); if (secondChar.isUpper()) { QChar thirdChar = m_word.at(2); if (firstChar.isUpper() && thirdChar.isLower()) m_word.replace(1, 1, secondChar.toLower()); } }
const QString ctkLDAPExpr::fixupQString( const QString &s ) { QString sb; int len = s.length(); for(int i=0; i<len; i++) { QChar c = s.at(i); if (!c.isSpace()) { if (c.isUpper()) c = c.toLower(); sb.append(c); } } return sb; }
// static ChromaticKey KeyUtils::guessKeyFromText(const QString& text) { QString trimmed = text.trimmed(); // Try using the user's custom notation. { QMutexLocker locker(&s_notationMutex); QMap<QString, ChromaticKey>::const_iterator it = s_reverseNotation.find(text); if (it != s_reverseNotation.end()) { return it.value(); } } QRegExp openKeyMatcher(s_openKeyPattern, Qt::CaseInsensitive); if (openKeyMatcher.exactMatch(trimmed)) { bool ok = false; int openKeyNumber = openKeyMatcher.cap(1).toInt(&ok); // Regex should mean this never happens. if (!ok || openKeyNumber < 1 || openKeyNumber > 12) { return mixxx::track::io::key::INVALID; } bool major = openKeyMatcher.cap(2) .compare("d", Qt::CaseInsensitive) == 0; return openKeyNumberToKey(openKeyNumber, major); } QRegExp lancelotKeyMatcher(s_lancelotKeyPattern, Qt::CaseInsensitive); if (lancelotKeyMatcher.exactMatch(trimmed)) { bool ok = false; int lancelotNumber = lancelotKeyMatcher.cap(1).toInt(&ok); // Regex should mean this never happens. if (!ok || lancelotNumber < 1 || lancelotNumber > 12) { return mixxx::track::io::key::INVALID; } int openKeyNumber = lancelotNumberToOpenKeyNumber(lancelotNumber); bool major = lancelotKeyMatcher.cap(2) .compare("b", Qt::CaseInsensitive) == 0; return openKeyNumberToKey(openKeyNumber, major); } QRegExp keyMatcher(s_keyPattern, Qt::CaseInsensitive); if (keyMatcher.exactMatch(trimmed)) { // Take the first letter, lowercase it and subtract 'a' and we get a // number between 0-6. Look up the major key associated with that letter // from s_letterToMajorKey. Upper-case means major, lower-case means // minor. Then apply the sharps or flats to the key. QChar letter = keyMatcher.cap(1).at(0); int letterIndex = letter.toLower().toAscii() - 'a'; bool major = letter.isUpper(); // Now apply sharps and flats to the letter key. QString adjustments = keyMatcher.cap(2); int steps = 0; for (QString::const_iterator it = adjustments.begin(); it != adjustments.end(); ++it) { steps += (*it == '#' || *it == s_sharpSymbol[0]) ? 1 : -1; } QString scale = keyMatcher.cap(3); // we override major if a scale definition exists if (! scale.isEmpty()) { if (scale.compare("m", Qt::CaseInsensitive) == 0) { major = false; } else if (scale.startsWith("min", Qt::CaseInsensitive)) { major = false; } else if (scale.startsWith("maj", Qt::CaseInsensitive)) { major = true; } else { qDebug() << "WARNING: scale from regexp has unexpected value." " should never happen"; } } ChromaticKey letterKey = static_cast<ChromaticKey>( s_letterToMajorKey[letterIndex] + (major ? 0 : 12)); return scaleKeySteps(letterKey, steps); } // We didn't figure out the key. Womp womp. return mixxx::track::io::key::INVALID; }
int Lexer::nextTokenKind() { int token = Parser::Token_INVALID; if (m_curpos >= m_contentSize) { m_tokenBegin = -1; m_tokenEnd = -1; createNewline(m_curpos); return 0; } QChar* it = m_content.data(); it += m_curpos; m_tokenBegin = m_curpos; if (it->isSpace()) { token = Parser::Token_WHITESPACE; while (m_curpos < m_contentSize && it->isSpace()) { if (it->unicode() == '\n') { createNewline(m_curpos); } it++; m_curpos++; } m_curpos--; } else if (it->isDigit()) { QRegExp regex("\\d+\\.\\d+|\\d+\\.\\d+|\\d+\\.\\d+e-?\\d+|\\d+\\.\\d+e-?\\d+|[\\dABCDEF]+#\\d{1,2}|\\d+"); if ( regex.indexIn(m_content, m_curpos) != -1) { kDebug() << "Matched: " << regex.cap(); m_curpos += regex.matchedLength() - 1; token = Parser::Token_INTEGER_LITERAL; } } else if (it->unicode() == '-') { if ((it + 1)->unicode() == '>') { m_curpos++; token = Parser::Token_LEADS_TO; } else if ((it + 1)->unicode() == '-') { m_curpos++; token = Parser::Token_LIST_DIFFERENCE; } else { token = Parser::Token_MINUS; } } else if (it->unicode() == '+') { if ((it + 1)->unicode() == '+') { m_curpos++; token = Parser::Token_LIST_ADDITION; } else { token = Parser::Token_PLUS; } } else if (it->unicode() == '$' && processCharLiteral(it + 1)) { token = Parser::Token_CHAR_LITERAL; } else if (it->unicode() == '}') { token = Parser::Token_RBRACE; if (state() == Tuple) { popState(); } } else if (it->unicode() == '_') { token = Parser::Token_UNDERLINE; } else if (it->unicode() == '{') { token = Parser::Token_LBRACE; pushState(Tuple); } else if (it->unicode() == ')') { token = Parser::Token_RPAREN; } else if (it->unicode() == '(') { token = Parser::Token_LPAREN; } else if (it->unicode() == ']') { token = Parser::Token_RBRACKET; } else if (it->unicode() == '[') { token = Parser::Token_LBRACKET; } else if (it->unicode() == ',') { token = Parser::Token_COMMA; } else if (it->unicode() == '#') { token = Parser::Token_POUND_SIGN; } else if (it->unicode() == '!') { token = Parser::Token_EXCLAMATION; } else if (it->unicode() == '<') { if ( (it + 1)->unicode() == '-') { m_curpos += 1; token = Parser::Token_LIST_COMPREHENSION_LEADS_TO; } else if ( (it + 1)->unicode() == '<' ) { m_curpos += 1; token = Parser::Token_BINARY_OPEN; } else { token = Parser::Token_IS_SMALLER; } } else if (it->unicode() == '>') { if ((it + 1)->unicode() == '=') { m_curpos++; token = Parser::Token_IS_GREATER_OR_EQUAL; } else if ( (it + 1)->unicode() == '>' ) { m_curpos += 1; token = Parser::Token_BINARY_CLOSE; } else { token = Parser::Token_IS_GREATER; } } else if (it->unicode() == '?') { token = Parser::Token_QUESTION; } else if (it->unicode() == '%') { token = Parser::Token_COMMENT; while (it->unicode() != '\n') { m_curpos++; it++; } createNewline(m_curpos); } else if (it->unicode() == '/') { if ((it + 1)->unicode() == '=') { token = Parser::Token_IS_NOT_EQUAL; } else { token = Parser::Token_FORWARD_SLASH; } } else if (it->unicode() == '*') { token = Parser::Token_MUL; } else if (it->unicode() == '|') { if ((it + 1)->unicode() == '|') { m_curpos++; token = Parser::Token_DOUBLE_PIPE; } else { token = Parser::Token_PIPE; } } else if (it->unicode() == ':') { if ( (it + 1)->unicode() == ':') { m_curpos += 1; token = Parser::Token_DOUBLE_COLON; } else { token = Parser::Token_COLON; } } else if (it->unicode() == '.') { token = Parser::Token_DOT; } else if (it->unicode() == ';') { token = Parser::Token_SEMICOLON; } else if (it->unicode() == '\'') { token = Parser::Token_ATOM_LITERAL; it++; m_curpos++; int startPos = m_curpos; while (m_curpos < m_contentSize && (it->unicode() != '\'')) { if (it->unicode() == '\n') createNewline(m_curpos); it++; m_curpos++; } // if the string is never terminated, make sure we don't overflow the boundaries if ( m_curpos == m_contentSize ) { --m_curpos; } } else if (it->unicode() == '"') { token = Parser::Token_STRING_LITERAL; it++; m_curpos++; while (m_curpos < m_contentSize && (it->unicode() != '\"')) { if (it->unicode() == '\n') createNewline(m_curpos); it++; m_curpos++; } // if the string is never terminated, make sure we don't overflow the boundaries if ( m_curpos == m_contentSize ) { --m_curpos; } } else if (it->unicode() == '=') { if ((it + 1)->unicode() == '=') { m_curpos++; token = Parser::Token_IS_EQUAL; } else if ((it + 1)->unicode() == '<') { m_curpos++; token = Parser::Token_IS_SMALLER_OR_EQUAL; } else if ((it + 1)->unicode() == ':' && (it + 2)->unicode() == '=') { m_curpos += 2; token = Parser::Token_EXACT_EQUATIONAL; } else if ((it + 1)->unicode() == '/' && (it + 2)->unicode() == '=') { m_curpos += 2; token = Parser::Token_EXACT_NOT_EQUATIONAL; } else { token = Parser::Token_ASSIGN; } } else if (it->isLetter() && it->isUpper()) { QString name; while (m_curpos < m_contentSize && (isValidVariableIdentifier(it))) { name.append(*it); it++; m_curpos++; } m_curpos--; token = Parser::Token_VARIABLE; } else if (it->isLetter() && it->isLower()) { QString name; while (m_curpos < m_contentSize && (isValidVariableIdentifier(it))) { name.append(*it); it++; m_curpos++; } m_curpos--; if (name == "after") { token = Parser::Token_AFTER; } else if (name == "begin") { token = Parser::Token_BEGIN; } else if (name == "case") { token = Parser::Token_CASE; } else if (name == "if") { token = Parser::Token_IF; } else if (name == "catch") { token = Parser::Token_CATCH; } else if (name == "cond") { token = Parser::Token_COND; } else if (name == "end") { token = Parser::Token_END; } else if (name == "fun") { token = Parser::Token_FUN; } else if (name == "let") { token = Parser::Token_LET; } else if (name == "of") { token = Parser::Token_OF; } else if (name == "catch") { token = Parser::Token_CATCH; } else if (name == "receive") { token = Parser::Token_RECEIVE; } else if (name == "when") { token = Parser::Token_WHEN; } else if (name == "div") { token = Parser::Token_INT_DIV; } else if (name == "rem") { token = Parser::Token_INT_REM; } else if (name == "or") { token = Parser::Token_OR; } else if (name == "xor") { token = Parser::Token_XOR; } else if (name == "bor") { token = Parser::Token_BIT_OR; } else if (name == "bxor") { token = Parser::Token_BIT_XOR; } else if (name == "query") { token = Parser::Token_QUERY; } else if (name == "bsl") { token = Parser::Token_SL; } else if (name == "bsr") { token = Parser::Token_SR; } else if (name == "and") { token = Parser::Token_AND; } else if (name == "band") { token = Parser::Token_BIT_AND; } else if (name == "not") { token = Parser::Token_NOT; } else if (name == "bnot") { token = Parser::Token_BIT_NOT; } else if (name == "orelse") { token = Parser::Token_ORELSE; } else if (name == "andalso") { token = Parser::Token_ANDALSO; } else if (name == "module") { token = Parser::Token_MODULE_DIRECTIVE; } else if (name == "include") { token = Parser::Token_INCLUDE_DIRECTIVE; } else if (name == "export") { token = Parser::Token_EXPORT_DIRECTIVE; } else if (name == "file") { token = Parser::Token_FILE_DIRECTIVE; } else if (name == "record") { token = Parser::Token_RECORD_DIRECTIVE; } else if (name == "include") { token = Parser::Token_INCLUDE_DIRECTIVE; } else if (name == "behaviour"){ token = Parser::Token_BEHAVIOUR_DIRECTIVE; } else if (name == "define"){ token = Parser::Token_DEFINE_DIRECTIVE; } else { token = Parser::Token_ATOM_LITERAL; } } m_tokenEnd = m_curpos; m_curpos++; return token; }
void KeyEvent::fromScriptValue(const QScriptValue& object, KeyEvent& event) { event.isValid = false; // assume the worst event.isMeta = object.property("isMeta").toVariant().toBool(); event.isControl = object.property("isControl").toVariant().toBool(); event.isAlt = object.property("isAlt").toVariant().toBool(); event.isKeypad = object.property("isKeypad").toVariant().toBool(); event.isAutoRepeat = object.property("isAutoRepeat").toVariant().toBool(); QScriptValue key = object.property("key"); if (key.isValid()) { event.key = key.toVariant().toInt(); event.text = QString(QChar(event.key)); event.isValid = true; } else { QScriptValue text = object.property("text"); if (text.isValid()) { event.text = object.property("text").toVariant().toString(); // if the text is a special command, then map it here... // TODO: come up with more elegant solution here, a map? is there a Qt function that gives nice names for keys? if (event.text.toUpper() == "F1") { event.key = Qt::Key_F1; } else if (event.text.toUpper() == "F2") { event.key = Qt::Key_F2; } else if (event.text.toUpper() == "F3") { event.key = Qt::Key_F3; } else if (event.text.toUpper() == "F4") { event.key = Qt::Key_F4; } else if (event.text.toUpper() == "F5") { event.key = Qt::Key_F5; } else if (event.text.toUpper() == "F6") { event.key = Qt::Key_F6; } else if (event.text.toUpper() == "F7") { event.key = Qt::Key_F7; } else if (event.text.toUpper() == "F8") { event.key = Qt::Key_F8; } else if (event.text.toUpper() == "F9") { event.key = Qt::Key_F9; } else if (event.text.toUpper() == "F10") { event.key = Qt::Key_F10; } else if (event.text.toUpper() == "F11") { event.key = Qt::Key_F11; } else if (event.text.toUpper() == "F12") { event.key = Qt::Key_F12; } else if (event.text.toUpper() == "UP") { event.key = Qt::Key_Up; event.isKeypad = true; } else if (event.text.toUpper() == "DOWN") { event.key = Qt::Key_Down; event.isKeypad = true; } else if (event.text.toUpper() == "LEFT") { event.key = Qt::Key_Left; event.isKeypad = true; } else if (event.text.toUpper() == "RIGHT") { event.key = Qt::Key_Right; event.isKeypad = true; } else if (event.text.toUpper() == "SPACE") { event.key = Qt::Key_Space; } else if (event.text.toUpper() == "ESC") { event.key = Qt::Key_Escape; } else if (event.text.toUpper() == "TAB") { event.key = Qt::Key_Tab; } else if (event.text.toUpper() == "DELETE") { event.key = Qt::Key_Delete; } else if (event.text.toUpper() == "BACKSPACE") { event.key = Qt::Key_Backspace; } else if (event.text.toUpper() == "SHIFT") { event.key = Qt::Key_Shift; } else if (event.text.toUpper() == "ALT") { event.key = Qt::Key_Alt; } else if (event.text.toUpper() == "CONTROL") { event.key = Qt::Key_Control; } else if (event.text.toUpper() == "META") { event.key = Qt::Key_Meta; } else if (event.text.toUpper() == "PAGE DOWN") { event.key = Qt::Key_PageDown; } else if (event.text.toUpper() == "PAGE UP") { event.key = Qt::Key_PageUp; } else if (event.text.toUpper() == "HOME") { event.key = Qt::Key_Home; } else if (event.text.toUpper() == "END") { event.key = Qt::Key_End; } else if (event.text.toUpper() == "HELP") { event.key = Qt::Key_Help; } else if (event.text.toUpper() == "CAPS LOCK") { event.key = Qt::Key_CapsLock; } else { // Key values do not distinguish between uppercase and lowercase // and use the uppercase key value. event.key = event.text.toUpper().at(0).unicode(); } event.isValid = true; } } QScriptValue isShifted = object.property("isShifted"); if (isShifted.isValid()) { event.isShifted = isShifted.toVariant().toBool(); } else { // if no isShifted was included, get it from the text QChar character = event.text.at(0); if (character.isLetter() && character.isUpper()) { event.isShifted = true; } else { // if it's a symbol, then attempt to detect shifted-ness if (QString("~!@#$%^&*()_+{}|:\"<>?").contains(character)) { event.isShifted = true; } } } const bool wantDebug = false; if (wantDebug) { qCDebug(scriptengine) << "event.key=" << event.key << " event.text=" << event.text << " event.isShifted=" << event.isShifted << " event.isControl=" << event.isControl << " event.isMeta=" << event.isMeta << " event.isAlt=" << event.isAlt << " event.isKeypad=" << event.isKeypad << " event.isAutoRepeat=" << event.isAutoRepeat; } }