Esempio n. 1
0
File: driver.cpp Progetto: Suneal/qt
QString Driver::normalizedName(const QString &name)
{
    QString result = name;
    QChar *data = result.data();
    for (int i = name.size(); --i >= 0; ++data) {
        if (!data->isLetterOrNumber())
            *data = QLatin1Char('_');
    }
    return result;
}
Esempio n. 2
0
void TypePrettyPrinter::space()
{
    if (_text.isEmpty())
        return;

    const QChar ch = _text.at(_text.length() - 1);

    if (ch.isLetterOrNumber() || ch == QLatin1Char('_') || ch == QLatin1Char(')'))
        _text += QLatin1Char(' ');
}
Esempio n. 3
0
QString gdbQuoteTypes(const QString &type)
{
    // gdb does not understand sizeof(Core::IFile*).
    // "sizeof('Core::IFile*')" is also not acceptable,
    // it needs to be "sizeof('Core::IFile'*)"
    //
    // We never will have a perfect solution here (even if we had a full blown
    // C++ parser as we do not have information on what is a type and what is
    // a variable name. So "a<b>::c" could either be two comparisons of values
    // 'a', 'b' and '::c', or a nested type 'c' in a template 'a<b>'. We
    // assume here it is the latter.
    //return type;

    // (*('myns::QPointer<myns::QObject>*'*)0x684060)" is not acceptable
    // (*('myns::QPointer<myns::QObject>'**)0x684060)" is acceptable
    if (isPointerType(type))
        return gdbQuoteTypes(stripPointerType(type)) + QLatin1Char('*');

    QString accu;
    QString result;
    int templateLevel = 0;

    const QChar colon = QLatin1Char(':');
    const QChar singleQuote = QLatin1Char('\'');
    const QChar lessThan = QLatin1Char('<');
    const QChar greaterThan = QLatin1Char('>');
    for (int i = 0; i != type.size(); ++i) {
        const QChar c = type.at(i);
        if (c.isLetterOrNumber() || c == QLatin1Char('_') || c == colon || c == QLatin1Char(' ')) {
            accu += c;
        } else if (c == lessThan) {
            ++templateLevel;
            accu += c;
        } else if (c == greaterThan) {
            --templateLevel;
            accu += c;
        } else if (templateLevel > 0) {
            accu += c;
        } else {
            if (accu.contains(colon) || accu.contains(lessThan))
                result += singleQuote + accu + singleQuote;
            else
                result += accu;
            accu.clear();
            result += c;
        }
    }
    if (accu.contains(colon) || accu.contains(lessThan))
        result += singleQuote + accu + singleQuote;
    else
        result += accu;
    //qDebug() << "GDB_QUOTING" << type << " TO " << result;

    return result;
}
Esempio n. 4
0
static bool isValidFileNameChar(const QChar &c)
{
    if (c.isLetterOrNumber()
            || c == QLatin1Char('.')
            || c == QLatin1Char('_')
            || c == QLatin1Char('-')
            || c == QLatin1Char('/')
            || c == QLatin1Char('\\'))
        return true;
    return false;
}
Esempio n. 5
0
/*
Returns true if none of the characters in [str] does not match isLetterOrNumber() and validChars.
*/
bool validateAlphaNum(const QString & str)
{
  const QString validChars = "-_.+@:;,[](){}~#$! ";
  for (uint i=0; i < str.length() ; i++)
  {
    QChar tmp = str.at(i);
    if ((!tmp.isLetterOrNumber()) && (validChars.find(tmp) == -1))
      return false;
  }
  return true;
}
Esempio n. 6
0
void AIMLParser::normalizeString(QString &str)
{
    QString newStr;
    for (int i = 0; i < str.length(); i++)
    {
        QChar c = str.at(i);
        if (c.isLetterOrNumber() || (c == '*') || (c == '_') || (c == ' '))
            newStr += c.lower();
    }
    str = newStr;
}
Esempio n. 7
0
bool QssCompletionAssistProcessor::acceptsIdleEditor()
{
    const int pos = m_interface->position();
    QChar characterUnderCursor = m_interface->characterAt(pos);
    if (!characterUnderCursor.isLetterOrNumber()) {
        m_startPosition = findStartOfName();
        if (pos - m_startPosition >= 3  && !isInComment())
            return true;
    }
    return false;
}
IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterface *interface)
{
    QScopedPointer<const AssistInterface> assistInterface(interface);
    if (running())
        return nullptr;

    int pos = interface->position();

    QChar chr;
    // Skip to the start of a name
    do {
        chr = interface->characterAt(--pos);
    } while (chr.isLetterOrNumber() || chr == '_');

    ++pos;
    int length = interface->position() - pos;

    if (interface->reason() == IdleEditor) {
        QChar characterUnderCursor = interface->characterAt(interface->position());
        if (characterUnderCursor.isLetterOrNumber() || length < 3)
            return nullptr;
    }

    const QString wordUnderCursor = interface->textAt(pos, length);
    const QString text = interface->textDocument()->toPlainText();

    m_watcher.setFuture(Utils::runAsync(&createProposal, text, wordUnderCursor));
    QObject::connect(&m_watcher, &QFutureWatcher<QStringList>::resultReadyAt,
                     &m_watcher, [this, pos](int index){
        const TextEditor::SnippetAssistCollector snippetCollector(
                    m_snippetGroup, QIcon(":/texteditor/images/snippet.png"));
        QList<AssistProposalItemInterface *> items = snippetCollector.collect();
        for (const QString &word : m_watcher.resultAt(index)) {
            auto item = new AssistProposalItem();
            item->setText(word);
            items.append(item);
        }
        setAsyncProposalAvailable(new GenericProposal(pos, items));
    });
    return nullptr;
}
QString WordFixFormattedStringVisitor::fixWord(const QString &content, const QString &word, const QString &fix)
{
	QString result = content;
	const int wordLength = word.length();
	const int fixLength = fix.length();

	int pos = 0;
	while ((pos = result.indexOf(word, pos)) != -1)
	{
		bool beginsWord = (pos == 0);
		if (!beginsWord)
		{
			const QChar ch(result.at(pos - 1));
			beginsWord = !ch.isLetterOrNumber() && !ch.isMark() && ch != QLatin1Char('_');

			if (!beginsWord)
			{
				pos += wordLength;
				continue;
			}
		}

		bool endsWord = (pos + wordLength == result.length());
		if (!endsWord)
		{
			const QChar ch(result.at(pos + wordLength));
			endsWord = !ch.isLetterOrNumber() && !ch.isMark() && ch != QLatin1Char('_');

			if (!endsWord)
			{
				pos += wordLength;
				continue;
			}
		}

		result.replace(pos, wordLength, fix);
		pos += fixLength;
	}

	return result;
}
Esempio n. 10
0
static bool isNumberChar(QChar ch)
{
    switch (ch.unicode()) {
    case '.':
    case 'e':
    case 'E': // ### more...
        return true;

    default:
        return ch.isLetterOrNumber();
    }
}
Esempio n. 11
0
static void moveCursorToEndOfName(QTextCursor *tc)
{
    QTextDocument *doc = tc->document();
    if (!doc)
        return;

    QChar ch = doc->characterAt(tc->position());
    while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
        tc->movePosition(QTextCursor::NextCharacter);
        ch = doc->characterAt(tc->position());
    }
}
Esempio n. 12
0
QString ibanBic::ibanToElectronic(const QString& iban)
{
  QString canonicalIban;
  const int length = iban.length();
  for (int i = 0; i < length; ++i) {
    const QChar letter = iban.at(i);
    if (letter.isLetterOrNumber())
      canonicalIban.append(letter.toUpper());
  }

  return canonicalIban;
}
Esempio n. 13
0
QWORKBENCH_UTILS_EXPORT QString settingsKey(const QString &category)
{
    QString rc(category);
    const QChar underscore = QLatin1Char('_');
    const int size = rc.size();
    for (int i = 0; i < size; i++) {
        const QChar c = rc.at(i);
        if (!c.isLetterOrNumber() && c != underscore)
            rc[i] = underscore;
    }
    return rc;
}
Esempio n. 14
0
/*
 * Removes bad characters
 */
