本文整理汇总了C++中QStringRef::string方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::string方法的具体用法?C++ QStringRef::string怎么用?C++ QStringRef::string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nextToken
QStringRef ChessEngine::nextToken(const QStringRef& previous, bool untilEnd)
{
const QString* str = previous.string();
if (str == 0)
return QStringRef();
int i;
int start = -1;
int firstPos = previous.position() + previous.size();
for (i = firstPos; i < str->size(); i++)
{
if (str->at(i).isSpace())
{
if (start == -1)
continue;
break;
}
else if (start == -1)
{
start = i;
if (untilEnd)
{
int end = str->size();
while (str->at(--end).isSpace())
;
i = end + 1;
break;
}
}
}
if (start == -1)
return QStringRef();
return QStringRef(str, start, i - start);
}
示例2: parse
/*!
\internal
Parses \a pattern.
Allowed is f.ex.:
qt.core.io.debug FullText, QtDebugMsg
qt.core.* LeftFilter, all types
*.io.warning RightFilter, QtWarningMsg
*.core.* MidFilter
*/
void QLoggingRule::parse(const QStringRef &pattern)
{
QStringRef p;
// strip trailing ".messagetype"
if (pattern.endsWith(QLatin1String(".debug"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 6); // strlen(".debug")
messageType = QtDebugMsg;
} else if (pattern.endsWith(QLatin1String(".info"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 5); // strlen(".info")
messageType = QtInfoMsg;
} else if (pattern.endsWith(QLatin1String(".warning"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 8); // strlen(".warning")
messageType = QtWarningMsg;
} else if (pattern.endsWith(QLatin1String(".critical"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 9); // strlen(".critical")
messageType = QtCriticalMsg;
} else {
p = pattern;
}
if (!p.contains(QLatin1Char('*'))) {
flags = FullText;
} else {
if (p.endsWith(QLatin1Char('*'))) {
flags |= LeftFilter;
p = QStringRef(p.string(), p.position(), p.length() - 1);
}
if (p.startsWith(QLatin1Char('*'))) {
flags |= RightFilter;
p = QStringRef(p.string(), p.position() + 1, p.length() - 1);
}
if (p.contains(QLatin1Char('*'))) // '*' only supported at start/end
flags = 0;
}
category = p.toString();
}
示例3: tokenize
UrlParser::UrlTokenList UrlParser::tokenize(const QString &text, Flags flags)
{
UrlTokenList result;
static QRegExp linkRegExp("([a-zA-Z0-9\\-\\_\\.][email protected]([a-zA-Z0-9\\-\\_]+\\.)+[a-zA-Z]+)|"
"([a-z]+(\\+[a-z]+)?://|www\\.)"
"[\\w-]+(\\.[\\w-]+)*\\.\\w+"
"(:\\d+)?"
"(/[\\w\\+\\.\\[\\]!%\\$/\\(\\),:;@'&=~-]*"
"(\\?[\\w\\+\\.\\[\\]!%\\$/\\(\\),:;@\\'&=~-]*)?"
"(#[\\w\\+\\.\\[\\]!%\\$/\\\\\\(\\)\\|,:;@&=~-]*)?)?",
Qt::CaseInsensitive);
Q_ASSERT(linkRegExp.isValid());
QList<QPair<int, int> > tags;
int currentTag = 0;
if (flags & Html) {
enum TagParserState {
AtText,
AtTag,
AtSingleQuote,
AtDoubleQuote
};
TagParserState state = AtText;
int start = 0;
for (int i = 0; i < text.size(); ++i) {
QChar ch = text.at(i);
switch (state) {
case AtText:
if (ch == QLatin1Char('<')) {
state = AtTag;
start = i;
}
break;
case AtTag:
if (ch == QLatin1Char('>')) {
tags << qMakePair(start, i);
state = AtText;
} else if (ch == QLatin1Char('\'')) {
state = AtSingleQuote;
} else if (ch == QLatin1Char('\"')) {
state = AtDoubleQuote;
}
break;
case AtSingleQuote:
if (ch == QLatin1Char('\''))
state = AtTag;
break;
case AtDoubleQuote:
if (ch == QLatin1Char('\"'))
state = AtTag;
break;
}
}
}
int pos = 0;
int lastPos = 0;
while (((pos = linkRegExp.indexIn(text, pos)) != -1)) {
QString link = linkRegExp.cap(0);
while (currentTag < tags.size() && tags.at(currentTag).second < pos)
currentTag++;
if (currentTag < tags.size()) {
const QPair<int, int> &pair = tags.at(currentTag);
int left = qBound(pair.first, pos, pair.second);
int right = qBound(pair.first, pos + link.size(), pair.second);
if (left != right) {
pos += link.size();
continue;
}
}
UrlToken tok = { text.midRef(lastPos, pos - lastPos), QString() };
if (!tok.text.isEmpty()) {
if (!result.isEmpty() && result.last().url.isEmpty()) {
QStringRef tmp = result.last().text;
result.last().text = QStringRef(tmp.string(), tmp.position(), tmp.size() + tok.text.size());
} else {
result << tok;
}
}
tok.text = text.midRef(pos, link.size());
pos += link.size();
if (link.startsWith(QLatin1String("www."), Qt::CaseInsensitive))
link.prepend(QLatin1String("http://"));
else if(!link.contains(QLatin1String("//")))
link.prepend(QLatin1String("mailto:"));
tok.url = link;
result << tok;
lastPos = pos;
}
if (!result.isEmpty() && result.last().url.isEmpty()) {
result.last().text = text.midRef(result.last().text.position());
} else {
UrlToken tok = { text.midRef(lastPos), QString() };
result << tok;
}
return result;
}
示例4: toBool
bool toBool(const QStringRef stringref)
{
return (stringref == "true" || stringref.string()->toInt() == 1);
}
示例5:
String::String(const QStringRef& ref)
{
if (!ref.string())
return;
m_impl = StringImpl::create(reinterpret_cast_ptr<const UChar*>(ref.unicode()), ref.length());
}
示例6:
ProString::ProString(const QStringRef &str) :
m_string(*str.string()), m_offset(str.position()), m_length(str.size()), m_file(0), m_hash(0x80000000)
{
}