Beispiel #1
0
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;
}
Beispiel #2
0
/**
 * Returns a the complete word defined by the current cursor position.
 * Attempts to extract a valid C symbol from the location of the cursor, by
 * starting at the current line and column, and looking forward and backward
 * for non-symbol characters.
 * @return	A C symbol under the cursor, if any, or QString::null otherwise
 */
QString EditorPage::getWordUnderCursor(uint* pPosInWord)
{
	KTextEditor::ViewCursorInterface* pCursor;
	KTextEditor::EditInterface* pEditIf;
	QString sLine;
	uint nLine, nCol, nFrom, nTo, nLast, nLength;
	QChar ch;

	// Get a cursor object
	pCursor = dynamic_cast<KTextEditor::ViewCursorInterface*>(m_pView);
	if (pCursor == NULL)
		return QString::null;

	// Get a pointer to the edit interface	
	pEditIf = dynamic_cast<KTextEditor::EditInterface*>(m_pDoc);
	if (!pEditIf)
		return QString::null;
	
	// Get the line on which the cursor is positioned
	pCursor->cursorPositionReal(&nLine, &nCol);
	sLine = pEditIf->textLine(nLine);
	
	// Find the beginning of the current word
	for (nFrom = nCol; nFrom > 0;) {
		ch = sLine.at(nFrom - 1);
		if (!ch.isLetter() && !ch.isDigit() && ch != '_')
			break;
		
		nFrom--;
	}
	
	// Find the end of the current word
	nLast = sLine.length();
	for (nTo = nCol; nTo < nLast;) {
		ch = sLine.at(nTo);
		if (!ch.isLetter() && !ch.isDigit() && ch != '_')
			break;
		
		nTo++;
	}
	
	// Mark empty words
	nLength = nTo - nFrom;
	if (nLength == 0)
		return QString::null;
	
	// Return the in-word position, if required
	if (pPosInWord != NULL)
		*pPosInWord = nCol - nFrom;
	
	// Extract the word under the cursor from the entire line
	return sLine.mid(nFrom, nLength);
}
Beispiel #3
0
QString QgsDxfExport::dxfLayerName( const QString& name )
{
  //dxf layers can be max 31 characters long
  QString layerName = name.left( 31 );

  //allowed characters are 0-9, A-Z, $, -, _
  for ( int i = 0; i < layerName.size(); ++i )
  {
    QChar c = layerName.at( i );
    if ( c > 122 )
    {
      layerName[i] = '_';
      continue;
    }

    if ( c.isNumber() )
    {
      continue;
    }
    if ( c == '$' || c == '-' || c == '_' )
    {
      continue;
    }

    if ( !c.isLetter() )
    {
      layerName[i] = '_';
    }
  }
  return layerName;
}
Beispiel #4
0
void WordPredict::setLetter(QChar c, const QPoint &p)
{
    if (!c.isLetter()) // useless junk, dispose it!
      return;
    m_layout[c] = p;
    m_alphabet += c;
}
Beispiel #5
0
void EditorCompletion::updateCompletionMap( Q3TextDocument *doc )
{
    bool strict = true;
    if ( doc != lastDoc )
	strict = false;
    lastDoc = doc;
    Q3TextParagraph *s = doc->firstParagraph();
    if ( !s->extraData() )
	s->setExtraData( new ParagData );
    while ( s ) {
	if ( s->length() == ( (ParagData*)s->extraData() )->lastLengthForCompletion ) {
	    s = s->next();
	    continue;
	}

	QChar c;
	QString buffer;
	for ( int i = 0; i < s->length(); ++i ) {
	    c = s->at( i )->c;
	    if ( c.isLetter() || c.isNumber() || c == '_' || c == '#' ) {
		buffer += c;
	    } else {
		addCompletionEntry( buffer, doc, strict );
		buffer = QString::null;
	    }
	}
	if ( !buffer.isEmpty() )
	    addCompletionEntry( buffer, doc, strict );

	( (ParagData*)s->extraData() )->lastLengthForCompletion = s->length();
	s = s->next();
    }
}
Beispiel #6
0
Word Filter::nextWord() const
{
    QChar currentChar = skipToLetter( m_currentPosition );

    if ( m_currentPosition >= m_buffer.length() ) {
        return Filter::end();
    }

    bool allUppercase = currentChar.category() & QChar::Letter_Uppercase;
    bool runTogether = false;

    QString foundWord;
    int start = m_currentPosition;
    while ( currentChar.isLetter() ) {
        if ( currentChar.category() & QChar::Letter_Lowercase )
            allUppercase = false;

	/* FIXME: this does not work for Hebrew for example
        //we consider run-together words as mixed-case words
        if ( !allUppercase &&
             currentChar.category() & QChar::Letter_Uppercase )
            runTogether = true;
	*/

        foundWord += currentChar;
        ++m_currentPosition;
        currentChar = m_buffer[ m_currentPosition ];
    }

    if ( shouldBeSkipped( allUppercase, runTogether, foundWord ) )
        return nextWord();

    return Word( foundWord, start );
}
void QuickAddCapacitorDialog::slotAttemptAutoComplete()
{
    QString text = ui->capacitanceValueLineEdit->text().trimmed();
    //We accept 3 digit value codes with an optional tolerance code
    if(text.length()==3 || text.length()==4){
        QString multiplicandStr = text.left(2);
        QChar multiplierChar = text.at(2);
        bool multiplicandOk;
        int multiplicand = multiplicandStr.toInt(&multiplicandOk);        
        if(multiplicandOk && multiplierChar.isDigit()){
            double capacitance = multiplicand * pow10(-12);
            int multiplierIdx = to_char(multiplierChar) - '0';
            if(multiplierIdx >= 0 && multiplierIdx <= 9){
                capacitance = capacitance * MULTIPLIERS[multiplierIdx];
            }
            QString capacitanceStr = UnitFormatter::format(capacitance, _capacitanceParam.unitSymbol());
            ui->capacitanceValueLineEdit->setText(capacitanceStr);
        }
        if(text.length()==4){
            QChar toleranceChar = text.at(3);
            if(toleranceChar.isLetter()){
                QString tolerance = lookupTolerance(to_char(toleranceChar));
                if(!tolerance.isEmpty()){
                    ui->toleranceLineEdit->setText(tolerance);
                }
            }
        }
    }

}
Beispiel #8
0
// TODO: will be a word in two lines ?
QString EditorPage::getWordUnderCursor(uint* pPosInWord)
{
	QString sLine;
	int nLine, nCol, nFrom, nTo, nLast, nLength;
	QChar ch;

	const KTextEditor::Cursor c = m_pView->cursorPosition();

	// Get the line on which the cursor is positioned
    c.position(nLine, nCol);
    const KTextEditor::Cursor cFrom(nLine, 0);
    const KTextEditor::Cursor cTo = m_pDoc->endOfLine(nLine);
    KTextEditor::Range range(cFrom, cTo);

    sLine = m_pDoc->text(range);
	
	// Find the beginning of the current word
	for (nFrom = nCol; nFrom > 0;) {
		ch = sLine.at(nFrom - 1);
		if (!ch.isLetter() && !ch.isDigit() && ch != '_')
			break;
		
		nFrom--;
	}
	
	// Find the end of the current word
	nLast = sLine.length();
	for (nTo = nCol; nTo < nLast;) {
		ch = sLine.at(nTo);
		if (!ch.isLetter() && !ch.isDigit() && ch != '_')
			break;
		
		nTo++;
	}

	// Mark empty words
	nLength = nTo - nFrom;
	if (nLength == 0)
		return QString::null;
	
	// Return the in-word position, if required
	if (pPosInWord != NULL)
		*pPosInWord = nCol - nFrom;
	
	// Extract the word under the cursor from the entire line
	return sLine.mid(nFrom, nLength);
}
void Scanner::consumeRegexpModifiers()
{
    QChar ch = m_src.peek();
    while (ch.isLetter() && ch.isLower()) {
        m_src.move();
        ch = m_src.peek();
    }
}
Beispiel #10
0
bool Tokenizer::isWordChar(const QChar& c)
{
	// this method exists because some languages have non-letter category charaters
	// mixed with their letter character to make words (like hindi)
	// NOTE: this has to be extended then languages give problems,
	//       just add a category in the following test
	return (c.isLetter() || c.isMark());
}
Beispiel #11
0
void CellItem::setChar(QChar c) {
	if (c.isLetter())
	{
		is_empty = false;
		this->c = c.toUpper();
		update();
	}
}
Beispiel #12
0
QChar Filter::skipToLetter( uint &fromPosition ) const
{

    QChar currentChar = m_buffer[ fromPosition ];
    while ( !currentChar.isLetter() &&
            ++fromPosition < m_buffer.length() ) {
        currentChar = m_buffer[ fromPosition ];
    }
    return currentChar;
}
Beispiel #13
0
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;
}
static bool checkStartOfIdentifier(const QString &word)
{
    if (! word.isEmpty()) {
        const QChar ch = word.at(0);
        if (ch.isLetter() || ch == QLatin1Char('_'))
            return true;
    }

    return false;
}
QStringList CommandExecutionEngine::tokenizeNonQuoted(const QString& string)
{
	//TODO The concept of tokens here is unclear. Define this better.
	QStringList result;
	QString str;

	QChar last;
	bool fractionInitiated = false;

	for (int i = 0; i < string.size(); ++i)
	{
		if ( string[i] == ' ' )
		{
			if ( !str.isNull() ) result.append(str);
			str = QString();
			fractionInitiated = false;
		}
		else if ( string[i].isDigit() && fractionInitiated && last == '.' )
		{
			str = result.last() + '.' + string[i];
			result.removeLast();
			fractionInitiated = false;
		}
		else if ( string[i].isDigit() && str.isNull() )
		{
			fractionInitiated = true;
			str += string[i];
		}
		else if ( string[i] == '.' && fractionInitiated )
		{
			result.append(str);
			str = ".";
		}
		else if ( string[i].isDigit() && fractionInitiated )
		{
			str += string[i];
		}
		else if ( (string[i].isLetter() || string[i].isDigit() || string[i] == '_') != (last.isLetter() || last.isDigit() || last == '_') )
		{
			if ( !str.isNull() ) result.append(str);
			str = string[i];
			fractionInitiated = false;
		}
		else
		{
			str += string[i];
		}

		last = string[i];
	}

	if ( !str.isNull() ) result.append(str);
	return result;
}
Beispiel #16
0
bool HTMLSpellCheck::IsBoundary(QChar prev_c, QChar c, QChar next_c, const QString & wordChars)
{
    if (c.isLetter()) {
        return false;
    }

    // Single quotes of ' and curly version and hyphen/emdash are sometimes a boundary
    // and sometimes not, depending on whether they are surrounded by letters or not.
    // A sentence which 'has some text' should treat the ' as a boundary but didn't should not.
    bool is_potential_boundary = (c == '-' || 
                                  c == QChar(0x2012) || 
                                  c == '\'' || 
                                  c == QChar(0x2019) ||
                                  (!wordChars.isEmpty() && wordChars.contains(c)));

    if (is_potential_boundary && (!prev_c.isLetter() || !next_c.isLetter())) {
        return true;
    }

    return !(is_potential_boundary && (prev_c.isLetter() || next_c.isLetter()));
}
Beispiel #17
0
TokenPtr Lexer::nextToken()
{
    while (true)
    {
        while (peek().isSpace())
        {
            consume();
        }

        QChar next = peek();
        d->newSpan();

        if (next.isNull())
        {
            return TokenPtr();
        }
        else if (next == '{')
        {
            consume();
            return TokenPtr(new LeftBraceToken(d->currentSpan()));
        }
        else if (next == '}')
        {
            consume();
            return TokenPtr(new RightBraceToken(d->currentSpan()));
        }
        else if (next == '=')
        {
            consume();
            return TokenPtr(new EqualsToken(d->currentSpan()));
        }
        else if (next.isLetter())
        {
            return lexIdentifiers();
        }
        else if (next == '"')
        {
            return lexStrings();
        }
        else if (next.isDigit() || next == '-')
        {
            return lexNumeric();
        }
        else if (next == '#')
        {
            consumeToEnd();
            continue;
        }

        throw exceptions::UnmatchedInputException(currentPos(), next);
    }
}
bool CodeCompletionModelControllerInterface::shouldStartCompletion(View* view, const QString &insertedText, bool userInsertion, const Cursor &position)
{
    Q_UNUSED(view);
    Q_UNUSED(position);
    if(insertedText.isEmpty())
        return false;

    QChar lastChar = insertedText.at(insertedText.count() - 1);
    if ((userInsertion && (lastChar.isLetter() || lastChar.isNumber() || lastChar == '_')) ||
        lastChar == '.' || insertedText.endsWith(QLatin1String("->"))) {
        return true;
    }
    return false;
}
long LXMLVar::What( const QChar S )
//            ~~~~
{
	for(;;)
	{
		if( S.isLetter() || (S == _T('_')) )
			return 1;
		if( S.isDigit() || ( S == _T('-') ) || ( S == _T('.') ) )
			return 2;
		if( S == _T(':') )
			return 3;
		return 0;
	}
}
Beispiel #20
0
static bool checkStartOfIdentifier(const QString &word)
{
    if (word.isEmpty())
        return false;

    const QChar ch = word.at(0);

    switch (ch.unicode()) {
    case '_': case '$':
        return true;

    default:
        return ch.isLetter();
    }
}
Beispiel #21
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;
}
QString DurationSpinBox::extractUnit ( const QString &text ) const
{
    //kDebug(planDbg())<<text;
    QString s;
    for ( int i = text.length() - 1; i >= 0; --i ) {
        QChar c = text[ i ];
        if ( ! c.isLetter() ) {
            break;
        }
        s.prepend( c );
    }
    if ( Duration::unitList( true ).contains( s ) ) {
        return s;
    }
    return QString();
}
Beispiel #23
0
bool isIdentifierChar(const QChar &c, bool atStart, bool acceptDollar)
{
    switch (c.unicode()) {
    case '_':
        return true;
    case '$':
        if (acceptDollar)
            return true;
        return false;

    default:
        if (atStart)
            return c.isLetter();
        else
            return c.isLetterOrNumber();
    }
}
Beispiel #24
0
VersionNumber::characterType VersionNumber::helper_characterType(const QChar & value)
{
    // variables
    characterType returnValue;

    // code
    if (value.isLetter()) {
        returnValue = letter;
    } else {
        if (value.isDigit()) {
            returnValue = digit;
        } else {
            returnValue = other;
        };
    };
    return returnValue;
}
Beispiel #25
0
QString CssSelector::parse(const QString& input)
{
    QString str = input;
    sub_.clear();
    source_ = input;
    bool can_be_class_name = true;
    bool can_be_object_name = true;
    while(str.length()>0) {
    //for (int i = 0; i < str.length(); ++i) {
        QChar character = str[0];
        ValidatorPtr validator = nullptr;
        if(can_be_object_name && character == '#') {
            validator.reset(new ValidatorName);
        }
        // Class name
        else if(can_be_class_name && character.isLetter()) {
            validator.reset(new ValidatorClassName);
        }
        else if(character == '"') {
            validator.reset(new ValidatorGUIText);
        }
        else if(character == '[') {
            validator.reset(new ValidatorProperty);
        }
        // End of selector
        else if(character == ' ') {
            return str.mid(1);
        }
        else {
            throw std::runtime_error((QString("Unparsable CSS: ")+input).toStdString());
        }
        if(validator != nullptr) {
            str = validator->parse(str);
            sub_.push_back(ValidatorPtr(validator));
        }
        else {
            throw std::runtime_error((QString("Impossible CSS error (consider yourself lucky): ")+input).toStdString());
        }

        if(!can_be_class_name)
            can_be_object_name = false;
        can_be_class_name = false;
    }
    return str;
}
Token Scanner::readPercentageNotation()
{
    QChar ch = m_src.peek();
    if (ch.isSpace() || ch.isDigit())
        return Token(Token::Operator, m_src.anchor(), m_src.length());

    State state = State_String;
    if (ch.isLetter()) {
        if (ch == 'r')
            state = State_Regexp;
        if (ch == 'i')
            state = State_Symbols;
        m_src.move();
    }
    QChar delimiter = translateDelimiter(m_src.peek());
    m_src.move();
    return readStringLiteral(delimiter, state);
}
Beispiel #27
0
QPair<QString, int> NickListModel::nickPairFromString(const QString &nick)
{
  int flags = NoPrivileges;
  int i;
  for (i = 0; i < nick.count(); i++) {
    const QChar c = nick.at(i);
    if (c.isLetter()) {
      break;
    }
    else if (c == '@') {
      flags |= OpPrivileges;
    }
    else if (c == '+') {
      flags |= VoicePrivileges;
    }
  }
  return QPair<QString, int>(nick.mid(i), flags);
}
void ProFileHighlighter::highlightBlock(const QString &text)
{
    if (text.isEmpty())
        return;

    QString buf;
    bool inCommentMode = false;

    QTextCharFormat emptyFormat;
    int i = 0;
    for (;;) {
        const QChar c = text.at(i);
        if (inCommentMode) {
            setFormat(i, 1, formatForCategory(ProfileCommentFormat));
        } else {
            if (c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('.') || c.isDigit()) {
                buf += c;
                setFormat(i - buf.length()+1, buf.length(), emptyFormat);
                if (!buf.isEmpty() && m_keywords.isFunction(buf))
                    setFormat(i - buf.length()+1, buf.length(), formatForCategory(ProfileFunctionFormat));
                else if (!buf.isEmpty() && m_keywords.isVariable(buf))
                    setFormat(i - buf.length()+1, buf.length(), formatForCategory(ProfileVariableFormat));
            } else if (c == QLatin1Char('(')) {
                if (!buf.isEmpty() && m_keywords.isFunction(buf))
                    setFormat(i - buf.length(), buf.length(), formatForCategory(ProfileFunctionFormat));
                buf.clear();
            } else if (c == QLatin1Char('#')) {
                inCommentMode = true;
                setFormat(i, 1, formatForCategory(ProfileCommentFormat));
                buf.clear();
            } else {
                if (!buf.isEmpty() && m_keywords.isVariable(buf))
                    setFormat(i - buf.length(), buf.length(), formatForCategory(ProfileVariableFormat));
                buf.clear();
            }
        }
        i++;
        if (i >= text.length())
            break;
    }

    applyFormatToSpaces(text, formatForCategory(ProfileVisualWhitespaceFormat));
}
Beispiel #29
0
	void encodeFileName(QString & szPath)
	{
		QString szSrc(szPath);
		szPath = "";
		for(int i = 0; i < szSrc.length(); i++)
		{
			QChar cur = szSrc[i];
			if( ! (cur.isLetter() || cur.isDigit() || cur==' ' || cur=='_' || cur=='.' || cur=='#' || cur=='%') )
			{
				if(cur.row()!=0)
				{
					szPath += '%';
					szPath += cHexChars[cur.row() >> 4];
					szPath += cHexChars[cur.row() & 15];
				}
				szPath += '%';
				szPath += cHexChars[cur.cell() >> 4];
				szPath += cHexChars[cur.cell() & 15];
			} else if (cur=='%')
QString base_text_editor::_highlight_keywords(QString src, int &tab) {
    QList<QString> tokens;
    bool in_word = false;
    QString word = "";
    for (int i = 0; i < src.size(); i++) {
        QChar c = src[i];
        if (c.isLetter() || c.isDigit() || c == '_') {
            in_word = true;
            word += c;
        } else {
            if (in_word) {
                in_word = false;
                tokens.push_back(word);
                word.clear();
            }
            tokens.push_back(c);
        }
    }
    if (!word.isEmpty())
        tokens.push_back(word);

    QString ret = "";
    tab = 0;
    for (int i = 0; i < tokens.size(); i++) {
        QString token = tokens[i];
        if (token == " ")
            ret += "&nbsp;";
        else if (token == "\n")
            ret += "<br/>";
        else if (token == "\t") {
            ret += "&nbsp;&nbsp;&nbsp;&nbsp;";
            tab += 3;
        }
        else if (token == "<")
            ret += "&lt;";
        else if (_is_keyword(token))
            ret += "<font color='#0000ff'>" + token + "</font>";
        else
            ret += token;
    }

    return ret;
}