QString InstrumentData::cleanWord(QString data)
{
    QString out;
    QChar c;

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

    return out;
}
Esempio n. 15
0
QString GLSLTextEditorWidget::wordUnderCursor() const
{
    QTextCursor tc = textCursor();
    const QChar ch = characterAt(tc.position() - 1);
    // make sure that we're not at the start of the next word.
    if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
        tc.movePosition(QTextCursor::Left);
    tc.movePosition(QTextCursor::StartOfWord);
    tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
    const QString word = tc.selectedText();
    return word;
}
int ProFileCompletionAssistProcessor::findStartOfName(int pos) const
{
    if (pos == -1)
        pos = m_interface->position();
    QChar chr;

    // Skip to the start of a name
    do {
        chr = m_interface->characterAt(--pos);
    } while (chr.isLetterOrNumber() || chr == QLatin1Char('_'));

    return pos + 1;
}
Esempio n. 17
0
bool Lexer::isIdentLetter(QChar ch)
{
    // ASCII-biased, since all reserved words are ASCII, aand hence the
    // bulk of content to be parsed.
    if ((ch >= QLatin1Char('a') && ch <= QLatin1Char('z'))
            || (ch >= QLatin1Char('A') && ch <= QLatin1Char('Z'))
            || ch == QLatin1Char('$')
            || ch == QLatin1Char('_'))
        return true;
    if (ch.unicode() < 128)
        return false;
    return ch.isLetterOrNumber();
}
Esempio n. 18
0
QString CppFileWizard::toAlphaNum(const QString &s)
{
    QString rc;
    const int len = s.size();
    const QChar underscore =  QLatin1Char('_');

    for (int i = 0; i < len; i++) {
        const QChar c = s.at(i);
        if (c == underscore || c.isLetterOrNumber())
            rc += c;
    }
    return rc;
}
QString VariableController::expressionUnderCursor(KTextEditor::Document* doc, const KTextEditor::Cursor& cursor)
{
    QString line = doc->line(cursor.line());
    int index = cursor.column();
    QChar c = line[index];
    if (!c.isLetterOrNumber() && c != '_' && c != '$')
        return QString();

    int start = Utils::expressionAt(line, index);
    int end = index;
    for (; end < line.size(); ++end) {
        QChar c = line[end];
        if (!(c.isLetterOrNumber() || c == '_' || c == '$'))
            break;
    }
    if (!(start < end))
        return QString();

    QString expression(line.mid(start, end-start));
    expression = expression.trimmed();
    return expression;
}
Esempio n. 20
0
QString WordIterator::getNextWord()
{
    QString res;
    for (; pos < (int)str.length(); pos++){
        QChar c = str[pos];
        if (c.isLetterOrNumber()) break;
    }
    for (; pos < (int)str.length(); pos++){
        if (!str[pos].isLetterOrNumber()) break;
        res += str[pos];
    }
    return res;
}
Esempio n. 21
0
void CallTipsList::callTipItemActivated(QListWidgetItem *item)
{
    hide();
    if (!isItemSelected(item)) return;
    
    QString text = item->text();
    QTextCursor cursor = textEdit->textCursor();
    cursor.setPosition(this->cursorPos);
    cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
    QString sel = cursor.selectedText();
    if (!sel.isEmpty()) {
        // in case the cursor moved too far on the right side
        const QChar underscore =  QLatin1Char('_');
        const QChar ch = sel.at(sel.count()-1);
        if (!ch.isLetterOrNumber() && ch != underscore)
            cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
    }
    cursor.insertText( text );

    // get CallTip from item's UserRole-data
    const CallTip &callTip = item->data(Qt::UserRole).value<CallTip>();

    // if call completion enabled and we've something callable (method or class constructor) ...
    if (this->doCallCompletion
     && (callTip.type == CallTip::Method || callTip.type == CallTip::Class))
    {
      cursor.insertText( QLatin1String("()") ); //< just append parenthesis to identifier even inserted.

      /**
       * Try to find out if call needs arguments.
       * For this we search the description for appropriate hints ...
       */
      QRegExp argumentMatcher( QRegExp::escape( callTip.name ) + QLatin1String("\\s*\\(\\s*\\w+.*\\)") );
      argumentMatcher.setMinimal( true ); //< set regex non-greedy!
      if (argumentMatcher.indexIn( callTip.description ) != -1)
      {
        // if arguments are needed, we just move the cursor one left, to between the parentheses.
        cursor.movePosition( QTextCursor::Left, QTextCursor::MoveAnchor, 1 );
        textEdit->setTextCursor( cursor );
      }
    }
    textEdit->ensureCursorVisible();

    QRect rect = textEdit->cursorRect(cursor);
    int posX = rect.x();
    int posY = rect.y();

    QPoint p(posX, posY);
    p = textEdit->mapToGlobal(p);
    QToolTip::showText( p, callTip.parameter );
}
Esempio n. 22
0
static void moveCursorToStartOrEndOfIdentifier(QTextCursor *tc,
                                               QTextCursor::MoveOperation op,
                                               int posDiff = 0)
{
    QTextDocument *doc = tc->document();
    if (!doc)
        return;

    QChar ch = doc->characterAt(tc->position() - posDiff);
    while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
        tc->movePosition(op);
        ch = doc->characterAt(tc->position() - posDiff);
    }
}
int KeywordsCompletionAssistProcessor::findStartOfName(int pos)
{
    if (pos == -1)
        pos = m_interface->position();

    QChar chr = m_interface->characterAt(pos-1);
    if (chr == QLatin1Char('('))
        --pos;
    // Skip to the start of a name
    do {
        chr = m_interface->characterAt(--pos);
    } while (chr.isLetterOrNumber() || chr == QLatin1Char('_'));

    int start = ++pos;
    m_word.clear();
    do {
        m_word += m_interface->characterAt(pos);
        chr = m_interface->characterAt(++pos);
    } while ((chr.isLetterOrNumber() || chr == QLatin1Char('_'))
             && chr != QLatin1Char('('));

    return start;
}
Esempio n. 24
0
void AccelString::calculateWeights(int initialWeight)
{
  m_weight.resize(m_pureText.length());

  int pos = 0;
  bool start_character = true;

  while (pos<m_pureText.length())
  {
    QChar c = m_pureText[pos];

    int weight = initialWeight+1;

    // add special weight to first character
    if (pos == 0)
      weight += AccelManagerAlgorithm::FIRST_CHARACTER_EXTRA_WEIGHT;

    // add weight to word beginnings
    if (start_character)
    {
      weight += AccelManagerAlgorithm::WORD_BEGINNING_EXTRA_WEIGHT;
      start_character = false;
    }

    // add decreasing weight to left characters
    if (pos < 50)
      weight += (50-pos);

    // try to preserve the wanted accelarators
    if ((int)pos == accel()) {
        weight += AccelManagerAlgorithm::WANTED_ACCEL_EXTRA_WEIGHT;
        // kDebug(240) << "wanted " << m_pureText << " " << AcceleratorManagerPrivate::standardName(m_origText);
        if (AcceleratorManagerPrivate::standardName(m_origText))  {
            weight += AccelManagerAlgorithm::STANDARD_ACCEL;
        }
    }

    // skip non typeable characters
    if (!c.isLetterOrNumber())
    {
      weight = 0;
      start_character = true;
    }

    m_weight[pos] = weight;

    ++pos;
  }
}
Esempio n. 25
0
QString TypePrettyPrinter::operator()(const FullySpecifiedType &type, const QString &name)
{
    const QString previousName = switchName(name);
    QString text = operator()(type);
    if (! _name.isEmpty() && ! text.isEmpty()) {
        const QChar ch = text.at(text.size() - 1);
        if (ch.isLetterOrNumber() || ch == QLatin1Char('_') || ch == QLatin1Char('>'))
            text += QLatin1Char(' ');
        text += _name;
    } else if (text.isEmpty()) {
        text = name;
    }
    (void) switchName(previousName);
    return text;
}
Esempio n. 26
0
//----------------------------------------------------------------------------
//
QString TelnetTCPClient::CleanQString(QString toClean)
{
    QString ret;
    ret.clear();
    int count = toClean.size();
    for ( int ic = 0 ; ic < count ; ic ++ )
    {
        QChar ch = toClean.at( ic );
        if ( ch.isLetterOrNumber() )
        {
            ret = ret.append( ch );
        }
    }
    return ret;
}
Esempio n. 27
0
int Lexer::getWord(QString& word)
{
	// kdDebug(0)<<"Lexer::getWord()"<<endl;
	QChar currentChar = getChar();
	if ( currentChar.isLetter() || currentChar == '[' || currentChar == ']' ) {
		while ( ( currentChar.isLetterOrNumber() || currentChar == '_' || currentChar == '[' || currentChar == ']' ) && !inputStream->atEnd() )
		{
			word += currentChar;
			currentChar = getChar();
		}
		kdDebug(0)<<"Lexer::getWord(), got NAME: '"<<word<<"'"<<endl;
		ungetChar(currentChar); //read one too much
		return tokUnknown; // returns tokUnknown, actual token is to be determained later in Lexer::setTokenType
	}
	else return tokError;
}
Esempio n. 28
0
bool validateKeyBlock(const QString &keyBlock, bool allowEmpty = false)
{
    const int length = keyBlock.length();
    if (allowEmpty && length == 0)
        return true;
    if (length != 5)
        return false;
    for (int i = 0; i < 5; ++i)
    {
        const QChar character = keyBlock.at(i);
        //only accept ASCII letters or arabic numbers
        if (!character.isLetterOrNumber() || character.unicode() >= 128)
            return false;
    }
    return true;
}
QTCREATOR_UTILS_EXPORT QString settingsKey(const QString &category)
{
    QString rc(category);
    const QChar underscore = QLatin1Char('_');
    // Remove the sort category "X.Category" -> "Category"
    if (rc.size() > 2 && rc.at(0).isLetter() && rc.at(1) == QLatin1Char('.'))
        rc.remove(0, 2);
    // Replace special characters
    const int size = rc.size();
    for (int i = 0; i < size; i++) {
        const QChar c = rc.at(i);
        if (!c.isLetterOrNumber() && c != underscore)
            rc[i] = underscore;
    }
    return rc;
}
Esempio n. 30
0
QString GLC_WorldTo3dxml::symplifyName(QString name)
{
	const int nameSize= name.size();
	for (int i= 0; i < nameSize; ++i)
	{
        const QChar curChar= name.at(i);
        bool simplifyCharacter= !curChar.isLetterOrNumber() && (curChar != '.');
        simplifyCharacter= simplifyCharacter && (curChar != '/') && (curChar != '\\');
        if (simplifyCharacter)
		{
			name.replace(i, 1, '_');
		}
	}

	return name;
}