本文整理汇总了C++中QStringRef::length方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::length方法的具体用法?C++ QStringRef::length怎么用?C++ QStringRef::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compress
QString CompressedWhitespace::compress(const QStringRef &input)
{
Q_ASSERT(!isEven(1) && isEven(0) && isEven(2));
Q_ASSERT(!input.isEmpty());
QString result;
const int len = input.length();
/* The amount of compressed characters. For instance, if input is
* four spaces followed by one tab, compressedChars will be 2, and the resulting
* QString will have a length of 1, two compressedChars stored in one QChar. */
int compressedChars = 0;
for(int i = 0; i < len; ++i)
{
const QChar c(input.at(i));
int start = i;
while(true)
{
if(i + 1 == input.length() || input.at(i + 1) != c)
break;
else
++i;
}
/* The length of subsequent whitespace characters in the input. */
int wsLen = (i - start) + 1;
/* We might get a sequence of whitespace that is so long, that we can't
* store it in one unit/byte. In that case we chop it into as many subsequent
* ones that is needed. */
while(true)
{
const int unitLength = qMin(wsLen, int(MaxCharCount));
wsLen -= unitLength;
ushort resultCP = toCompressedChar(c, unitLength);
if(isEven(compressedChars))
result += QChar(resultCP);
else
{
resultCP = resultCP << 8;
resultCP |= result.at(result.size() - 1).unicode();
result[result.size() - 1] = resultCP;
}
++compressedChars;
if(wsLen == 0)
break;
}
}
return result;
}
示例2: isCompleteCharLiteral
static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index)
{
const QStringRef text = tk.textRef(index);
if (text.length() < 2)
return false;
else if (text.at(text.length() - 1) == QLatin1Char('\''))
return text.at(text.length() - 2) != QLatin1Char('\\'); // ### not exactly.
return false;
}
示例3: Cell
KeyFace::KeyFace(VAC * vac, XmlStreamReader & xml) :
Cell(vac, xml),
KeyCell(vac, xml),
FaceCell(vac, xml)
{
// Cycles
QString str;
QStringRef d = xml.attributes().value("cycles");
bool opened = false;
for(int i=0; i<d.length(); ++i)
{
QChar c = d.at(i);
if(c == '[')
opened = true;
if(opened)
str += c;
if(c==']')
{
cycles_ << Cycle();
cycles_.last().fromString(str);
opened = false;
str.clear();
}
}
}
示例4: parseInt
QT_BEGIN_NAMESPACE
static int parseInt(const QStringRef &str, bool *ok)
{
int pos = 0;
int number = 0;
while (pos < str.length() && str.at(pos).isDigit()) {
if (pos != 0)
number *= 10;
number += str.at(pos).unicode() - '0';
++pos;
}
if (pos != str.length())
*ok = false;
else
*ok = true;
return number;
}
示例5: processComment
void FindTrCalls::processComment(const AST::SourceLocation &loc)
{
if (!loc.length)
return;
const QStringRef commentStr = engine->midRef(loc.begin(), loc.length);
const QChar *chars = commentStr.constData();
const int length = commentStr.length();
// Try to match the logic of the C++ parser.
if (*chars == QLatin1Char(':') && chars[1].isSpace()) {
if (!extracomment.isEmpty())
extracomment += QLatin1Char(' ');
extracomment += QString(chars+2, length-2);
} else if (*chars == QLatin1Char('=') && chars[1].isSpace()) {
msgid = QString(chars+2, length-2).simplified();
} else if (*chars == QLatin1Char('~') && chars[1].isSpace()) {
QString text = QString(chars+2, length-2).trimmed();
int k = text.indexOf(QLatin1Char(' '));
if (k > -1)
extra.insert(text.left(k), text.mid(k + 1).trimmed());
} else if (*chars == QLatin1Char('%') && chars[1].isSpace()) {
sourcetext.reserve(sourcetext.length() + length-2);
ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length();
int p = 2, c;
forever {
if (p >= length)
break;
c = chars[p++].unicode();
if (std::isspace(c))
continue;
if (c != '"') {
yyMsg(loc.startLine) << qPrintable(LU::tr("Unexpected character in meta string\n"));
break;
}
forever {
if (p >= length) {
whoops:
yyMsg(loc.startLine) << qPrintable(LU::tr("Unterminated meta string\n"));
break;
}
c = chars[p++].unicode();
if (c == '"')
break;
if (c == '\\') {
if (p >= length)
goto whoops;
c = chars[p++].unicode();
if (c == '\r' || c == '\n')
goto whoops;
*ptr++ = '\\';
}
*ptr++ = c;
}
}
sourcetext.resize(ptr - (ushort *)sourcetext.data());
} else {
示例6: stripParameterUrl
QString stripParameterUrl(const QString &url, const QString &scheme)
{
QStringRef ref = url.midRef(scheme.length() + 1);
if (ref.startsWith(QLatin1String("//")))
ref = ref.mid(2);
if (ref.endsWith(QLatin1Char('/')))
ref = ref.left(ref.length() - 1);
return ref.toString();
}
示例7: isPPKeyword
bool GlslHighlighter::isPPKeyword(const QStringRef &text) const
{
switch (text.length())
{
case 2:
if (text.at(0) == QLatin1Char('i') && text.at(1) == QLatin1Char('f'))
return true;
break;
case 4:
if (text.at(0) == QLatin1Char('e') && text == QLatin1String("elif"))
return true;
else if (text.at(0) == QLatin1Char('e') && text == QLatin1String("else"))
return true;
break;
case 5:
if (text.at(0) == QLatin1Char('i') && text == QLatin1String("ifdef"))
return true;
else if (text.at(0) == QLatin1Char('u') && text == QLatin1String("undef"))
return true;
else if (text.at(0) == QLatin1Char('e') && text == QLatin1String("endif"))
return true;
else if (text.at(0) == QLatin1Char('e') && text == QLatin1String("error"))
return true;
break;
case 6:
if (text.at(0) == QLatin1Char('i') && text == QLatin1String("ifndef"))
return true;
if (text.at(0) == QLatin1Char('i') && text == QLatin1String("import"))
return true;
else if (text.at(0) == QLatin1Char('d') && text == QLatin1String("define"))
return true;
else if (text.at(0) == QLatin1Char('p') && text == QLatin1String("pragma"))
return true;
break;
case 7:
if (text.at(0) == QLatin1Char('i') && text == QLatin1String("include"))
return true;
else if (text.at(0) == QLatin1Char('w') && text == QLatin1String("warning"))
return true;
break;
case 12:
if (text.at(0) == QLatin1Char('i') && text == QLatin1String("include_next"))
return true;
break;
default:
break;
}
return false;
}
示例8: valueAsDouble
double ScXmlStreamAttributes::valueAsDouble (const QString& attrName, double def) const
{
double retValue = def;
QStringRef att = value(attrName);
if (!att.isEmpty())
{
QString strVal = QString::fromRawData(att.constData(), att.length());
retValue = ScCLocale::toDoubleC(strVal, def);
}
return retValue;
}
示例9: eventFilter
bool Highlighter::eventFilter(QObject* watched, QEvent* event)
{
if (watched != m_text->viewport() || event->type() != QEvent::ContextMenu || !m_enabled) {
return QSyntaxHighlighter::eventFilter(watched, event);
} else {
// Check spelling of text block under mouse
QContextMenuEvent* context_event = static_cast<QContextMenuEvent*>(event);
m_start_cursor = m_text->cursorForPosition(context_event->pos());
QTextBlock block = m_start_cursor.block();
int cursor = m_start_cursor.position() - block.position();
bool under_mouse = false;
QStringRef word;
QVector<QStringRef> words = static_cast<BlockStats*>(block.userData())->misspelled();
for (int i = 0; i < words.count(); ++i) {
word = words.at(i);
int delta = cursor - word.position();
if (delta >= 0 && delta <= word.length()) {
under_mouse = true;
break;
}
}
if (!under_mouse) {
return false;
} else {
// Select misspelled word
m_cursor = m_start_cursor;
m_cursor.setPosition(word.position() + block.position());
m_cursor.setPosition(m_cursor.position() + word.length(), QTextCursor::KeepAnchor);
m_word = m_cursor.selectedText();
m_text->setTextCursor(m_cursor);
// List suggestions in context menu
QMenu* menu = new QMenu;
QStringList guesses = m_dictionary->suggestions(m_word);
if (!guesses.isEmpty()) {
foreach (const QString& guess, guesses) {
menu->addAction(guess);
}
} else {
示例10: valueAsUInt
uint ScXmlStreamAttributes::valueAsUInt (const QString& attrName, uint def) const
{
uint retValue = def;
QStringRef att = value(attrName);
if (!att.isEmpty())
{
bool success = false;
QString strVal = QString::fromRawData(att.constData(), att.length());
uint intVal = strVal.toUInt(&success);
if (success)
retValue = intVal;
}
return retValue;
}
示例11: valueAsInt
int ScXmlStreamAttributes::valueAsInt (const char* attrName, int def) const
{
int retValue = def;
QStringRef att = value(QLatin1String(attrName));
if (!att.isEmpty())
{
bool success = false;
QString strVal = QString::fromRawData(att.constData(), att.length());
int intVal = strVal.toInt(&success);
if (success)
retValue = intVal;
}
return retValue;
}
示例12: valueAsBool
bool ScXmlStreamAttributes::valueAsBool (const QString& attrName, bool def) const
{
bool retValue = def;
QStringRef att = value(attrName);
if (!att.isEmpty())
{
bool success = false;
QString strVal = QString::fromRawData(att.constData(), att.length());
int intVal = strVal.toInt(&success);
if (success)
retValue = static_cast<bool>(intVal);
}
return retValue;
}
示例13: read
void XmlElementReader::read(MapCoordVector& coords)
{
namespace literal = XmlStreamLiteral;
coords.clear();
const auto num_coords = attribute<unsigned int>(literal::count);
coords.reserve(std::min(num_coords, 500000u));
try
{
for( xml.readNext(); xml.tokenType() != QXmlStreamReader::EndElement; xml.readNext() )
{
const QXmlStreamReader::TokenType token = xml.tokenType();
if (xml.error() || token == QXmlStreamReader::EndDocument)
{
throw FileFormatException(ImportExport::tr("Could not parse the coordinates."));
}
else if (token == QXmlStreamReader::Characters && !xml.isWhitespace())
{
QStringRef text = xml.text();
QString data = QString::fromRawData(text.constData(), text.length());
QTextStream stream(&data, QIODevice::ReadOnly);
stream.setIntegerBase(10);
while (!stream.atEnd())
{
coords.emplace_back();
stream >> coords.back();
}
if (stream.status() == QTextStream::ReadCorruptData)
{
throw FileFormatException(ImportExport::tr("Could not parse the coordinates."));
}
}
else if (token == QXmlStreamReader::StartElement)
{
if (xml.name() == literal::coord)
{
coords.emplace_back(MapCoord::load(xml));
}
else
{
xml.skipCurrentElement();
}
}
// otherwise: ignore element
}
示例14: while
glm::vec3 XMLReader::ToVec3(const QStringRef &s)
{
glm::vec3 result;
int start_idx;
int end_idx = -1;
for(int i = 0; i < 3; i++){
start_idx = ++end_idx;
while(end_idx < s.length() && s.at(end_idx) != QChar(' '))
{
end_idx++;
}
result[i] = s.mid(start_idx, end_idx - start_idx).toFloat();
}
return result;
}
示例15: if
static Action::SpriteDirection directionByName(const QStringRef &name)
{
if (name.length() == 0 || name == "default")
return Action::DIRECTION_DEFAULT;
else if (name == "up")
return Action::DIRECTION_UP;
else if (name == "down")
return Action::DIRECTION_DOWN;
else if (name == "left")
return Action::DIRECTION_LEFT;
else if (name == "right")
return Action::DIRECTION_RIGHT;
else
return Action::DIRECTION_INVALID;
}