示例#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;
}
示例#2
0
// Function: PROPER
Value func_proper(valVector args, ValueCalc *calc, FuncExtra *)
{
    QString str = calc->conv()->asString(args[0]).asString().toLower();

    QChar f;
    bool  first = true;

    for (int i = 0; i < str.length(); ++i) {
        if (first) {
            f = str[i];
            if (f.isNumber())
                continue;

            f = f.toUpper();

            str[i] = f;
            first = false;

            continue;
        }

        if (str[i].isSpace() || str[i].isPunct())
            first = true;
    }

    return Value(str);
}
示例#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;
}
示例#4
0
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();
}
示例#5
0
void Coefficient::getNumer(QString& fractionRep, int& numerInt, bool& hasDenom)
{
    QString numerString;

    int numeratorSize = 0;

    for(int i = 0; i<fractionRep.size(); i++)
    {
        QChar ch = fractionRep.at(i);

        if(ch.isNumber() || (ch=='-' || ch=='+') )
            numerString += ch;

        else if (ch=='/' || ch=='\\')
        {
            hasDenom = true;
            numerInt = numerString.toInt();
            fractionRep.remove(0,numeratorSize);
            return;
        }

        else
            numerInt = 0;

        numeratorSize++;

    }

    numerInt = numerString.toInt();
}
示例#6
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();
    }
}
示例#7
0
	static int DecodeEscapedChar(QString & password,int idx)
	{
		QChar a = password[idx + 1].lower();
		QChar b = password[idx + 2].lower();
		if (!a.isNumber() && !(a.latin1() >= 'a' && a.latin1() <= 'f'))
			return idx + 2; // not a valid hex digit
		
		if (!b.isNumber() && !(b.latin1() >= 'a' && b.latin1() <= 'f'))
			return idx + 2; // not a valid hex digit
		
		// calculate high and low nibble
		Uint8 h = (a.latin1() - (a.isNumber() ? '0' : 'a')) << 4;
		Uint8 l = (b.latin1() - (b.isNumber() ? '0' : 'a'));
		char r = (char) h | l; // combine them and cast to a char
		password.replace(idx,3,r);
		return idx + 1;
	}
示例#8
0
 bool isNumber(const QChar &ch)
 {
     if (ch.isNumber()) {
         return true;
     }
     if (QString(QLatin1String( ".,-+" )).contains( ch )) {
         return true;
     }
     return false;
 }
