本文整理汇总了C++中QByteArray::chop方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::chop方法的具体用法?C++ QByteArray::chop怎么用?C++ QByteArray::chop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::chop方法的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: 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;
}
示例3: composePreprocessorOutput
QByteArray composePreprocessorOutput(const Symbols &symbols) {
QByteArray output;
int lineNum = 1;
Token last = PP_NOTOKEN;
Token secondlast = last;
int i = 0;
while (hasNext(symbols, i)) {
Symbol sym = next(symbols, i);
switch (sym.token) {
case PP_NEWLINE:
case PP_WHITESPACE:
if (last != PP_WHITESPACE) {
secondlast = last;
last = PP_WHITESPACE;
output += ' ';
}
continue;
case PP_STRING_LITERAL:
if (last == PP_STRING_LITERAL)
output.chop(1);
else if (secondlast == PP_STRING_LITERAL && last == PP_WHITESPACE)
output.chop(2);
else
break;
output += sym.lexem().mid(1);
secondlast = last;
last = PP_STRING_LITERAL;
continue;
case MOC_INCLUDE_BEGIN:
lineNum = 0;
continue;
case MOC_INCLUDE_END:
lineNum = sym.lineNum;
continue;
default:
break;
}
secondlast = last;
last = sym.token;
const int padding = sym.lineNum - lineNum;
if (padding > 0) {
output.resize(output.size() + padding);
memset(output.data() + output.size() - padding, '\n', padding);
lineNum = sym.lineNum;
}
output += sym.lexem();
}
return output;
}
示例4: 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');
}
示例5: parseFinishKeyX
bool Cipher::parseFinishKeyX(QByteArray key)
{
QCA::Initializer init;
if (key.length() != 181)
return false;
QCA::SecureArray remoteKey = QByteArray::fromBase64(key.left(180));
QCA::DLGroup group(m_primeNum, QCA::BigInteger(2));
QCA::DHPublicKey remotePub(group, remoteKey);
if (remotePub.isNull())
return false;
if (m_tempKey.isNull())
return false;
QByteArray sharedKey = m_tempKey.deriveKey(remotePub).toByteArray();
sharedKey = QCA::Hash("sha256").hash(sharedKey).toByteArray().toBase64();
// remove trailng = because mircryption and fish think it's a swell idea.
while (sharedKey.endsWith('='))
sharedKey.chop(1);
bool success = setKey(sharedKey);
return success;
}
示例6: 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;
}
示例7: fp
MozPaster::MozPaster(AnimatedWindow *parent) :
AnimatedWindow(parent),
ui(new Ui::MozPaster),
nam (new QNetworkAccessManager(this))
{
ui->setupUi(this);
ui->plainTextEdit->setFocus();
resize (500, 400);
///
QFile fp (":/resources/data/types");
if (fp.open(QIODevice::ReadOnly | QIODevice::Text))
{
while (! fp.atEnd())
{
QByteArray line = fp.readLine();
line.chop(1);
ui->comboBox->addItem(line);
}
}
connect (nam , SIGNAL(finished(QNetworkReply*)) , SLOT(finished(QNetworkReply*)));
}
示例8: fromHex
QByteArray TransformAbstract::fromHex(QByteArray in)
{
QString invalid;
QString HEXCHAR("abcdefABCDEF0123456789");
for (int i = 0; i < in.size(); i++) {
if (!HEXCHAR.contains(in.at(i))) {
if (!invalid.contains(in.at(i)))
invalid.append(in.at(i));
}
}
if (!invalid.isEmpty()) {
emit error(tr("Invalid character(s) found in the hexadecimal stream: '%1', they will be skipped").arg(invalid),name());
}
in.replace(invalid,"");
if (in.size()%2 != 0) {
in.chop(1);
emit error(tr("Invalid size for a hexadecimal stream, skipping the last byte."),name());
}
return QByteArray::fromHex(in);
}
示例9: _parseOutput
void NtgTransformDomainNameToIp::_parseOutput()
{
_setProgress(50.0, "Parsing output...");
QList<NtgEntity> results;
QByteArray line;
while( ! _process.atEnd())
{
if(_process.canReadLine())
{
line = _process.readLine();
if(line.startsWith("Name:"))
{
if(_process.canReadLine())
{
line = _process.readLine();
line = line.mid(9);line.chop(1);
qDebug() << "IP: " << line;
QHash<QString,QString> values;
values["value"] = line;
NtgEntity e("ip-address", values );
results.append(e);
}
else
{
// incomplete IP line, unget Name line
ungetLine(&_process, line);
break;
}
}
}
}
_addResults(results);
_setProgress(100.0, "Finished");
}
示例10: slotReadyRead
void OwncloudDolphinPluginHelper::slotReadyRead()
{
while (_socket.bytesAvailable()) {
_line += _socket.readLine();
if (!_line.endsWith("\n"))
continue;
QByteArray line;
qSwap(line, _line);
line.chop(1);
if (line.isEmpty())
continue;
if (line.startsWith("REGISTER_PATH:")) {
auto col = line.indexOf(':');
QString file = QString::fromUtf8(line.constData() + col + 1, line.size() - col - 1);
_paths.append(file);
continue;
} else if (line.startsWith("STRING:")) {
auto args = QString::fromUtf8(line).split(QLatin1Char(':'));
if (args.size() >= 3) {
_strings[args[1]] = args.mid(2).join(QLatin1Char(':'));
}
continue;
}
emit commandRecieved(line);
}
}
示例11: testPutSequential
void testPutSequential()
{
#if defined(USE_QNAM) && QT_VERSION <= QT_VERSION_CHECK(5, 5, 0)
QSKIP("This test is broken with Qt < 5.5, the fix is 9286a8e5dd97c5d4d7e0ed07a73d4ce7240fdc1d in qtbase");
#endif
const QString aDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
QVERIFY(QDir::temp().mkpath(aDir));
const QString aFile = aDir + QStringLiteral("/accessmanagertest-data2");
const QString putDataContents = "We love free software! " + QString(24000, 'c');
QProcess process;
process.start(QStringLiteral("echo"), QStringList() << putDataContents);
QFile::remove(aFile);
QNetworkReply *reply = manager()->put(QNetworkRequest(QUrl::fromLocalFile(aFile)), &process);
QSignalSpy spy(reply, SIGNAL(finished()));
QVERIFY(spy.wait());
QVERIFY(QFile::exists(aFile));
QFile f(aFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QByteArray cts = f.readAll();
cts.chop(1); //we remove the eof
QCOMPARE(QString::fromUtf8(cts).size(), putDataContents.size());
QCOMPARE(QString::fromUtf8(cts), putDataContents);
QFile::remove(aFile);
}
示例12: transform
void Binary::transform(const QByteArray &input, QByteArray &output) {
output.clear();
if (input.isEmpty())
return;
QByteArray temp;
if (wayValue == TransformAbstract::INBOUND) {
for (int i = 0; i < input.size(); i++) {
temp = QByteArray::number((uchar)(input.at(i)), 2);
if (temp.size() < 8) {
int count = temp.size();
for (int j = 0; j < 8 - count ; j++)
temp.prepend("0");
}
output.append(temp);
}
if (blockSize != 0) {
temp = output;
output.clear();
for (int i = 0; i < temp.size(); i += blockSize) {
output.append(temp.mid(i, blockSize)).append(' ');
}
output.chop(1);
}
} else {
bool ok = false;
for (int i = 0; i < input.size(); i++) {
if (BINARYCHAR.contains(input.at(i))) {
temp.append(input.at(i));
} else {
ok = false;
}
}
if (!ok)
emit warning(tr("Invalid characters have been found, they have been ignored."),id);
int length = (temp.size() / 8) * 8;
int rest = temp.size() % 8;
bool errors = false;
for (int i = 0; i < length; i += 8) {
char ch = char(temp.mid(i,8).toUShort(&ok,2));
if (ok)
output.append(ch);
else {
errors = true;
output.append(temp.mid(i,8));
}
}
if (rest != 0) {
output.append(temp.mid(length,rest));
emit warning(tr("Length is not a multiple of 8, ignoring the last bit(s)"),id);
}
if (errors)
emit error(tr("Errors were encountered during the process, faulty blocks have been skipped."),id);
}
}
示例13:
bool Nuria::Serializer::writeField (void *object, Nuria::MetaField &field, const QVariantMap &data) {
QVariant value = data.value (QString::fromLatin1 (field.name ()));
QByteArray typeName = field.typeName ();
bool isPointer = typeName.endsWith ('*');
bool ignored = false;
int pointerId = 0;
if (isPointer) {
pointerId = QMetaType::type (typeName.constData ());
typeName.chop (1);
}
int sourceId = value.userType ();
int targetId = QMetaType::type (typeName.constData ());
if (sourceId != targetId && targetId != QMetaType::QVariant) {
variantToField (value, typeName, targetId, sourceId, pointerId, ignored);
if (ignored) {
return true;
}
}
if ((isPointer && value.isValid ()) || value.userType () == targetId ||
targetId == QMetaType::QVariant) {
return field.write (object, value);
}
//
return false;
}
示例14: file
// Save unfinished time
MPlayer::~MPlayer()
{
#ifdef Q_OS_LINUX
if (!unfinished_time.isEmpty() && Settings::rememberUnfinished)
{
QByteArray data;
QHash<QString, int>::const_iterator i = unfinished_time.constBegin();
while (i != unfinished_time.constEnd())
{
QString name = i.key();
if (!name.startsWith("http://"))
data += name.toUtf8() + '\n' + QByteArray::number(i.value()) + '\n';
i++;
}
data.chop(1); // Remove last '\n'
if (data.isEmpty())
return;
QString filename = QDir::homePath() + "/.moonplayer/unfinished.txt";
QFile file(filename);
if (!file.open(QFile::WriteOnly))
return;
file.write(data);
file.close();
}
else
{
QDir dir = QDir::home();
dir.cd(".moonplayer");
if (dir.exists("unfinished.txt"))
dir.remove("unfinished.txt");
}
#endif
}
示例15: dropMimeData
bool KBModel::dropMimeData(const QMimeData* mime, Qt::DropAction action, int row, int col, const QModelIndex& parent)
{
if (action == Qt::IgnoreAction)
return true;
if (!mime->hasFormat("application/lain.local_binary_objects"))
return false;
QByteArray encodedData = mime->data("application/lain.local_binary_objects");
QByteArray dt = encodedData;
dt.append(' ');
dt.chop(1);
QDataStream stream(&dt, QIODevice::ReadOnly);
QString text;
while (!stream.atEnd())
{
tnode_t tnode;
stream >> tnode;
tnode = db_->tnodeman()->locate(tnode.idx);
text += "Tnode: ";
text += QString::number(tnode.idx);
text += "\t";
text += tnode.mastername;
text += "\n";
}
QMessageBox::information(NULL, tr("Drop!"), text);
return true;
}