当前位置: 首页>>代码示例>>C++>>正文


C++ QByteArray::replace方法代码示例

本文整理汇总了C++中QByteArray::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::replace方法的具体用法?C++ QByteArray::replace怎么用?C++ QByteArray::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QByteArray的用法示例。


在下文中一共展示了QByteArray::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: digest

QByteArray Dialog::digest(const QString s)
{
    QByteArray c = s.toLatin1();
    int index;

    index = 0;

    while ((index = c.indexOf("\\n", index)) != -1) {
        c.replace(index, 2, "\n");
        index += 1;
    }

    index = 0;

    while ((index = c.indexOf("\\t", index)) != -1) {
        c.replace(index, 2, "\t");
        index += 1;
    }

    index = 0;

    while ((index = c.indexOf("\r", index)) != -1) {
        c.remove(index, 1);
    }

    return c;
}
开发者ID:DoUML,项目名称:douml,代码行数:27,代码来源:Dialog.cpp

示例2: SIGNAL

void SignalProxy::SignalRelay::attachSignal(QObject *sender, int signalId, const QByteArray &funcName)
{
    // we ride without safetybelts here... all checking for valid method etc pp has to be done by the caller
    // all connected methodIds are offset by the standard methodCount of QObject
    int slotId;
    for (int i = 0;; i++) {
        if (!_slots.contains(i)) {
            slotId = i;
            break;
        }
    }

    QByteArray fn;
    if (!funcName.isEmpty()) {
        fn = QMetaObject::normalizedSignature(funcName);
    }
    else {
        fn = SIGNAL(fakeMethodSignature());
#if QT_VERSION >= 0x050000
        fn = fn.replace("fakeMethodSignature()", sender->metaObject()->method(signalId).methodSignature());
#else
        fn = fn.replace("fakeMethodSignature()", sender->metaObject()->method(signalId).signature());
#endif
    }

    _slots[slotId] = Signal(sender, signalId, fn);

    QMetaObject::connect(sender, signalId, this, QObject::staticMetaObject.methodCount() + slotId);
}
开发者ID:esainane,项目名称:quassel,代码行数:29,代码来源:signalproxy.cpp

示例3: translate

void MainWindow::translate()
{
    Language *srcLn = mLangageModel->language(ui->sourceComboBox->currentIndex());
    Language *targetLn = mLangageModel->language(ui->targetComboBox->currentIndex());

    QByteArray sourceText = ui->sourceTextEdit->toPlainText().toUtf8();
    sourceText.replace("&", "&");
    sourceText.replace("<", "&lt;");
    sourceText.replace(">", "&gt;");
    sourceText.replace("\n", "<br>");


    QByteArray postData;
    QString source = srcLn->id.toUtf8().toPercentEncoding();
    QString dest = targetLn->id.toUtf8().toPercentEncoding();
    QString texte=ui->sourceTextEdit->toPlainText().toUtf8().toPercentEncoding();
    QString st = "text="+texte+"&client=t&sl=" + source + "&tl=" + dest;

    postData = st.toUtf8();

    QNetworkRequest request(QString(GOOGLE_URL));

    request.setRawHeader("Content-Type","application/x-www-form-urlencoded");
    request.setRawHeader("Host","www.google.com");
    request.setRawHeader("User-Agent","Mozilla/5.0");
    request.setRawHeader("Accept-Encoding","deflate");
    request.setRawHeader("Connection","Close");


    QNetworkReply * reply = mNetManager->post(QNetworkRequest(request),postData);
    qDebug()<<reply->url();
    connect(reply,SIGNAL(finished()),this,SLOT(parseResult()));
}
开发者ID:Wohlstand,项目名称:quicklytranslate,代码行数:33,代码来源:mainwindow.cpp

示例4: parseData

void DBLPFetcher::parseData(QByteArray& data_) {
    // weird XML
    // remove the CDATA and the dblp:: namespace
    data_.replace("<![CDATA[", ""); // krazy:exclude=doublequote_chars
    data_.replace("]]", ""); // krazy:exclude=doublequote_chars
    data_.replace("dblp:", ""); // krazy:exclude=doublequote_chars
}
开发者ID:KDE,项目名称:tellico,代码行数:7,代码来源:dblpfetcher.cpp

示例5: searchResult

