本文整理汇总了C++中Tokens::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ Tokens::isEmpty方法的具体用法?C++ Tokens::isEmpty怎么用?C++ Tokens::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokens
的用法示例。
在下文中一共展示了Tokens::isEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isInStringHelper
static bool isInStringHelper(const QTextCursor &cursor, Token *retToken = 0)
{
LanguageFeatures features;
features.qtEnabled = false;
features.qtKeywordsEnabled = false;
features.qtMocRunEnabled = false;
features.cxx11Enabled = true;
features.c99Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const Tokens tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (tokens.isEmpty() || pos <= tokens.first().utf16charsBegin())
return false;
if (pos >= tokens.last().utf16charsEnd()) {
const Token tk = tokens.last();
return tk.isStringLiteral() && prevState > 0;
}
Token tk = tokenAtPosition(tokens, pos);
if (retToken)
*retToken = tk;
return tk.isStringLiteral() && pos > tk.utf16charsBegin();
}
示例2: triggerAutoComplete
void Editor::triggerAutoComplete()
{
if( !d->autoCompleteEnabled ) return;
// tokenize the expression (don't worry, this is very fast)
// faster now that it uses flex. ;)
int para = 0, curPos = 0;
getCursorPosition( ¶, &curPos );
QString subtext = text().left( curPos );
Tokens tokens = Evaluator::scan( subtext );
if(!tokens.valid())
{
kdWarning() << "invalid tokens.\n";
return;
}
if(tokens.isEmpty() || subtext.endsWith(" "))
return;
Token lastToken = tokens[ tokens.count()-1 ];
// last token must be an identifier
if( !lastToken.isIdentifier() )
return;
QString id = lastToken.text();
if( id.isEmpty() )
return;
// find matches in function names
QStringList fnames = FunctionManager::instance()->functionList(FunctionManager::All);
QStringList choices;
for( unsigned i=0; i<fnames.count(); i++ )
if( fnames[i].startsWith( id, false ) )
{
QString str = fnames[i];
::Function* f = FunctionManager::instance()->function( str );
if( f && !f->description.isEmpty() )
str.append( ':' ).append( f->description );
choices.append( str );
}
choices.sort();
// find matches in variables names
QStringList vchoices;
QStringList values = NumeralModel::instance()->valueNames();
for(QStringList::ConstIterator it = values.begin(); it != values.end(); ++it)
if( (*it).startsWith( id, false ) )
{
QString choice = NumeralModel::description(*it);
if(choice.isEmpty())
choice = NumeralModel::instance()->value(*it).toString();
vchoices.append( QString("%1:%2").arg( *it, choice ) );
}
vchoices.sort();
choices += vchoices;
// no match, don't bother with completion
if( !choices.count() ) return;
// one match, complete it for the user
if( choices.count()==1 )
{
QString str = QStringList::split( ':', choices[0] )[0];
// single perfect match, no need to give choices.
if(str == id.lower())
return;
str = str.remove( 0, id.length() );
int para = 0, curPos = 0;
getCursorPosition( ¶, &curPos );
blockSignals( true );
insert( str );
setSelection( 0, curPos, 0, curPos+str.length() );
blockSignals( false );
return;
}
// present the user with completion choices
d->completion->showCompletion( choices );
}
示例3: kDebug
void CellEditor::Private::updateActiveSubRegion(const Tokens &tokens)
{
// Index of the token, at which the text cursor is positioned.
// For sub-regions it is the start range.
currentToken = 0;
if (tokens.isEmpty()) {
selection->setActiveSubRegion(0, 0); // also set the active element
return;
}
const int cursorPosition = textEdit->textCursor().position() - 1; // without '='
kDebug() << "cursorPosition:" << cursorPosition << "textLength:" << textEdit->toPlainText().length() - 1;
uint rangeCounter = 0; // counts the ranges in the sub-region
uint currentRange = 0; // range index denoting the current range
int regionStart = 0; // range index denoting the sub-region start
uint regionEnd = 0; // range index denoting the sub-region end
enum { Anywhere, InRegion, BeyondCursor } state = Anywhere;
Token token;
Token::Type type;
// Search the current range the text cursor is positioned to.
// Determine the subregion start and end, in which the range is located.
for (int i = 0; i < tokens.count(); ++i) {
token = tokens[i];
type = token.type();
// If not in a subregion, we may already quit the loop here.
if (state == Anywhere) {
// Already beyond the cursor position?
if (token.pos() > cursorPosition) {
state = BeyondCursor;
break; // for loop
}
} else if (state == InRegion) {
// Loop to the end of the subregion.
if (type == Token::Cell || type == Token::Range) {
regionEnd = rangeCounter++;
continue; // keep going until the referenced region ends
}
if (type == Token::Operator) {
if (tokens[i].asOperator() == Token::Semicolon) {
continue; // keep going until the referenced region ends
}
}
state = Anywhere;
continue;
}
// Can the token be replaced by a reference?
switch (type) {
case Token::Cell:
case Token::Range:
if (state == Anywhere) {
currentToken = i;
regionStart = rangeCounter;
state = InRegion;
}
regionEnd = rangeCounter; // length = 1
currentRange = ++rangeCounter; // point behind the last
continue;
case Token::Unknown:
case Token::Boolean:
case Token::Integer:
case Token::Float:
case Token::String:
case Token::Error:
// Set the active sub-region start to the next range but
// with a length of 0, which results in inserting a new range
// to the selection on calling Selection::initialize() or
// Selection::update().
currentToken = i;
regionStart = rangeCounter; // position of the next range
regionEnd = rangeCounter - 1; // length = 0
currentRange = rangeCounter;
continue;
case Token::Operator:
case Token::Identifier:
continue;
}
}
// Cursor not reached? I.e. the cursor is placed at the last token's end.
if (state == Anywhere) {
token = tokens.last();
type = token.type();
// Check the last token.
// It was processed, but maybe a reference can be placed behind it.
// Check, if the token can be replaced by a reference.
switch (type) {
case Token::Operator:
// Possible to place a reference behind the operator?
switch (token.asOperator()) {
case Token::Plus:
case Token::Minus:
case Token::Asterisk:
case Token::Slash:
case Token::Caret:
case Token::LeftPar:
//.........这里部分代码省略.........