示例#9
0
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 );
}
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;
}
示例#11
0
int Lexer::getNumber(Value& num, QString& look)
{
	// by reference the value (Value) and look part are set
	// kdDebug(0)<<"Lexer::getNumber()"<<endl;
	bool hasPoint = false;
	QChar currentChar = getChar();
	if ( currentChar.isNumber() )
	{
		while ( ( currentChar.isNumber() || (currentChar == '.' && !hasPoint) ) && !inputStream->atEnd() )
		{
			if (currentChar == '.')
			{
				hasPoint = true;
			}
			look += currentChar;
			currentChar = getChar();
		}
		ungetChar(currentChar); //read one too much
		num.setNumber( look.toDouble() );
		kdDebug(0)<<"Lexer::getNumber(), got NUMBER: '"<<num.Number()<<"'"<<endl;
		return tokNumber;
	}
	else return tokError;
}
示例#12
0
void Coefficient::getDenom(QString& fractionRep, int& denomInt)
{
    QString denomString;

    for(int i = 0; i<fractionRep.size(); i++)
    {
        QChar ch = fractionRep.at(i);

        if(ch.isNumber())
            denomString += ch;

        else
            denomInt = 1;
    }

    denomInt = denomString.toInt();
}
示例#13
0
Token Lexer::lex()
{
	skipSpaces(); // skips the white space that it quite likely (indentation) infront of the Token

	Token currentToken;
	currentToken.type = tokNotSet; // not really needed
	currentToken.look = "";
	currentToken.value = 0;
	currentToken.start.row = row;
	currentToken.start.col = col;

	QChar currentChar = getChar();

	if ( inputStream->atEnd() )
	{
		kdDebug(0)<<"Lexer::lex(), got EOF."<<endl;
		currentToken.type = tokEOF;
		currentToken.look = "EOF";
		ungetChar(currentChar); // unget the currentChar and fix the row/col values
		return currentToken;
	}

	if (currentChar == '#')
	{
		while ( !inputStream->atEnd() && !(currentChar == '\x0a' || currentChar == '\n') )
			currentChar = getChar();
	}
	
	// if (currentChar.category() == QChar::Separator_Line) somehow doesnt work
	if (currentChar == '\x0a' || currentChar == '\n')
	{
		currentToken.type = tokEOL;
		currentToken.look = "EOL";
	}
	else if (currentChar.isLetter() || currentChar == '[' || currentChar == ']')
	{
		ungetChar(currentChar);
		// sets currentToken.look by reference, and set the currentToken.type to tokUnknown
		currentToken.type = getWord(currentToken.look);
		setTokenType(currentToken); // gets the actual tokenType
	}
	else if ( currentChar.isNumber() )
	{
		ungetChar(currentChar);
		// set currentToken.value/look by reference, and set the currentToken.type to tokNumber
		currentToken.type = getNumber(currentToken.value, currentToken.look);
	}
	else if (currentChar == '>')
	{
		currentChar = getChar();
		if (currentChar == '=')
		{
			currentToken.type = tokGe;
			currentToken.look = ">=";
		}
		else
		{
			ungetChar(currentChar);
			currentToken.type = tokGt;
			currentToken.look = ">";
		}
	}
	else if (currentChar == '<')
	{
		currentChar = getChar();
		if ( currentChar == '=' )
		{
			currentToken.type = tokLe;
			currentToken.look = "<=";
		}
		else
		{
			ungetChar(currentChar);
			currentToken.type = tokLt;
			currentToken.look = ">";
		}
	}
	else if (currentChar == '!')
	{
		currentChar = getChar();
		if (currentChar == '=')
		{
			currentToken.type = tokNe;
			currentToken.look = "!=";
		}
		else
		{
			ungetChar(currentChar);
			currentToken.type = tokNot;
			currentToken.look = "!";
		}
	}
	else if (currentChar == '=')
	{
		currentChar = getChar();
		if (currentChar == '=')
		{
			currentToken.type = tokEq;
			currentToken.look = "==";
		}
		else
		{
			ungetChar(currentChar);
			currentToken.type = tokAssign;
			currentToken.look = "=";
		}
	}
	else if (currentChar == '(')
	{
		currentToken.type = tokBraceOpen;
		currentToken.look = "(";
	}
	else if (currentChar == ')')
	{
		currentToken.type = tokBraceClose;
		currentToken.look = ")";
	}
	else if (currentChar == '+')
	{
		currentToken.type = tokPlus;
		currentToken.look = "+";
	}
	else if (currentChar == '-')
	{
		currentToken.type = tokMinus;
		currentToken.look = "-";
	}
	else if (currentChar == '*')
	{
		currentToken.type = tokMul;
		currentToken.look = "*";
	}
	else if (currentChar == '/')
	{
		currentToken.type = tokDev;
		currentToken.look = "/";
	}
	else if (currentChar == ',')
	{
		currentToken.type = tokComma;
		currentToken.look = ",";
	}
	else if (currentChar == '"')
	{
		getString(currentToken);
	}
	else
	{
		currentToken.type = tokUnknown;
		currentToken.look = currentChar;
	}
	
	currentToken.end.row = row;
	currentToken.end.col = col;
	return currentToken;
}
示例#14
0
QString FLUtil::nextSequence(int nivel, const QString &secuencia, const QString &ultimo)
{
  QString cadena;
  QString valor;
  QString string;
  QString string2;

  QChar temp;
  long num;
  int pos2 = 0;
  int nivpas = 0;
  int posult = 0;

  int niveles = secuencia.contains("%A") + secuencia.contains("%N");
  int pos = 1;
  pos2 = secuencia.find("%", 0);

  while (pos2 != -1) {
    if (nivpas == 0) {
      cadena = secuencia.mid(0, pos2);
      posult = pos2;
    } else {
      string2 = secuencia.mid(pos + 2, pos2 - pos - 2);
      posult = ultimo.find(string2, posult) + string2.length();
      cadena = cadena + secuencia.mid(pos + 2, pos2 - pos - 2);
    }

    pos = pos2;
    valor = "";
    if (nivpas < niveles - nivel) {
      for (uint i = posult; i < ultimo.length(); ++i) {
        if (secuencia.mid(pos + 1, 1) == "A") {
          temp = ultimo.at(i);
          if (temp.isLetter() == false) {
            cadena = cadena + valor;
            break;
          }
          valor = valor + temp;
        }
        if (secuencia.mid(pos + 1, 1) == "N") {
          temp = ultimo.at(i);
          if (temp.isNumber() == false) {
            cadena = cadena + valor;
            break;
          }
          valor = valor + temp;
        }
      }
      posult = posult + valor.length();
    } else if (nivpas == niveles - nivel) {
      for (uint i = posult; i < ultimo.length(); ++i) {
        if (secuencia.mid(pos + 1, 1) == "A") {
          temp = ultimo.at(i);
          if (i == (ultimo.length() - 1)) {
            valor = valor + temp;
            num = serialLettertoNumber(valor).toLong() + 1;
            cadena = cadena + serialNumbertoLetter(num);
            break;
          }
          if (temp.isLetter() == false) {
            num = serialLettertoNumber(valor).toLong() + 1;
            cadena = cadena + serialNumbertoLetter(num);
            break;
          }
          valor = valor + temp;
        }
        if (secuencia.mid(pos + 1, 1) == "N") {
          temp = ultimo.at(i);
          if (i == (ultimo.length() - 1)) {
            valor = valor + temp;
            cadena = cadena + string.setNum(valor.toInt() + 1);
            break;
          }
          if (temp.isNumber() == false) {
            cadena = cadena + string.setNum(valor.toInt() + 1);
            break;
          }
          valor = valor + temp;
        }
      }
      posult = posult + valor.length();
    } else {
      if (secuencia.mid(pos + 1, 1) == "N")
        cadena = cadena + "1";
      if (secuencia.mid(pos + 1, 1) == "A")
        cadena = cadena + "A";
    }
    pos2 = secuencia.find("%", pos + 1);
    nivpas++;
  }
  return cadena;
}
DevHighlighter::BlockState CppHighlighter::process(	const QString& text,
													BlockData *bd)
{
	QChar c;
	QString s;
	const QChar *str = text.data();
	int i, n = i = 0, len = text.length();
	
	switch ( previousBlockState() )
	{
		case comment :
			i = text.indexOf("*/");
			
			if ( i == -1 )
			{
				setFormat(0, len, fmts[comment]);
				
				return comment;
			}
			
			setFormat(0, i+2, fmts[comment]);
			i--;
			break;
			
		case quote :
			do
			{
				i = text.indexOf("\"", i);
					
				if ( i == -1 )
				{
					setFormat(n, len-n, fmts[quote]);
					
					if ( text.endsWith('\\') )
						return quote;
					
					return normal;
				}
			} while ( text.at(i-1)=='\\' );
			
			setFormat(0, i+1, fmts[quote]);
			//i--;
			break;
		
		case preprocessor :
			
			setFormat(0, len, fmts[preprocessor]);
			
			while ( i<len )
			{
				if ( (i = text.indexOf('/', i)) == -1 )
					break;
				n = i;
				switch ( text.at(++i).toLatin1() )
				{
					case '/':
						setFormat(n, len-n, fmts[comment]);
						
						return normal;
						
					case '*':
						i = text.indexOf("*/", ++i);
						
						if ( i == -1 )
						{
							setFormat(n, len-n, fmts[comment]);
							
							return comment;
						}
						
						setFormat(n, i-n+2, fmts[comment]);
						break;
				}
			}
			
			if ( str[len-1] == '\\' )
				return preprocessor;
			
			return normal;
			
		default:
			i = -1;
			break;
	}
	
	while ( i < len )
	{
		do
		{
			c = str[++i];
		} while ( c.isSpace() );
		
		n = i;
		
		if ( c == '/' )
		{
			switch ( str[++i].toLatin1() )
			{
				case '/':
					setFormat(n, len-n, fmts[comment]);
					
					return normal;
					
				case '*':
					i = text.indexOf("*/", n);
					
					if ( i == -1 )
					{
						setFormat(n, len-n, fmts[comment]);
						
						return comment;
					}
					
					setFormat(n, i-n+2, fmts[comment]);
					break;
			}
		}
		else if ( c == '#' )
		{
			setFormat(n, len-n, fmts[preprocessor]);
			
			while ( i<len )
			{
				if ( (i = text.indexOf('/', i)) == -1 )
					break;
				n = i;
				switch ( text.at(++i).toLatin1() )
				{
					case '/':
						setFormat(n, len-n, fmts[comment]);
						
						return normal;
						
					case '*':
						i = text.indexOf("*/", ++i);
						
						if ( i == -1 )
						{
							setFormat(n, len-n, fmts[comment]);
							
							return comment;
						}
						
						setFormat(n, i-n+2, fmts[comment]);
						break;
				}
			} 
			
			if ( str[len-1] == '\\' )
				return preprocessor;
			else
				return normal;
		}
		else if ( c=='\'' )
		{
			do
			{
				i = text.indexOf("\'", ++i);
					
				if ( i == -1 )
				{
					setFormat(n, len-n, fmts[quote]);
					
					return normal;
				}
			} while ( text.at(i-1)=='\\' );
			
			setFormat(n, i-n+1, fmts[quote]);
		}
		else if ( c=='\"' )
		{
			do
			{
				i = text.indexOf("\"", ++i);
					
				if ( i == -1 )
				{
					setFormat(n, len-n, fmts[quote]);
					
					if ( str[len-1]=='\\' )
						return quote;
					else
						return normal;
				}
			} while ( text.at(i-1)=='\\' );
			
			setFormat(n, i-n+1, fmts[quote]);
		}
		else if ( c.isLetter() || (c == '_') )
		{
			do
			{
				c = str[++i];
			} while ( c.isLetterOrNumber() || (c == '_') );
			
			s = QString(str+n, i-n);
			
			for (int j=0; j<keywords; j++)
			{
				if ( s != kwds[j] )
					continue;
				
				setFormat(n, s.count(), fmts[keyword]);
				break;
			}
			i--;
		}
		else if ( c.isNumber() )
		{
			char base = 10;
			
			if ( str[i] == '0' )
			{
				base = 8;
				if ( str[i+1] == 'x' )
				{
					base = 16;
					i++;
				}
			}
			
			do
			{
				c = str[++i];
			} while ( 	DevQt::isNumber(c.toLatin1(), base) || ( (base==10) && 
					((c=='.') || (c=='e') || (c=='E') || (c=='f') || (c=='F')) )
					);
			
			s = QString(str+n, i-n);
			i--;
			
			if (base == 10 && (
				(s.count('e', Qt::CaseInsensitive)>1) || 
				(s.count('f', Qt::CaseInsensitive)>1)  ) )
				continue;
			
			setFormat(n, s.count(), fmts[number]);
		} else if ( c == '{' ) {
			bd->parentheses << Parenthesis(Parenthesis::Open, c, i);
			//TODO : add collapsing stuffs
		} else if ( c == '(' || c == '[' ) {
			bd->parentheses << Parenthesis(Parenthesis::Open, c, i);
		} else if ( c == '}' ) {
			bd->parentheses << Parenthesis(Parenthesis::Closed, c, i);
			//TODO : add collapsing stuffs
		} else if ( c == ')' ||  c == ']' ) {
			bd->parentheses << Parenthesis(Parenthesis::Closed, c, i);
		}
	}
	
	return normal;
}
示例#16
0
bool isValidIdentifierChar(const QChar &ch)
{
    return isValidFirstIdentifierChar(ch) || ch.isNumber();
}
示例#17
0
 foreach (QChar c, str) {
     if (!c.isNumber()) {
         return false;
     }
 }
