本文整理汇总了C++中QByteArray::endsWith方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::endsWith方法的具体用法?C++ QByteArray::endsWith怎么用?C++ QByteArray::endsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::endsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: metaDataChanged
void DownloadItem::metaDataChanged()
{
if (m_reply->hasRawHeader(QByteArray("Content-Disposition"))) {
QByteArray header = m_reply->rawHeader(QByteArray("Content-Disposition"));
int index = header.indexOf("filename=");
if (index >= 0) {
header = header.mid(index+9);
if (header.startsWith("\"") || header.startsWith("'"))
header = header.mid(1);
if (header.endsWith("\"") || header.endsWith("'"))
header.chop(1);
m_fileName = QUrl::fromPercentEncoding(header);
}
// Sometimes "filename=" and "filename*=UTF-8''" is set.
// So, search for this too.
index = header.indexOf("filename*=UTF-8''");
if (index >= 0) {
header = header.mid(index+17);
if (header.startsWith("\"") || header.startsWith("'"))
header = header.mid(1);
if (header.endsWith("\"") || header.endsWith("'"))
header.chop(1);
m_fileName = QUrl::fromPercentEncoding(header);
}
}
QVariant statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (!statusCode.isValid())
return;
int status = statusCode.toInt();
if (status != 200) {
QString reason = m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
qDebug() << reason;
}
}
示例2: loadTextFile
QStringList Helper::loadTextFile(QSharedPointer<QFile> file, bool trim_lines, QChar skip_header_char, bool skip_empty_lines)
{
QStringList output;
while (!file->atEnd())
{
QByteArray line = file->readLine();
//remove newline or trim
if (trim_lines)
{
line = line.trimmed();
}
else
{
while (line.endsWith('\n') || line.endsWith('\r')) line.chop(1);
}
//skip empty lines
if (skip_empty_lines && line.count()==0) continue;
//skip header lines
if (skip_header_char!=QChar::Null && line.count()!=0 && line[0]==skip_header_char.toLatin1()) continue;
output.append(line);
}
return output;
}
示例3: testMailAddressFormat
void ImapMessageTest::testMailAddressFormat()
{
QFETCH( Imap::Message::MailAddress, addr );
QFETCH( QString, pretty );
QFETCH( QByteArray, addrspec );
QFETCH( bool, should2047 );
QCOMPARE( addr.prettyName(Imap::Message::MailAddress::FORMAT_READABLE), pretty );
QCOMPARE( addr.asSMTPMailbox(), addrspec );
QByteArray full = addr.asMailHeader();
QByteArray bracketed;
bracketed.append(" <").append(addrspec).append(">");
QVERIFY( full.endsWith(bracketed) );
full.remove(full.size() - bracketed.size(), bracketed.size());
if (should2047) {
QVERIFY( full.startsWith("=?") );
QVERIFY( full.endsWith("?=") );
QCOMPARE( addr.name, Imap::decodeRFC2047String(full) );
} else {
QVERIFY( !full.contains("=?") );
QVERIFY( !full.contains("?=") );
}
}
示例4: absoluteName
//static
QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
{
if (entry.isAbsolute() && entry.isClean())
return entry;
QByteArray orig = entry.nativeFilePath();
QByteArray result;
if (orig.isEmpty() || !orig.startsWith('/')) {
QFileSystemEntry cur(currentPath());
result = cur.nativeFilePath();
}
if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) {
if (!result.isEmpty() && !result.endsWith('/'))
result.append('/');
result.append(orig);
}
if (result.length() == 1 && result[0] == '/')
return QFileSystemEntry(result, QFileSystemEntry::FromNativePath());
const bool isDir = result.endsWith('/');
/* as long as QDir::cleanPath() operates on a QString we have to convert to a string here.
* ideally we never convert to a string since that loses information. Please fix after
* we get a QByteArray version of QDir::cleanPath()
*/
QFileSystemEntry resultingEntry(result, QFileSystemEntry::FromNativePath());
QString stringVersion = QDir::cleanPath(resultingEntry.filePath());
if (isDir)
stringVersion.append(QLatin1Char('/'));
return QFileSystemEntry(stringVersion);
}
示例5: QByteArray
QList<QByteArray> TSVFileStream::readLine()
{
//handle first content line
if (!next_line_.isNull())
{
if (next_line_=="")
{
next_line_ = QByteArray();
return QList<QByteArray>();
}
QList<QByteArray> parts = next_line_.split(separator_);
if (parts.count()!=columns_)
{
THROW(FileParseException, "Expected " + QString::number(columns_) + " columns, but got " + QString::number(parts.count()) + " columns in line 1 of file " + filename_);
}
next_line_ = QByteArray();
return parts;
}
//handle second to last content line
QByteArray line = file_.readLine();
while (line.endsWith('\n') || line.endsWith('\r')) line.chop(1);
++line_;
if (line=="")
{
return QList<QByteArray>();
}
QList<QByteArray> parts = line.split(separator_);
if (parts.count()!=columns_)
{
THROW(FileParseException, "Expected " + QString::number(columns_) + " columns, but got " + QString::number(parts.count()) + " columns in line " + QString::number(line_) + " of file " + filename_);
}
return parts;
}
示例6: attributeToFloat
qreal MStyleSheetAttribute::attributeToFloat(const QByteArray &attribute, bool *conversionOk)
{
QByteArray value = attribute.trimmed();
if (attribute.endsWith(units[PIXELS_UNIT])) {
// strip "px" from the end
value.truncate(value.length() - 2);
return value.toFloat(conversionOk);
}
if (attribute.endsWith(units[MM_UNIT])) {
// strip "mm" from the end
value.truncate(value.length() - 2);
return MDeviceProfile::instance()->mmToPixelsF(value.toFloat(conversionOk));
}
if (attribute.endsWith(units[PT_UNIT])) {
// strip "pt" from the end
value.truncate(value.length() - 2);
return MDeviceProfile::instance()->ptToPixelsF(value.toFloat(conversionOk));
}
return value.toFloat(conversionOk);
}
示例7: canCompress
/*!
We compress small text and JavaScript files.
*/
bool QCacheItem::canCompress() const
{
bool sizeOk = false;
bool typeOk = false;
foreach (const QNetworkCacheMetaData::RawHeader &header, metaData.rawHeaders()) {
if (header.first.toLower() == "content-length") {
qint64 size = header.second.toLongLong();
if (size > MAX_COMPRESSION_SIZE)
return false;
else
sizeOk = true;
}
if (header.first.toLower() == "content-type") {
QByteArray type = header.second;
if (type.startsWith("text/")
|| (type.startsWith("application/")
&& (type.endsWith("javascript") || type.endsWith("ecmascript"))))
typeOk = true;
else
return false;
}
if (sizeOk && typeOk)
return true;
}
return false;
}
示例8: onMessageReceived
void ProjectorShutterBlock::onMessageReceived() {
QByteArray data = m_tcpSocket->readAll();
if (data.startsWith(QString("PJLINK 0").toUtf8())) {
// -> connection established, no authentication required
m_authenticationToken = "";
m_authenticated = true;
m_passwordIsWrong = false;
sendCommand("%1NAME ?\r");
} else if (data.startsWith(QString("PJLINK 1").toUtf8())) {
// -> connection established, received random number for authentification
if (data.size() < 18) {
qWarning() << "Received invalid response from projector.";
return;
}
QString randomNumber = data.mid(9, 8);
m_authenticationToken = md5(randomNumber + m_password);
m_authenticated = true;
m_passwordIsWrong = false;
sendCommand("%1NAME ?\r");
} else if (data.startsWith(QString("PJLINK ERRA").toUtf8())) {
m_authenticated = false;
m_passwordIsWrong = true;
} else if (data.startsWith(QString("%1NAME=").toUtf8())) {
m_projectorName = QString::fromUtf8(data.mid(7, data.size() - 8));
checkPower();
} else if (data.endsWith(QString("=OK\r").toUtf8())) {
// ignore
} else if (data.endsWith(QString("=ERR1\r").toUtf8())) {
qDebug() << "Projector reports undefined command.";
} else if (data.endsWith(QString("=ERR2\r").toUtf8())) {
qDebug() << "Projector reports out-of-parameter.";
} else if (data.endsWith(QString("=ERR3\r").toUtf8())) {
qWarning() << "Projector unavailable.";
} else if (data.endsWith(QString("=ERR4\r").toUtf8())) {
qWarning() << "Projector reports failure.";
} else if (data.startsWith(QString("%1POWR=").toUtf8())) {
if (data.size() < 9) {
qWarning() << "Projector responded with invalid power status.";
return;
}
m_powerStatus = QString(data.mid(7, 1)).toInt();
} else if (data.startsWith(QString("%1AVMT=").toUtf8())) {
if (data.size() < 10) {
qWarning() << "Projector responded with invalid shutter status.";
return;
}
m_shutterIsOpen = data.mid(7, 2) == QString("30").toUtf8() // audio and video mute OFF
|| data.mid(7, 2) == QString("21").toUtf8(); // audio mute ON video mute OFF
} else {
qDebug() << "Received response from projector:" << QString::fromUtf8(data);
}
}
示例9: sizeofTypeExpression
QByteArray sizeofTypeExpression(const QByteArray &type)
{
if (type.endsWith('*'))
return "sizeof(void*)";
if (type.endsWith('>'))
return "sizeof(" + type + ')';
return "sizeof(" + gdbQuoteTypes(type) + ')';
}
示例10: getALine
char KGrGameIO::getALine (const bool kgr3, QByteArray & line)
{
char c;
line = "";
while (openFile.getChar (&c)) {
line = line.append (c);
if (c == '\n') {
break;
}
}
// kDebug() << "Raw line:" << line;
if (line.size() <= 0) {
// Return a '\0' byte if end-of-file.
return ('\0');
}
if (kgr3) {
// In KGr 3 format, strip off leading and trailing syntax.
if (line.startsWith ("// ")) {
line = line.right (line.size() - 3);
// kDebug() << "Stripped comment is:" << line;
}
else {
if (line.startsWith (" i18n(\"")) {
line = ' ' + line.right (line.size() - 7);
}
else if (line.startsWith (" NOTi18n(\"")) {
line = ' ' + line.right (line.size() - 10);
}
else if (line.startsWith (" \"")) {
line = ' ' + line.right (line.size() - 2);
}
if (line.endsWith ("\");\n")) {
line = line.left (line.size() - 4) + '\n';
}
else if (line.endsWith ("\\n\"\n")) {
line = line.left (line.size() - 4) + '\n';
}
else if (line.endsWith ("\"\n")) {
line = line.left (line.size() - 2);
}
// kDebug() << "Stripped syntax is:" << line;
}
// In Kgr 3 format, return the first byte if not end-of-file.
c = line.at (0);
line = line.right (line.size() - 1);
}
else {
// In KGr 2 format, return a space if not end-of-file.
c = ' ';
if (line.startsWith (".")) { // Line to set an option.
c = line.at (0);
line = line.right (line.size() - 1);
}
}
return (c);
}
示例11: stripPointerType
QByteArray stripPointerType(QByteArray type)
{
if (type.endsWith('*'))
type.chop(1);
if (type.endsWith("* const"))
type.chop(7);
if (type.endsWith(' '))
type.chop(1);
return type;
}
示例12: res
static inline QByteArray paramType(const QByteArray &ptype, bool *out)
{
*out = ptype.endsWith('&') || ptype.endsWith("**");
if (*out) {
QByteArray res(ptype);
res.truncate(res.length() - 1);
return res;
}
return ptype;
}
示例13: parseInitKeyX
QByteArray Cipher::parseInitKeyX(QByteArray key)
{
QCA::Initializer init;
bool isCBC = false;
if (key.endsWith(" CBC")) {
isCBC = true;
key.chop(4);
}
if (key.length() != 181)
return QByteArray();
QCA::SecureArray remoteKey = QByteArray::fromBase64(key.left(180));
QCA::DLGroup group(m_primeNum, QCA::BigInteger(2));
QCA::DHPrivateKey privateKey = QCA::KeyGenerator().createDH(group).toDH();
if (privateKey.isNull())
return QByteArray();
QByteArray publicKey = privateKey.y().toArray().toByteArray();
// remove leading 0
if (publicKey.length() > 135 && publicKey.at(0) == '\0')
publicKey = publicKey.mid(1);
QCA::DHPublicKey remotePub(group, remoteKey);
if (remotePub.isNull())
return QByteArray();
QByteArray sharedKey = privateKey.deriveKey(remotePub).toByteArray();
sharedKey = QCA::Hash("sha256").hash(sharedKey).toByteArray().toBase64();
// remove trailing = because mircryption and fish think it's a swell idea.
while (sharedKey.endsWith('='))
sharedKey.chop(1);
if (isCBC)
sharedKey.prepend("cbc:");
bool success = setKey(sharedKey);
if (!success)
return QByteArray();
return publicKey.toBase64().append('A');
}
示例14: main
int main(int argc, char * argv[])
{
if (argc < 2)
{
printf("Usage at_command <command> ...\n");
return -1;
}
QApplication app(argc, argv);
ModemMap mm;
SerialPort sp(mm.signalChannel().toAscii());
Reporter * reporter = 0;
if (mm.provider() == "ZTE")
{
reporter = new ZTEReport(mm);
}
else
{
reporter = new HuaWeiReport(mm);
}
QByteArray data;
data.append(argv[1]);
if (!data.endsWith('\r'))
{
data.append('\r');
}
reporter->sendCommand(sp, data, 5000);
qDebug("Result:");
qDebug() << data;
return 0;
}
示例15: doOSCommand
void QTerminal::doOSCommand(const QByteArray & cmd) {
int termLength = (cmd.endsWith("\x1b\\") ? 2 : 1);
int firstParam = cmd.left(cmd.indexOf(';')).toInt();
QByteArray textParam = cmd.left(cmd.length() - termLength).mid(cmd.indexOf(';') + 1);
QPalette activePalette = this->palette();
/* TODO: XTerm technically allows a series of ;-separated color specifications,
* with subsequent colors being assigned to subsequent slots.
* The old code didn't try, and this doesn't try yet.
*/
switch (firstParam) {
case 10:
/* Qt displays "green" as #008000. Anyone using it as a text color
* probably has a dark background and wants the traditional X11 #00FF00.
*/
activePalette.setColor(QPalette::Text,
(textParam.toLower() == "green") ? QColor(0x00FF00) : QColor(textParam.constData()));
this->setPalette(activePalette);
break;
case 11:
activePalette.setColor(QPalette::Text, QColor(textParam.constData()));
this->setPalette(activePalette);
break;
default:
qDebug("No Can Do ESC ] %s", cmd.toHex().constData());
break;
}
}