ShellCommand::ShellCommand(const QString & fullCommand) { bool inQuotes = false; QString builder; for ( int i = 0 ; i < fullCommand.count() ; i++ ) { QChar ch = fullCommand[i]; const bool isLastChar = ( i == fullCommand.count() - 1 ); const bool isQuote = ( ch == '\'' || ch == '\"' ); if ( !isLastChar && isQuote ) { inQuotes = !inQuotes; } else { if ( (!ch.isSpace() || inQuotes) && !isQuote ) { builder.append(ch); } if ( (ch.isSpace() && !inQuotes) || ( i == fullCommand.count()-1 ) ) { _arguments << builder; builder.clear(); } } } }
QStringList NaturalQueryParser::split(const QString &query, bool is_user_query, QList<int> *positions) const { QStringList parts; QString part; int size = query.size(); bool between_quotes = false; bool split_at_every_char = !localeWordsSeparatedBySpaces(); for (int i=0; i<size; ++i) { QChar c = query.at(i); if (!between_quotes && (is_user_query || part != QLatin1String("$")) && (split_at_every_char || c.isSpace() || (is_user_query && d->separators.contains(c)))) { // If there is a cluster of several spaces in the input, part may be empty if (part.size() > 0) { parts.append(part); part.clear(); } // Add a separator, if any if (!c.isSpace()) { if (positions) { positions->append(i); } part.append(c); } } else if (c == QLatin1Char('"')) { between_quotes = !between_quotes; } else { if (is_user_query && part.length() == 1 && d->separators.contains(part.at(0))) { // The part contains only a separator, split "-KMail" to "-", "KMail" parts.append(part); part.clear(); } if (positions && part.size() == 0) { // Start of a new part, save its position in the stream positions->append(i); } part.append(c); } } if (!part.isEmpty()) { parts.append(part); } return parts; }
bool LineParser::isKeywordSeparator(const QChar &ch) { return ch.isSpace() || (ch == QLatin1Char(':')) || (ch == QLatin1Char('/')) || (ch == QLatin1Char('*')); }
//----------------------------------------------------------------------------- bool SqlTokenizer::nextToken() { sqlTokenStartM = sqlTokenEndM; if (sqlTokenEndM == 0 || *sqlTokenEndM == 0) { sqlTokenTypeM = tkEOF; return false; } // use QChar* member to scan QChar c = *sqlTokenEndM; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) keywordIdentifierToken(); else if (c == '"') quotedIdentifierToken(); else if (c == '\'') stringToken(); else if (c == '(') symbolToken(tkPARENOPEN); else if (c == ')') symbolToken(tkPARENCLOSE); else if (c == '=') symbolToken(tkEQUALS); else if (c == ',') symbolToken(tkCOMMA); else if (c == '/' && *(sqlTokenEndM + 1) == '*') multilineCommentToken(); else if (c == '-' && *(sqlTokenEndM + 1) == '-') singleLineCommentToken(); else if (c.isSpace()) whitespaceToken(); else defaultToken(); return true; }
/* Transforms 'int x = 3 + 4' into 'int x=3+4'. A white space is kept between 'int' and 'x' because it is meaningful in C++. */ static void trimWhiteSpace( QString& str ) { enum { Normal, MetAlnum, MetSpace } state = Normal; const int n = str.length(); int j = -1; QChar *d = str.data(); for ( int i = 0; i != n; ++i ) { const QChar c = d[i]; if ( c.isLetterOrNumber() ) { if ( state == Normal ) { state = MetAlnum; } else { if ( state == MetSpace ) str[++j] = c; state = Normal; } str[++j] = c; } else if ( c.isSpace() ) { if ( state == MetAlnum ) state = MetSpace; } else { state = Normal; str[++j] = c; } } str.resize(++j); }
/** * Split a line into lexemes. */ QStringList scan(const QString& lin) { QStringList result; QString line = lin.trimmed(); if (line.isEmpty()) return result; // empty QString lexeme; const uint len = line.length(); bool inString = false; for (uint i = 0; i < len; ++i) { QChar c = line[i]; if (c == QLatin1Char('"')) { lexeme += c; if (inString) { result.append(lexeme); lexeme.clear(); } inString = !inString; } else if (inString || c.isLetterOrNumber() || c == QLatin1Char('_') || c == QLatin1Char('@')) { lexeme += c; } else { if (!lexeme.isEmpty()) { result.append(lexeme); lexeme.clear(); } if (! c.isSpace()) { result.append(QString(c)); } } } if (!lexeme.isEmpty()) result.append(lexeme); return result; }
QValidator::State BitcoinAddressEntryValidator::validate(QString &input, int &pos) const { Q_UNUSED(pos); // Empty address is "intermediate" input if (input.isEmpty()) return QValidator::Intermediate; // Correction for (int idx = 0; idx < input.size();) { bool removeChar = false; QChar ch = input.at(idx); // Corrections made are very conservative on purpose, to avoid // users unexpectedly getting away with typos that would normally // be detected, and thus sending to the wrong address. switch(ch.unicode()) { // Qt categorizes these as "Other_Format" not "Separator_Space" case 0x200B: // ZERO WIDTH SPACE case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE removeChar = true; break; default: break; } // Remove whitespace if (ch.isSpace()) removeChar = true; // To next character if (removeChar) input.remove(idx, 1); else ++idx; } // Validation QValidator::State state = QValidator::Acceptable; for (int idx = 0; idx < input.size(); ++idx) { int ch = input.at(idx).unicode(); if (((ch >= '0' && ch<='9') || (ch >= 'a' && ch<='z') || (ch >= 'A' && ch<='Z') || (ch == ';')) &&//Allow for multiple address entries separated by a ; ch != 'l' && ch != 'I' && ch != '0' && ch != 'O') { // Alphanumeric and not a 'forbidden' character } else { state = QValidator::Invalid; } } return state; }
void CodeEditor::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_Return: case Qt::Key_Enter: { QTextCursor tc = textCursor(); QString t = tc.block().text(); QString spaces; QChar *data = t.data(); while (!data->isNull() && data->isSpace()) { spaces.append(*data); ++data; } QPlainTextEdit::keyPressEvent(event); insertPlainText(spaces); } break; case Qt::Key_F1: insertPlainText("\t"); break; default: QPlainTextEdit::keyPressEvent(event); } }
static QTextCursor createCursor(TranslationUnit *unit, AST *ast, QTextDocument *document) { unsigned startLine, startColumn, endLine, endColumn; unit->getTokenStartPosition(ast->firstToken(), &startLine, &startColumn); unit->getTokenEndPosition(ast->lastToken() - 1, &endLine, &endColumn); QTextCursor tc(document); tc.setPosition(document->findBlockByNumber(startLine - 1).position()); tc.setPosition(document->findBlockByNumber(endLine - 1).position() + endColumn - 1, QTextCursor::KeepAnchor); int charsToSkip = 0; forever { QChar ch = document->characterAt(tc.position() + charsToSkip); if (! ch.isSpace()) break; ++charsToSkip; if (ch == QChar::ParagraphSeparator) break; } tc.setPosition(tc.position() + charsToSkip, QTextCursor::KeepAnchor); return tc; }
bool BraceMatcher::shouldInsertMatchingText(const QChar lookAhead) const { return lookAhead.isSpace() || isQuote(lookAhead) || isDelimiter(lookAhead) || isClosingBrace(lookAhead); }
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; }
bool InputWidget::eventFilter(QObject *watched, QEvent *event) { if (event->type() != QEvent::KeyPress) return false; QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); // keys from BufferView should be sent to (and focus) the input line BufferView *view = qobject_cast<BufferView *>(watched); if (view) { if (keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier))) { // normal key press QChar c = keyEvent->text().at(0); if (c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) { setFocus(); QCoreApplication::sendEvent(inputLine(), keyEvent); return true; } } return false; } else if (watched == ui.inputEdit) { if (keyEvent->matches(QKeySequence::Find)) { QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar"); if (act) { act->toggle(); return true; } } return false; } return false; }
bool ChangeImportsVisitor::add(QmlJS::AST::UiProgram *ast, const Import &import) { setDidRewriting(false); if (!ast) return false; if (ast->headers && ast->headers->headerItem) { int insertionPoint = 0; if (ast->members && ast->members->member) insertionPoint = ast->members->member->firstSourceLocation().begin(); else insertionPoint = m_source.length(); while (insertionPoint > 0) { --insertionPoint; const QChar c = m_source.at(insertionPoint); if (!c.isSpace() && c != QLatin1Char(';')) break; } replace(insertionPoint+1, 0, QStringLiteral("\n") + import.toImportString()); } else { replace(0, 0, import.toImportString() + QStringLiteral("\n\n")); } setDidRewriting(true); return true; }
QList<QByteArray> KeymapParser::tokenize(const QByteArray &line) { bool quoted = false, separator = true; QList<QByteArray> result; QByteArray token; for (int i = 0; i < line.length(); ++i) { QChar c = line.at(i); if (!quoted && c == '#' && separator) break; else if (!quoted && c == '"' && separator) quoted = true; else if (quoted && c == '"') quoted = false; else if (!quoted && c.isSpace()) { separator = true; if (!token.isEmpty()) { result.append(token); token.truncate(0); } } else { separator = false; token.append(c); } } if (!token.isEmpty()) result.append(token); return result; }
QString get(int type) { QChar current; QString result; passWhiteSpace(); while (true) { current = next(); if (current.isNull()) { break; } if (current.isSpace()) { break; } bool number = isNumber(current); if (type == GetDigit && !number) { break; } if (type == GetString && number) { break; } if(current == QLatin1Char( CONVERSION_CHAR )) { break; } ++m_index; result += current; } return result; }
QValidator::State AddressValidator::validate( QString& string, int& pos ) const { Q_UNUSED( pos ) State result = QValidator::Acceptable; if( mCodecId == ExpressionCoding ) { string = string.trimmed(); if( ! expressionRegex.exactMatch(string) ) result = QValidator::Invalid; //only prefix has been typed: if( string == QStringLiteral("+") || string == QStringLiteral("-") || string.endsWith(QLatin1Char('x')) ) // 0x at end result = QValidator::Intermediate; } else { const int stringLength = string.length(); for( int i=0; i<stringLength; ++i ) { const QChar c = string.at( i ); if( !mValueCodec->isValidDigit( c.toLatin1() ) && !c.isSpace() ) { result = QValidator::Invalid; break; } } } if( string.isEmpty() ) result = QValidator::Intermediate; return result; }
bool Rewriter::includeSurroundingWhitespace(const QString &source, int &start, int &end) { bool includeStartingWhitespace = true; bool paragraphFound = false; bool paragraphSkipped = false; if (end >= 0) { QChar c = source.at(end); while (c.isSpace()) { ++end; if (c.unicode() == 10) { paragraphFound = true; paragraphSkipped = true; break; } else if (end == source.length()) { break; } c = source.at(end); } includeStartingWhitespace = paragraphFound; } paragraphFound = false; if (includeStartingWhitespace) { while (start > 0) { const QChar c = source.at(start - 1); if (c.unicode() == 10) { paragraphFound = true; break; } if (!c.isSpace()) break; --start; } } if (!paragraphFound && paragraphSkipped) //keep the line ending --end; return paragraphFound; }
/** * Returns true, if the path contains some whitespace. */ static bool isComplexPathName(const QString& path) { for (int i=path.length()-1; i > 0; i--) { const QChar ch = path.at(i); if (ch.isSpace()) return true; } return false; }
/** reads whitespace */ Token Scanner::readWhiteSpace() { QChar chr = m_src.peek(); while (chr.isSpace() && !isLineFeed(chr)) { m_src.move(); chr = m_src.peek(); } return Token(Token::Whitespace, m_src.anchor(), m_src.length()); }
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; }
QChar QPhoneNumberString::translatedToVanity(const QChar c) { if ( c.isNull() ) return QChar(); if ( c.isNumber() ) return c; if ( c.isSpace() ) return QChar('1'); QChar vanityChar = m_VanityChars[ c.toLower() ]; if ( vanityChar.isNull() ) kDebug() << " did not found char " << c << hex << c.unicode() << "\" to translate."; return( vanityChar ); }
void Lexer::skipSpaces() { // kdDebug(0)<<"Lexer::skipSpaces(), skipping SPACES."<<endl; QChar currentChar = getChar(); // when the Separator_* groups can be identified in the QChar thing would be easier while ( !inputStream->atEnd() && ( currentChar.isSpace() && !(currentChar == '\x0a' || currentChar == '\n') ) ) { currentChar = getChar(); } ungetChar(currentChar); // unget the tokEOL we likely just found }
QStringList StringBits::splitQuoted(QString s, QChar separator) { QStringList tokens; QString tok; enum { sep, unq, q1, q2 } mode = sep; for (int i = 0; i < s.length(); ++i) { QChar c = s[i]; if (c == '\'') { switch (mode) { case sep: mode = q1; break; case unq: case q2: tok += c; break; case q1: mode = sep; tokens << tok; tok = ""; break; } } else if (c == '"') { switch (mode) { case sep: mode = q2; break; case unq: case q1: tok += c; break; case q2: mode = sep; tokens << tok; tok = ""; break; } } else if (c == separator || (separator == ' ' && c.isSpace())) { switch (mode) { case sep: if (separator != ' ') tokens << ""; break; case unq: mode = sep; tokens << tok; tok = ""; break; case q1: case q2: tok += c; break; } } else if (c == '\\') { if (++i < s.length()) { c = s[i]; switch (mode) { case sep: mode = unq; tok += c; break; default: tok += c; break; } } } else { switch (mode) { case sep: mode = unq; tok += c; break; default: tok += c; break; } } } if (tok != "" || mode != sep) tokens << tok; return tokens; }
/** * Is the final character, ignoring trailing whitespace, a colon * */ bool InputSplitter::finalCharIsColon(const QString & str) const { QChar singleChar; int index = str.size() - 1; for (; index >= 0; --index) { singleChar = str.at(index); if(singleChar.isSpace()) continue; else break; } return (singleChar == ':'); }
void Scanner::consumeUntil(const char* stopAt, const char* stopAfter) { QChar ch = m_src.peek(); while (!ch.isNull() && !ch.isSpace() && !std::strchr(stopAt, ch.toLatin1())) { m_src.move(); ch = m_src.peek(); if (stopAfter && !ch.isNull() && std::strchr(stopAfter, ch.toLatin1())) { m_src.move(); break; } } }
QString CMakeEditor::contextHelpId() const { int pos = position(); QChar chr; do { --pos; if (pos < 0) break; chr = characterAt(pos); if (chr == QLatin1Char('(')) return QString(); } while (chr.unicode() != QChar::ParagraphSeparator); ++pos; chr = characterAt(pos); while (chr.isSpace()) { ++pos; chr = characterAt(pos); } int begin = pos; do { ++pos; chr = characterAt(pos); } while (chr.isLetterOrNumber() || chr == QLatin1Char('_')); int end = pos; while (chr.isSpace()) { ++pos; chr = characterAt(pos); } // Not a command if (chr != QLatin1Char('(')) return QString(); QString command = textAt(begin, end - begin).toLower(); return QLatin1String("command/") + command; }
// FIXME: duplicate code in the QmlJS::Rewriter class, remove this bool QMLRewriter::includeSurroundingWhitespace(int &start, int &end) const { QTextDocument *doc = m_textModifier->textDocument(); bool includeStartingWhitespace = true; bool paragraphFound = false; if (end >= 0) { QChar c = doc->characterAt(end); while (c.isSpace()) { ++end; if (c == QChar::ParagraphSeparator) { paragraphFound = true; break; } else if (end == doc->characterCount()) { break; } c = doc->characterAt(end); } includeStartingWhitespace = paragraphFound; } if (includeStartingWhitespace) { while (start > 0) { const QChar c = doc->characterAt(start - 1); if (!c.isSpace()) break; else if (c == QChar::ParagraphSeparator) break; --start; } } return paragraphFound; }
static bool CharMatch(QChar ref, QChar test) // ---------------------------------------------------------------------------- // Character matching function used by incremental search // ---------------------------------------------------------------------------- // * Comparison is case-insensitive // * Space and underscore are equivalent // * Accent folding: a letter without accent matches itself and the same // letter with any accent; but an accented letter matches only itself. // For instance: CharMatch('e', 'é') => true // CharMatch('e', 'e') => true // CharMatch('é', 'e') => false { static QMap<QChar, QChar> fold; if (fold.empty()) { # define F(from, to) fold[QChar(from)] = QChar(to) F(0xE0, 'a'); F(0xE1, 'a'); F(0xE2, 'a'); F(0xE3, 'a'); F(0xE4, 'a'); F(0xE5, 'a'); F(0xE8, 'e'); F(0xE9, 'e'); F(0xEA, 'e'); F(0xEB, 'e'); F(0xEC, 'i'); F(0xED, 'i'); F(0xEE, 'i'); F(0xEF, 'i'); F(0xF2, 'o'); F(0xF3, 'o'); F(0xF4, 'o'); F(0xF5, 'o'); F(0xF6, 'o'); F(0xF8, 'o'); F(0xF9, 'u'); F(0xFA, 'u'); F(0xFB, 'u'); F(0xFC, 'u'); F(0xFD, 'y'); F(0xFF, 'y'); # undef F } if (test.toLower() == ref.toLower()) return true; if ((test.isSpace() || test == '_') && ( ref.isSpace() || ref == '_')) return true; if (fold.contains(test) && fold[test] == ref) return true; return false; }
bool Rewriter::includeSurroundingWhitespace(int &start, int &end) const { bool includeStartingWhitespace = true; bool paragraphFound = false; if (end >= 0) { QChar c = m_originalText.at(end); while (c.isSpace()) { ++end; if (c == QChar::ParagraphSeparator) { paragraphFound = true; break; } else if (end == m_originalText.length()) { break; } c = m_originalText.at(end); } includeStartingWhitespace = paragraphFound; } if (includeStartingWhitespace) { while (start > 0) { const QChar c = m_originalText.at(start - 1); if (!c.isSpace()) break; else if (c == QChar::ParagraphSeparator) break; --start; } } return paragraphFound; }
EXPORT QString getPart(QString &str, unsigned size) { QString res; if (str.length() < size){ res = str; str = ""; return res; } int n = size; QChar c = str[(int)size]; if (!c.isSpace()){ for (; n >= 0; n++){ c = str[n]; if (c.isSpace()) break; } if (n < 0) n = size; } res = str.left(n); str = str.mid(n); return res; }