示例#18
0
QList<Token> Scanner::operator()(const QString &text, int startState)
{
    _state = startState;
    QList<Token> tokens;

    // ### handle multi line comment state.

    int index = 0;

    if (_state == MultiLineComment) {
        const int start = index;
        while (index < text.length()) {
            const QChar ch = text.at(index);
            QChar la;
            if (index + 1 < text.length())
                la = text.at(index + 1);

            if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
                _state = Normal;
                index += 2;
                break;
            } else {
                ++index;
            }
        }

        if (_scanComments)
            tokens.append(Token(start, index - start, Token::Comment));
    }

    while (index < text.length()) {
        const QChar ch = text.at(index);

        QChar la; // lookahead char
        if (index + 1 < text.length())
            la = text.at(index + 1);

        switch (ch.unicode()) {
        case '/':
            if (la == QLatin1Char('/')) {
                if (_scanComments)
                    tokens.append(Token(index, text.length() - index, Token::Comment));
                index = text.length();
            } else if (la == QLatin1Char('*')) {
                const int start = index;
                index += 2;
                _state = MultiLineComment;
                while (index < text.length()) {
                    const QChar ch = text.at(index);
                    QChar la;
                    if (index + 1 < text.length())
                        la = text.at(index + 1);

                    if (ch == QLatin1Char('*') && la == QLatin1Char('/')) {
                        _state = Normal;
                        index += 2;
                        break;
                    } else {
                        ++index;
                    }
                }
                if (_scanComments)
                    tokens.append(Token(start, index - start, Token::Comment));
            } else {
                tokens.append(Token(index++, 1, Token::Delimiter));
            }
            break;

        case '\'':
        case '"': {
            const QChar quote = ch;
            const int start = index;
            ++index;
            while (index < text.length()) {
                const QChar ch = text.at(index);

                if (ch == quote)
                    break;
                else if (index + 1 < text.length() && ch == QLatin1Char('\\'))
                    index += 2;
                else
                    ++index;
            }

            if (index < text.length()) {
                ++index;
                // good one
            } else {
                // unfinished
            }

            tokens.append(Token(start, index - start, Token::String));
        } break;

        case '.':
            if (la.isDigit()) {
                const int start = index;
                do {
                    ++index;
                } while (index < text.length() && isNumberChar(text.at(index)));
                tokens.append(Token(start, index - start, Token::Number));
                break;
            }
            tokens.append(Token(index++, 1, Token::Dot));
            break;

         case '(':
            tokens.append(Token(index++, 1, Token::LeftParenthesis));
            break;

         case ')':
            tokens.append(Token(index++, 1, Token::RightParenthesis));
            break;

         case '[':
            tokens.append(Token(index++, 1, Token::LeftBracket));
            break;

         case ']':
            tokens.append(Token(index++, 1, Token::RightBracket));
            break;

         case '{':
            tokens.append(Token(index++, 1, Token::LeftBrace));
            break;

         case '}':
            tokens.append(Token(index++, 1, Token::RightBrace));
            break;

         case ';':
            tokens.append(Token(index++, 1, Token::Semicolon));
            break;

         case ':':
            tokens.append(Token(index++, 1, Token::Colon));
            break;

         case ',':
            tokens.append(Token(index++, 1, Token::Comma));
            break;

        default:
            if (ch.isSpace()) {
                do {
                    ++index;
                } while (index < text.length() && text.at(index).isSpace());
            } else if (ch.isNumber()) {
                const int start = index;
                do {
                    ++index;
                } while (index < text.length() && isNumberChar(text.at(index)));
                tokens.append(Token(start, index - start, Token::Number));
            } else if (ch.isLetter() || ch == QLatin1Char('_') || ch == QLatin1Char('$')) {
                const int start = index;
                do {
                    ++index;
                } while (index < text.length() && isIdentifierChar(text.at(index)));

                if (isKeyword(text.mid(start, index - start)))
                    tokens.append(Token(start, index - start, Token::Keyword)); // ### fixme
                else
                    tokens.append(Token(start, index - start, Token::Identifier));
            } else {
                tokens.append(Token(index++, 1, Token::Delimiter));
            }
        } // end of switch
    }

    return tokens;
}
示例#19
0
bool EditorCompletion::doCompletion()
{
    searchString = "";
    if ( !curEditor )
	return false;

    Q3TextCursor *cursor = curEditor->textCursor();
    Q3TextDocument *doc = curEditor->document();

    if ( cursor->index() > 0 && cursor->paragraph()->at( cursor->index() - 1 )->c == '.' &&
	 ( cursor->index() == 1 || cursor->paragraph()->at( cursor->index() - 2 )->c != '.' ) )
	return doObjectCompletion();

    int idx = cursor->index();
    if ( idx == 0 )
	return false;
    QChar c = cursor->paragraph()->at( idx - 1 )->c;
    if ( !c.isLetter() && !c.isNumber() && c != '_' && c != '#' )
	return false;

    QString s;
    idx--;
    completionOffset = 1;
    for (;;) {
	s.prepend( QString( cursor->paragraph()->at( idx )->c ) );
	idx--;
	if ( idx < 0 )
	    break;
	if ( !cursor->paragraph()->at( idx )->c.isLetter() &&
	     !cursor->paragraph()->at( idx )->c.isNumber() &&
	     cursor->paragraph()->at( idx )->c != '_' &&
	     cursor->paragraph()->at( idx )->c != '#' )
	    break;
	completionOffset++;
    }

    searchString = s;

    QList<CompletionEntry> lst( completionList( s, doc ) );
    if ( lst.count() > 1 ) {
	Q3TextStringChar *chr = cursor->paragraph()->at( cursor->index() );
	int h = cursor->paragraph()->lineHeightOfChar( cursor->index() );
	int x = cursor->paragraph()->rect().x() + chr->x;
	int y, dummy;
	cursor->paragraph()->lineHeightOfChar( cursor->index(), &dummy, &y );
	y += cursor->paragraph()->rect().y();
	completionListBox->clear();
	for ( QList<CompletionEntry>::ConstIterator it = lst.begin(); it != lst.end(); ++it )
	    (void)new CompletionItem( completionListBox, (*it).text, (*it).type, (*it).postfix,
				      (*it).prefix, (*it).postfix2 );
	cList = lst;
	completionPopup->resize( completionListBox->sizeHint() +
				 QSize( completionListBox->verticalScrollBar()->width() + 4,
					completionListBox->horizontalScrollBar()->height() + 4 ) );
	completionListBox->setCurrentItem( 0 );
	if ( curEditor->mapToGlobal( QPoint( 0, y ) ).y() + h + completionPopup->height() < QApplication::desktop()->height() )
	    completionPopup->move( curEditor->mapToGlobal( curEditor->
							   contentsToViewport( QPoint( x, y + h ) ) ) );
	else
	    completionPopup->move( curEditor->mapToGlobal( curEditor->
							   contentsToViewport( QPoint( x, y - completionPopup->height() ) ) ) );
	completionPopup->show();
    } else if ( lst.count() == 1 ) {
	curEditor->insert( lst.first().text.mid( completionOffset, 0xFFFFFF ),
 			   (uint) ( Q3TextEdit::RedoIndentation |
				    Q3TextEdit::CheckNewLines |
				    Q3TextEdit::RemoveSelected ) );
    } else {
	return false;
    }

    return true;
}
示例#20
0
void Lexer::nextToken( Token& tk, bool stopOnNewline )
{
    int op = 0;

    if( m_size == (int)m_tokens.size() ){
	m_tokens.resize( m_tokens.size() + 5000 + 1 );
    }

    readWhiteSpaces( !stopOnNewline );

    int startLine = m_currentLine;
    int startColumn = m_currentColumn;

    QChar ch = currentChar();
    QChar ch1 = peekChar();

    if( ch.isNull() || ch.isSpace() ){
	/* skip */
    } else if( m_startLine && ch == '#' ){

	nextChar(); // skip #
	readWhiteSpaces( false );	    // skip white spaces
	m_startLine = false;

	int start = currentPosition();
	readIdentifier(); // read the directive
	QString directive = m_source.mid( start, currentPosition() - start );

	handleDirective( directive );
    } else if( m_startLine && m_skipping[ m_ifLevel ] ){
	// skip line and continue
        m_startLine = false;
        int ppe = preprocessorEnabled();
	setPreprocessorEnabled( false );
	while( currentChar() && currentChar() != '\n' ){
            Token tok(m_source);
            nextToken( tok, true );
        }
        ++m_skippedLines;
        m_startLine = true;
        setPreprocessorEnabled( ppe );
        return;
    } else if( ch == '/' && ch1 == '/' ){
	int start = currentPosition();
	readLineComment();
	if( recordComments() ){
	    tk = CREATE_TOKEN( Token_comment, start, currentPosition() - start );
	    tk.setStartPosition( startLine, startColumn );
	    tk.setEndPosition( m_currentLine, m_currentColumn );
	}
    } else if( ch == '/' && ch1 == '*' ){
	int start = currentPosition();
	nextChar( 2 );
	readMultiLineComment();

	if( recordComments() ){
	    tk = CREATE_TOKEN( Token_comment, start, currentPosition() - start );
	    tk.setStartPosition( startLine, startColumn );
	    tk.setEndPosition( m_currentLine, m_currentColumn );
	}
    } else if( ch == '\'' || (ch == 'L' && ch1 == '\'') ){
	int start = currentPosition();
	readCharLiteral();
	tk = CREATE_TOKEN( Token_char_literal, start, currentPosition() - start );
	tk.setStartPosition( startLine, startColumn );
	tk.setEndPosition( m_currentLine, m_currentColumn );
    } else if( ch == '"' ){
	int start = currentPosition();
	readStringLiteral();
	tk = CREATE_TOKEN( Token_string_literal, start, currentPosition() - start );
	tk.setStartPosition( startLine, startColumn );
	tk.setEndPosition( m_currentLine, m_currentColumn );
    } else if( ch.isLetter() || ch == '_' ){
	int start = currentPosition();
	readIdentifier();
	HashedString ide = m_source.mid( start, currentPosition() - start );
	int k = Lookup::find( ide );
    if( k == -1 && m_preprocessorEnabled ) m_driver->usingString( ide );
            
	if( m_preprocessorEnabled && m_driver->hasMacro(ide) &&
	    (k == -1 || !m_driver->macro(ide).body().isEmpty()) ){


            bool preproc = m_preprocessorEnabled;
            m_preprocessorEnabled = false;

            d->beginScope();

	    int svLine = currentLine();
	    int svColumn = currentColumn();

       Macro m = m_driver->macro( ide );
       m_driver->usingMacro( m );

       QString ellipsisArg;

	    if( m.hasArguments() ){
                int endIde = currentPosition();

		readWhiteSpaces();
		if( currentChar() == '(' ){
		    nextChar();
		    int argIdx = 0;
		    int argCount = m.argumentList().size();
		    while( currentChar() && argIdx<argCount ){
			readWhiteSpaces();

                        QString argName = m.argumentList()[ argIdx ];

                        bool ellipsis = argName == "...";

			QString arg = readArgument();

                        if( !ellipsis )
                            d->bind( argName, arg );
                        else
                            ellipsisArg += arg;

			if( currentChar() == ',' ){
			    nextChar();
                            if( !ellipsis ){
                                ++argIdx;
                            } else {
                                ellipsisArg += ", ";
                            }
			} else if( currentChar() == ')' ){
			    break;
			}
		    }
                    if( currentChar() == ')' ){
                        // valid macro
                        nextChar();
                    }
		} else {
		    tk = CREATE_TOKEN( Token_identifier, start, endIde - start );
		    tk.setStartPosition( svLine, svColumn );
		    tk.setEndPosition( svLine, svColumn + (endIde - start) );

                    m_startLine = false;

                    d->endScope();        // OPS!!
                    m_preprocessorEnabled = preproc;
                    return;
                }
	    }

	    int argsEndAtLine = currentLine();
	    int argsEndAtColumn = currentColumn();

#if defined( KDEVELOP_BGPARSER )
	    qthread_yield();
#endif
            insertCurrent( m.body() );
            
            // tokenize the macro body

            QString textToInsert;

            setEndPtr( offset( currentPosition() + m.body().length() ) );
            
            while( currentChar() ){

                readWhiteSpaces();

                Token tok(m_source);
                nextToken( tok );

                bool stringify = !m_inPreproc && tok == '#';
                bool merge = !m_inPreproc && tok == Token_concat;

                if( stringify || merge )
                    nextToken( tok );

                if( tok == Token_eof )
                     break;

                QString tokText = tok.text();
                HashedString str = (tok == Token_identifier && d->hasBind(tokText)) ? d->apply( tokText ) : tokText;
                if( str == ide ){
			//Problem p( i18n("unsafe use of macro '%1', macro is ignored").arg(ide.str()), m_currentLine, m_currentColumn, Problem::Level_Warning );
                    //m_driver->addProblem( m_driver->currentFileName(), p );
                    m_driver->removeMacro( ide );
                    // str = QString::null;
                }

                if( stringify ) {
                    textToInsert.append( QString::fromLatin1("\"") + str.str() + QString::fromLatin1("\" ") );
                } else if( merge ){
                    textToInsert.truncate( textToInsert.length() - 1 );
                    textToInsert.append( str.str()  + QString::fromLatin1(" ") );
                } else if( tok == Token_ellipsis && d->hasBind("...") ){
                    textToInsert.append( ellipsisArg );
                } else {
                    textToInsert.append( str.str() + QString::fromLatin1(" ") );
                }
            }
        
#if defined( KDEVELOP_BGPARSER )
	    qthread_yield();
#endif
        insertCurrent( textToInsert ); //also corrects the end-pointer

            d->endScope();
            m_preprocessorEnabled = preproc;
	    //m_driver->addMacro( m );
	    m_currentLine = argsEndAtLine;
	    m_currentColumn = argsEndAtColumn;
	} else if( k != -1 ){
	    tk = CREATE_TOKEN( k, start, currentPosition() - start );
	    tk.setStartPosition( startLine, startColumn );
	    tk.setEndPosition( m_currentLine, m_currentColumn );
	} else if( m_skipWordsEnabled ){
	    __gnu_cxx::hash_map< HashedString, QPair<SkipType, QString> >::iterator pos = m_words.find( ide );
	    if( pos != m_words.end() ){
		if( (*pos).second.first == SkipWordAndArguments ){
		    readWhiteSpaces();
		    if( currentChar() == '(' )
			skip( '(', ')' );
		}
		if( !(*pos).second.second.isEmpty() ){
#if defined( KDEVELOP_BGPARSER )
	    qthread_yield();
#endif
                    insertCurrent( QString(" ") + (*pos).second.second + QString(" ") );
		}
	    } else if( /*qt_rx.exactMatch(ide) ||*/
		ide.str().endsWith("EXPORT") ||
		(ide.str().startsWith("Q_EXPORT") && ide.str() != "Q_EXPORT_INTERFACE") ||
		ide.str().startsWith("QM_EXPORT") ||
		ide.str().startsWith("QM_TEMPLATE")){

		readWhiteSpaces();
		if( currentChar() == '(' )
		    skip( '(', ')' );
	    } else if( ide.str().startsWith("K_TYPELIST_") || ide.str().startsWith("TYPELIST_") ){
		tk = CREATE_TOKEN( Token_identifier, start, currentPosition() - start );
		tk.setStartPosition( startLine, startColumn );
		tk.setEndPosition( m_currentLine, m_currentColumn );
		readWhiteSpaces();
		if( currentChar() == '(' )
		    skip( '(', ')' );
	    } else{
		tk = CREATE_TOKEN( Token_identifier, start, currentPosition() - start );
		tk.setStartPosition( startLine, startColumn );
		tk.setEndPosition( m_currentLine, m_currentColumn );
	    }
	} else {
	    tk = CREATE_TOKEN( Token_identifier, start, currentPosition() - start );
	    tk.setStartPosition( startLine, startColumn );
	    tk.setEndPosition( m_currentLine, m_currentColumn );
	}
    } else if( ch.isNumber() ){
	int start = currentPosition();
	readNumberLiteral();
	tk = CREATE_TOKEN( Token_number_literal, start, currentPosition() - start );
	tk.setStartPosition( startLine, startColumn );
	tk.setEndPosition( m_currentLine, m_currentColumn );
    } else if( -1 != (op = findOperator3()) ){
	tk = CREATE_TOKEN( op, currentPosition(), 3 );
	nextChar( 3 );
	tk.setStartPosition( startLine, startColumn );
	tk.setEndPosition( m_currentLine, m_currentColumn );
    } else if( -1 != (op = findOperator2()) ){
	tk = CREATE_TOKEN( op, currentPosition(), 2 );
	nextChar( 2 );
	tk.setStartPosition( startLine, startColumn );
	tk.setEndPosition( m_currentLine, m_currentColumn );
    } else {
	tk = CREATE_TOKEN( ch, currentPosition(), 1 );
	nextChar();
	tk.setStartPosition( startLine, startColumn );
	tk.setEndPosition( m_currentLine, m_currentColumn );
    }

    m_startLine = false;
}