SearchEnginesManager::SearchResult SearchEnginesManager::searchResult(const Engine &engine, const QString &string)
{
    ENSURE_LOADED;

    SearchResult result;

    if (engine.postData.isEmpty()) {
        QByteArray url = engine.url.toUtf8();
        url.replace(QLatin1String("%s"), QUrl::toPercentEncoding(string));

        result.request = QNetworkRequest(QUrl::fromEncoded(url));
        result.operation = QNetworkAccessManager::GetOperation;
    }
    else {
        QByteArray data = engine.postData;
        data.replace("%s", QUrl::toPercentEncoding(string));

        result.request = QNetworkRequest(QUrl::fromEncoded(engine.url.toUtf8()));
        result.request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArray("application/x-www-form-urlencoded"));
        result.operation = QNetworkAccessManager::PostOperation;
        result.data = data;
    }

    return result;
}
开发者ID:Tasssadar,项目名称:qupzilla,代码行数:25,代码来源:searchenginesmanager.cpp

示例6: quotedPrintableDecode

QByteArray MCodecs::quotedPrintableDecode(const QByteArray & in) {
    QByteArray out;
    QByteArray chunk = in;
    chunk.replace(QByteArray("=\n\r"),QByteArray());
    chunk.replace(QByteArray("=\n"),QByteArray());
    quotedPrintableDecode(chunk, out);
    return out;
}
开发者ID:Eidolian,项目名称:qt-gmail-access,代码行数:8,代码来源:kcodecs.cpp

示例7: removeEscapes

static void removeEscapes( QByteArray &str )
{
  str.replace( (char *)"\\n", "\n" );
  str.replace( (char *)"\\N", "\n" );
  str.replace( (char *)"\\r", "\r" );
  str.replace( (char *)"\\,", "," );
  str.replace( (char *)"\\\\", "\\" );
}
开发者ID:lenggi,项目名称:kcalcore,代码行数:8,代码来源:vcardparser.cpp

示例8: addEscapes

static void addEscapes( QByteArray &str, bool excludeEscapteComma )
{
  str.replace( '\\', (char *)"\\\\" );
  if ( !excludeEscapteComma ) {
    str.replace( ',', (char *)"\\," );
  }
  str.replace( '\r', (char *)"\\r" );
  str.replace( '\n', (char *)"\\n" );
}
开发者ID:lenggi,项目名称:kcalcore,代码行数:9,代码来源:vcardparser.cpp

示例9: wait

bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &body)
{
    m_state = AwaitingHeader;
    m_data.clear();

    QFile expectFile(expect.toLocalFile());
    if (!expectFile.open(QIODevice::ReadOnly)) return false;

    QFile replyFile(reply.toLocalFile());
    if (!replyFile.open(QIODevice::ReadOnly)) return false;

    bodyData = QByteArray();
    if (body.isValid()) {
        QFile bodyFile(body.toLocalFile());
        if (!bodyFile.open(QIODevice::ReadOnly)) return false;
        bodyData = bodyFile.readAll();
    }

    const QByteArray serverHostUrl = QByteArrayLiteral("127.0.0.1:") + QByteArray::number(server.serverPort());

    QByteArray line;
    bool headers_done = false;
    while (!(line = expectFile.readLine()).isEmpty()) {
        line.replace('\r', "");
        if (line.at(0) == '\n') {
            headers_done = true;
            continue;
        }
        if (headers_done) {
            waitData.body.append(line);
        } else {
            line.replace("{{ServerHostUrl}}", serverHostUrl);
            waitData.headers.append(line);
        }
    }
    /*
    while (waitData.endsWith('\n'))
        waitData = waitData.left(waitData.count() - 1);
        */

    replyData = replyFile.readAll();

    if (!replyData.endsWith('\n'))
        replyData.append("\n");
    replyData.append("Content-length: " + QByteArray::number(bodyData.length()));
    replyData .append("\n\n");

    for (int ii = 0; ii < replyData.count(); ++ii) {
        if (replyData.at(ii) == '\n' && (!ii || replyData.at(ii - 1) != '\r')) {
            replyData.insert(ii, '\r');
            ++ii;
        }
    }
    replyData.append(bodyData);

    return true;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:57,代码来源:testhttpserver.cpp

示例10: hash

QString KQOAuthUtils::hmac_sha1(const QString &message, const QString &key)
{
    QByteArray keyBytes = key.toAscii();
    int keyLength;              // Lenght of key word
    const int blockSize = 64;   // Both MD5 and SHA-1 have a block size of 64.

    keyLength = keyBytes.size();
    // If key is longer than block size, we need to hash the key
    if (keyLength > blockSize) {
        QCryptographicHash hash(QCryptographicHash::Sha1);
        hash.addData(keyBytes);
        keyBytes = hash.result();
    }

    /* http://tools.ietf.org/html/rfc2104  - (1) */
    // Create the opad and ipad for the hash function.
    QByteArray ipad;
    QByteArray opad;

    ipad.fill( 0, blockSize);
    opad.fill( 0, blockSize);

    ipad.replace(0, keyBytes.length(), keyBytes);
    opad.replace(0, keyBytes.length(), keyBytes);

    /* http://tools.ietf.org/html/rfc2104 - (2) & (5) */
    for (int i=0; i<64; i++) {
        ipad[i] = ipad[i] ^ 0x36;
        opad[i] = opad[i] ^ 0x5c;
    }

    QByteArray workArray;
    workArray.clear();

    workArray.append(ipad, 64);
    /* http://tools.ietf.org/html/rfc2104 - (3) */
    workArray.append(message.toAscii());


    /* http://tools.ietf.org/html/rfc2104 - (4) */
    QByteArray sha1 = QCryptographicHash::hash(workArray, QCryptographicHash::Sha1);

    /* http://tools.ietf.org/html/rfc2104 - (6) */
    workArray.clear();
    workArray.append(opad, 64);
    workArray.append(sha1);

    sha1.clear();

    /* http://tools.ietf.org/html/rfc2104 - (7) */
    sha1 = QCryptographicHash::hash(workArray, QCryptographicHash::Sha1);
    return QString(sha1.toBase64());
}
开发者ID:Mendeley,项目名称:kqoauth,代码行数:53,代码来源:kqoauthutils.cpp

示例11: handleResponse

void SetMetaDataJob::handleResponse(const Message &response)
{
    Q_D(SetMetaDataJob);

    //TODO: Test if a server can really return more then one untagged NO response. If not, no need to OR the error codes
    if (!response.content.isEmpty() &&
        d->tags.contains(response.content.first().toString())) {
        if (response.content[1].toString() == "NO") {
            setError(UserDefinedError);
            setErrorText(i18n("%1 failed, server replied: %2", d->m_name, QLatin1String(response.toString().constData())));
            if (response.content[2].toString() == "[ANNOTATEMORE TOOMANY]" ||
                    response.content[2].toString() == "[METADATA TOOMANY]") {
                d->metaDataErrors |= TooMany;
            } else if (response.content[2].toString() == "[ANNOTATEMORE TOOBIG]" ||
                       response.content[2].toString().startsWith("[METADATA MAXSIZE")) {    //krazy:exclude=strings
                d->metaDataErrors |= TooBig;
                d->maxAcceptedSize = -1;
                if (response.content[2].toString().startsWith("[METADATA MAXSIZE")) {     //krazy:exclude=strings
                    QByteArray max = response.content[2].toString();
                    max.replace("[METADATA MAXSIZE", "");   //krazy:exclude=doublequote_chars
                    max.replace("]", "");                   //krazy:exclude=doublequote_chars
                    d->maxAcceptedSize = max.toLongLong();
                }
            } else if (response.content[2].toString() == "[METADATA NOPRIVATE]") {
                d->metaDataErrors |= NoPrivate;
            }
        } else if (response.content.size() < 2) {
            setErrorText(i18n("%1 failed, malformed reply from the server.", d->m_name));
        } else if (response.content[1].toString() != "OK") {
            setError(UserDefinedError);
            setErrorText(i18n("%1 failed, server replied: %2", d->m_name, QLatin1String(response.toString().constData())));
        }
        emitResult();
    } else if (d->serverCapability == Metadata && response.content[0].toString() == "+") {
        QByteArray content = "";
        if (d->entriesIt.value().isEmpty()) {
            content += "NIL";
        } else {
            content +=  d->entriesIt.value();
        }
        ++d->entriesIt;
        if (d->entriesIt == d->entries.constEnd()) {
            content += ')';
        } else {
            content += " \"" + d->entriesIt.key() + '\"';
            int size = d->entriesIt.value().size();
            content += " {" + QByteArray::number( size==0 ? 3 : size ) + '}';
        }
//      qCDebug(KIMAP_LOG) << "SENT: " << content;
        d->sessionInternal()->sendData(content);
    }
}
开发者ID:KDE,项目名称:kimap,代码行数:52,代码来源:setmetadatajob.cpp

示例12: toQByteArray

QByteArray HtmlReporter::toQByteArray() const{
	collector.flush();
	linkCollector.flush();
	if(collected.size() == 0) return QByteArray();
	QByteArray filecontent = loadFile(":/template.html");
	filecontent.replace("$title", title.toUtf8());
	filecontent.replace("$content", collected);
	filecontent.replace("$show", tr("show").toUtf8());
	filecontent.replace("$hide", tr("hide").toUtf8());
	filecontent.replace("$links", linkCollected + "</ul>");
	filecontent.replace("$version", "readesm " VERSION " (" VERSION_DATE ")");
	return filecontent;
}
开发者ID:roidelapluie,项目名称:readesm,代码行数:13,代码来源:HtmlReporter.cpp

示例13: testHelpOption

void tst_QCommandLineParser::testHelpOption()
{
#ifdef QT_NO_PROCESS
    QSKIP("This test requires QProcess support");
#else
#ifdef Q_OS_WINCE
    QSKIP("Reading and writing to a process is not supported on Qt/CE");
#endif
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
    QSKIP("Deploying executable applications to file system on Android not supported.");
#endif

    QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode);
    QFETCH(QString, expectedHelpOutput);
    QCoreApplication app(empty_argc, empty_argv);
    QProcess process;
    process.start("testhelper/qcommandlineparser_test_helper", QStringList() << QString::number(parsingMode) << "--help");
    QVERIFY(process.waitForFinished(5000));
    QCOMPARE(process.exitStatus(), QProcess::NormalExit);
    QString output = process.readAll();
#ifdef Q_OS_WIN
    output.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
#endif
    QCOMPARE(output.split('\n'), expectedHelpOutput.split('\n')); // easier to debug than the next line, on failure
    QCOMPARE(output, expectedHelpOutput);

    process.start("testhelper/qcommandlineparser_test_helper", QStringList() << "0" << "resize" << "--help");
    QVERIFY(process.waitForFinished(5000));
    QCOMPARE(process.exitStatus(), QProcess::NormalExit);
    output = process.readAll();
#ifdef Q_OS_WIN
    output.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
#endif
    QByteArray expectedResizeHelp = QByteArrayLiteral(
                                        "Usage: testhelper/qcommandlineparser_test_helper [options] resize [resize_options]\n"
                                        "Test helper\n"
                                        "\n")
                                    + expectedOptionsHelp +
                                    "  --size <size>               New size.\n"
                                    "\n"
                                    "Arguments:\n"
                                    "  resize                      Resize the object to a new size.\n";
#ifdef Q_OS_WIN
    expectedResizeHelp.replace("  -h, --help                  Displays this help.\n",
                               "  -?, -h, --help              Displays this help.\n");
    expectedResizeHelp.replace("testhelper/", "testhelper\\");
#endif
    QCOMPARE(output, QString(expectedResizeHelp));
#endif // !QT_NO_PROCESS
}
开发者ID:krysanto,项目名称:steamlink-sdk,代码行数:50,代码来源:tst_qcommandlineparser.cpp

