本文整理汇总了C++中Parentheses类的典型用法代码示例。如果您正苦于以下问题:C++ Parentheses类的具体用法?C++ Parentheses怎么用?C++ Parentheses使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parentheses类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition)
{
QTextBlock block = cursor->block();
int position = cursor->position();
int ignore = 0;
while (block.isValid()) {
Parentheses parenList = BaseTextDocumentLayout::parentheses(block);
if (!parenList.isEmpty() && !BaseTextDocumentLayout::ifdefedOut(block)) {
for (int i = parenList.count()-1; i >= 0; --i) {
Parenthesis paren = parenList.at(i);
if (paren.chr != QLatin1Char('{') && paren.chr != QLatin1Char('}')
&& paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-')
&& paren.chr != QLatin1Char('[') && paren.chr != QLatin1Char(']'))
continue;
if (block == cursor->block()) {
if (position - block.position() <= paren.pos + (paren.type == Parenthesis::Closed ? 1 : 0))
continue;
if (checkStartPosition && paren.type == Parenthesis::Opened && paren.pos== cursor->position()) {
return true;
}
}
if (paren.type == Parenthesis::Closed) {
++ignore;
} else if (ignore > 0) {
--ignore;
} else {
cursor->setPosition(block.position() + paren.pos);
return true;
}
}
}
block = block.previous();
}
return false;
}
示例2: collapseAtPos
int Parenthesis::collapseAtPos(const Parentheses &parentheses, QChar *character)
{
int result = -1;
QChar c;
int depth = 0;
for (int i = 0; i < parentheses.size(); ++i) {
const Parenthesis &p = parentheses.at(i);
if (p.chr == QLatin1Char('{')
|| p.chr == QLatin1Char('+')
|| p.chr == QLatin1Char('[')) {
if (depth == 0) {
result = p.pos;
c = p.chr;
}
++depth;
} else if (p.chr == QLatin1Char('}')
|| p.chr == QLatin1Char('-')
|| p.chr == QLatin1Char(']')) {
if (--depth < 0)
depth = 0;
result = -1;
}
}
if (result >= 0 && character)
*character = c;
return result;
}
示例3: setupDataForBlock
void Highlighter::highlightBlock(const QString &text)
{
if (!m_defaultContext.isNull() && !m_isBroken) {
try {
setupDataForBlock(text);
handleContextChange(m_currentContext->lineBeginContext(),
m_currentContext->definition());
ProgressData *progress = new ProgressData;
const int length = text.length();
while (progress->offset() < length)
iterateThroughRules(text, length, progress, false, m_currentContext->rules());
if (extractObservableState(currentBlockState()) != WillContinue) {
handleContextChange(m_currentContext->lineEndContext(),
m_currentContext->definition(),
false);
}
if (length == 0) {
handleContextChange(m_currentContext->lineEmptyContext(),
m_currentContext->definition(),
false);
}
delete progress;
m_contexts.clear();
if (m_indentationBasedFolding) {
applyIndentationBasedFolding(text);
} else {
applyRegionBasedFolding();
// In the case region depth has changed since the last time the state was set.
setCurrentBlockState(computeState(extractObservableState(currentBlockState())));
}
Parentheses parentheses;
for (int pos = 0; pos < length; ++pos) {
const QChar c = text.at(pos);
if (isOpeningParenthesis(c))
parentheses.push_back(Parenthesis(Parenthesis::Opened, c, pos));
else if (isClosingParenthesis(c))
parentheses.push_back(Parenthesis(Parenthesis::Closed, c, pos));
}
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
} catch (const HighlighterException &e) {
Core::MessageManager::write(
QCoreApplication::translate("GenericHighlighter",
"Generic highlighter error: %1")
.arg(e.message()),
Core::MessageManager::WithFocus);
m_isBroken = true;
}
}
formatSpaces(text);
}
示例4: userData
void BaseTextDocumentLayout::setParentheses(const QTextBlock &block, const Parentheses &parentheses)
{
if (parentheses.isEmpty()) {
if (TextBlockUserData *userData = testUserData(block))
userData->clearParentheses();
} else {
userData(block)->setParentheses(parentheses);
}
}
示例5: countBrackets
static void countBrackets(QTextCursor cursor, int from, int end, QChar open, QChar close,
int *errors, int *stillopen)
{
cursor.setPosition(from);
QTextBlock block = cursor.block();
while (block.isValid() && block.position() < end) {
Parentheses parenList = TextDocumentLayout::parentheses(block);
if (!parenList.isEmpty() && !TextDocumentLayout::ifdefedOut(block)) {
for (int i = 0; i < parenList.count(); ++i) {
Parenthesis paren = parenList.at(i);
int position = block.position() + paren.pos;
if (position < from || position >= end)
continue;
countBracket(open, close, paren.chr, errors, stillopen);
}
}
block = block.next();
}
}
示例6: matchCursorForward
TextBlockUserData::MatchType TextBlockUserData::matchCursorForward(QTextCursor *cursor)
{
cursor->clearSelection();
const QTextBlock block = cursor->block();
if (!BaseTextDocumentLayout::hasParentheses(block) || BaseTextDocumentLayout::ifdefedOut(block))
return NoMatch;
const int relPos = cursor->position() - block.position();
Parentheses parentheses = BaseTextDocumentLayout::parentheses(block);
const Parentheses::const_iterator cend = parentheses.constEnd();
for (Parentheses::const_iterator it = parentheses.constBegin(); it != cend; ++it) {
const Parenthesis &paren = *it;
if (paren.pos == relPos
&& paren.type == Parenthesis::Opened) {
return checkOpenParenthesis(cursor, paren.chr);
}
}
return NoMatch;
}
示例7: closeCollapseAtPos
int Parenthesis::closeCollapseAtPos(const Parentheses &parentheses, QChar *character)
{
int depth = 0;
for (int i = 0; i < parentheses.size(); ++i) {
const Parenthesis &p = parentheses.at(i);
if (p.chr == QLatin1Char('{')
|| p.chr == QLatin1Char('+')
|| p.chr == QLatin1Char('[')) {
++depth;
} else if (p.chr == QLatin1Char('}')
|| p.chr == QLatin1Char('-')
|| p.chr == QLatin1Char(']')) {
if (--depth < 0) {
if (character)
*character = p.chr;
return p.pos;
}
}
}
return -1;
}
示例8: checkOpenParenthesis
TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor *cursor, QChar c)
{
QTextBlock block = cursor->block();
if (!BaseTextDocumentLayout::hasParentheses(block) || BaseTextDocumentLayout::ifdefedOut(block))
return NoMatch;
Parentheses parenList = BaseTextDocumentLayout::parentheses(block);
Parenthesis openParen, closedParen;
QTextBlock closedParenParag = block;
const int cursorPos = cursor->position() - closedParenParag.position();
int i = 0;
int ignore = 0;
bool foundOpen = false;
for (;;) {
if (!foundOpen) {
if (i >= parenList.count())
return NoMatch;
openParen = parenList.at(i);
if (openParen.pos != cursorPos) {
++i;
continue;
} else {
foundOpen = true;
++i;
}
}
if (i >= parenList.count()) {
for (;;) {
closedParenParag = closedParenParag.next();
if (!closedParenParag.isValid())
return NoMatch;
if (BaseTextDocumentLayout::hasParentheses(closedParenParag)
&& !BaseTextDocumentLayout::ifdefedOut(closedParenParag)) {
parenList = BaseTextDocumentLayout::parentheses(closedParenParag);
break;
}
}
i = 0;
}
closedParen = parenList.at(i);
if (closedParen.type == Parenthesis::Opened) {
ignore++;
++i;
continue;
} else {
if (ignore > 0) {
ignore--;
++i;
continue;
}
cursor->clearSelection();
cursor->setPosition(closedParenParag.position() + closedParen.pos + 1, QTextCursor::KeepAnchor);
if ((c == QLatin1Char('{') && closedParen.chr != QLatin1Char('}'))
|| (c == QLatin1Char('(') && closedParen.chr != QLatin1Char(')'))
|| (c == QLatin1Char('[') && closedParen.chr != QLatin1Char(']'))
|| (c == QLatin1Char('+') && closedParen.chr != QLatin1Char('-'))
)
return Mismatch;
return Match;
}
}
}
示例9: checkClosedParenthesis
TextBlockUserData::MatchType TextBlockUserData::checkClosedParenthesis(QTextCursor *cursor, QChar c)
{
QTextBlock block = cursor->block();
if (!BaseTextDocumentLayout::hasParentheses(block) || BaseTextDocumentLayout::ifdefedOut(block))
return NoMatch;
Parentheses parenList = BaseTextDocumentLayout::parentheses(block);
Parenthesis openParen, closedParen;
QTextBlock openParenParag = block;
const int cursorPos = cursor->position() - openParenParag.position();
int i = parenList.count() - 1;
int ignore = 0;
bool foundClosed = false;
for (;;) {
if (!foundClosed) {
if (i < 0)
return NoMatch;
closedParen = parenList.at(i);
if (closedParen.pos != cursorPos - 1) {
--i;
continue;
} else {
foundClosed = true;
--i;
}
}
if (i < 0) {
for (;;) {
openParenParag = openParenParag.previous();
if (!openParenParag.isValid())
return NoMatch;
if (BaseTextDocumentLayout::hasParentheses(openParenParag)
&& !BaseTextDocumentLayout::ifdefedOut(openParenParag)) {
parenList = BaseTextDocumentLayout::parentheses(openParenParag);
break;
}
}
i = parenList.count() - 1;
}
openParen = parenList.at(i);
if (openParen.type == Parenthesis::Closed) {
ignore++;
--i;
continue;
} else {
if (ignore > 0) {
ignore--;
--i;
continue;
}
cursor->clearSelection();
cursor->setPosition(openParenParag.position() + openParen.pos, QTextCursor::KeepAnchor);
if ((c == '}' && openParen.chr != '{') ||
(c == ')' && openParen.chr != '(') ||
(c == ']' && openParen.chr != '[') ||
(c == '-' && openParen.chr != '+'))
return Mismatch;
return Match;
}
}
}