示例14: executeDebuggerCommand

void TcfEngine::executeDebuggerCommand(const QString &command)
{
    QByteArray cmd = command.toUtf8();
    cmd = cmd.mid(cmd.indexOf(' ') + 1);
    QByteArray null;
    null.append('\0');
    // FIXME: works for single-digit escapes only
    cmd.replace("\\0", null);
    cmd.replace("\\1", "\1");
    cmd.replace("\\3", "\3");
    TcfCommand tcf;
    tcf.command = cmd;
    enqueueCommand(tcf);
}
开发者ID:asokolov,项目名称:ananas-creator,代码行数:14,代码来源:tcfengine.cpp

示例15: replaceTokens

void EnergyPlotter::replaceTokens(QByteArray& commands)
{
	QString limbName;
	switch (m_limb)
	{
		case 0: limbName = "Left thigh";      break;
		case 1: limbName = "Right thigh";     break;
		case 2: limbName = "Left lower leg";  break;
		case 3: limbName = "Right lower leg"; break;
	}
	
	commands.replace("__LIMB__", limbName.toAscii());
	commands.replace("__VOXEL_FILENAME__", QFileInfo(frameInfo()->fileName()).fileName().toAscii());
}
开发者ID:davidsansome,项目名称:gait-modelfitting,代码行数:14,代码来源:energyplotter.cpp


注:本文中的QByteArray::replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。