int formatResult(char * buffer, int bufferSize, T number, int significantDigits) { QString result = formatResult(number, significantDigits); qstrncpy(buffer, result.toAscii().constData(), bufferSize); int size = result.count(); return size; }
bool DictWidget::lookup(const QString &word) { if (word.isEmpty()) { return false; } resetSimilarWordsOffset(); // Clean the word. word_ = word.trimmed(); // Title QString result; bool ret = dict_.translate(word_, result); formatResult(result); // Result doc_.setHtml(result); // Always stop timer as the screen can be updated later. launchTimer(false); updateVisibleWidgets(); onDetailsClicked(true); return ret; }
bool DictFrame::lookup(const QString &word) { if (word.isEmpty()) { return false; } resetSimilarWordsOffset(); // Clean the word. word_ = word.trimmed(); // Title QString result; bool ret = dict_mgr_.translate(word_, result); formatResult(result); // Result doc_.setHtml(result); updateVisibleWidgets(); onDetailsClicked(true); return ret; }
static jcharArray format(JNIEnv* env, jint addr, jobject fpIter, T val) { UErrorCode status = U_ZERO_ERROR; UnicodeString str; DecimalFormat* fmt = toDecimalFormat(addr); FieldPositionIterator fpi; FieldPositionIterator* pfpi = fpIter ? &fpi : NULL; fmt->format(reinterpret_cast<const Formattable&>(val), str, pfpi, status); return formatResult(env, str, pfpi, fpIter); }
// static void printBenchmarkResult(const char *bmtag, int value, int iterations) static void printBenchmarkResult(const QBenchmarkResult &result) { const char *bmtag = QTest::benchmarkResult2String(); char buf1[1024]; QTest::qt_snprintf( buf1, sizeof(buf1), "%s: %s::%s", bmtag, QTestResult::currentTestObjectName(), result.context.slotName.toAscii().data()); char bufTag[1024]; bufTag[0] = 0; QByteArray tag = result.context.tag.toAscii(); if (tag.isEmpty() == false) { QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); } char fillFormat[8]; int fillLength = 5; QTest::qt_snprintf( fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); char fill[1024]; QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); QByteArray unitText = QBenchmarkGlobalData::current->measurer->unitText().toAscii(); qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); char resultBuffer[100] = ""; formatResult(resultBuffer, 100, valuePerIteration, countSignificantDigits(result.value)); QByteArray iterationText = "per iteration"; char buf2[1024]; Q_ASSERT(result.iterations > 0); QTest::qt_snprintf( buf2, sizeof(buf2), "%s %s %s", resultBuffer, unitText.data(), iterationText.data()); char buf3[1024]; Q_ASSERT(result.iterations > 0); QTest::qt_snprintf( buf3, sizeof(buf3), " (total: %s, iterations: %d)\n", QByteArray::number(result.value).constData(), // no 64-bit qt_snprintf support result.iterations); char buf[1024]; QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s%s", buf1, bufTag, fill, buf2, buf3); memcpy(buf, bmtag, strlen(bmtag)); outputMessage(buf); }
static jcharArray format(JNIEnv* env, jlong addr, jobject javaFieldPositionIterator, T value) { UErrorCode status = U_ZERO_ERROR; UnicodeString s; DecimalFormat* fmt = toDecimalFormat(addr); FieldPositionIterator nativeFieldPositionIterator; FieldPositionIterator* fpi = javaFieldPositionIterator ? &nativeFieldPositionIterator : NULL; fmt->format(value, s, fpi, status); if (maybeThrowIcuException(env, "DecimalFormat::format", status)) { return NULL; } return formatResult(env, s, fpi, javaFieldPositionIterator); }
bool DictWidget::lookup(const QString &word) { if (word.isEmpty() || word_ == word.trimmed()) { return false; } resetSimilarWordsOffset(); // Clean the word. word_ = word.trimmed(); //remove quotes (“ ” " ) If it in the words if(word_.contains(QChar(0x201C)) || word_.contains(QChar(0x201D)) || word_.contains(QChar(0x0022))) { word_.remove(QChar(0x201C)); word_.remove(QChar(0x201D)); word_.remove(QChar(0x0022)); } // Title QString result; QString fuzzy_word(""); bool ret = dict_.fuzzyTranslate(word_, result, fuzzy_word); fuzzy_word_ = fuzzy_word; formatResult(result, fuzzy_word); // Result doc_.setHtml(result); // Always stop timer as the screen can be updated later. launchTimer(false); update_parent_ = false; updateVisibleWidgets(); onDetailsClicked(true); return ret; }
bool DictWidget::lookup(const QString &word, bool update_screen) { if (word.isEmpty() || word_ == word.trimmed()) { return false; } resetSimilarWordsOffset(); // Clean the word. word_ = word.trimmed(); // Title QString result; QString fuzzy_word(""); bool ret = dict_.fuzzyTranslate(word_, result, fuzzy_word); formatResult(result, fuzzy_word); // Result doc_.setHtml(result); // Always stop timer as the screen can be updated later. launchTimer(false); updateVisibleWidgets(); changeInternalState(EXPLANATION); checkSelectedButton(); explanation_text_.show(); explanation_text_.setFocus(); similar_words_view_.hide(); s_enable_update = update_screen; return ret; }
static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, FD_t fd, const char *fn) { char *buf = NULL; char *missingKeys = NULL; char *untrustedKeys = NULL; struct rpmtd_s sigtd; pgpDigParams sig = NULL; Header sigh = NULL; HeaderIterator hi = NULL; char * msg = NULL; int res = 1; /* assume failure */ rpmRC rc; int failed = 0; int nodigests = !(flags & VERIFY_DIGEST); int nosignatures = !(flags & VERIFY_SIGNATURE); struct sigtInfo_s sinfo; rpmDigestBundle plbundle = rpmDigestBundleNew(); rpmDigestBundle hdrbundle = rpmDigestBundleNew(); if ((rc = rpmLeadRead(fd, NULL, NULL, &msg)) != RPMRC_OK) { goto exit; } rc = rpmReadSignature(fd, &sigh, RPMSIGTYPE_HEADERSIG, &msg); if (rc != RPMRC_OK) { goto exit; } /* Initialize all digests we'll be needing */ hi = headerInitIterator(sigh); for (; headerNext(hi, &sigtd) != 0; rpmtdFreeData(&sigtd)) { rc = rpmSigInfoParse(&sigtd, "package", &sinfo, NULL, NULL); if (nosignatures && sinfo.type == RPMSIG_SIGNATURE_TYPE) continue; if (nodigests && sinfo.type == RPMSIG_DIGEST_TYPE) continue; if (rc == RPMRC_OK && sinfo.hashalgo) { rpmDigestBundleAdd(sinfo.payload ? plbundle : hdrbundle, sinfo.hashalgo, RPMDIGEST_NONE); } } hi = headerFreeIterator(hi); /* Read the file, generating digest(s) on the fly. */ fdSetBundle(fd, plbundle); if (readFile(fd, fn, plbundle, hdrbundle)) { goto exit; } rasprintf(&buf, "%s:%c", fn, (rpmIsVerbose() ? '\n' : ' ') ); hi = headerInitIterator(sigh); for (; headerNext(hi, &sigtd) != 0; rpmtdFreeData(&sigtd)) { char *result = NULL; DIGEST_CTX ctx = NULL; if (sigtd.data == NULL) /* XXX can't happen */ continue; /* Clean up parameters from previous sigtag. */ sig = pgpDigParamsFree(sig); /* Note: we permit failures to be ignored via disablers */ rc = rpmSigInfoParse(&sigtd, "package", &sinfo, &sig, &result); if (nosignatures && sinfo.type == RPMSIG_SIGNATURE_TYPE) continue; if (nodigests && sinfo.type == RPMSIG_DIGEST_TYPE) continue; if (sinfo.type == RPMSIG_OTHER_TYPE) continue; if (rc == RPMRC_OK) { ctx = rpmDigestBundleDupCtx(sinfo.payload ? plbundle : hdrbundle, sinfo.hashalgo); rc = rpmVerifySignature(keyring, &sigtd, sig, ctx, &result); rpmDigestFinal(ctx, NULL, NULL, 0); } if (result) { formatResult(sigtd.tag, rc, result, (rc == RPMRC_NOKEY ? &missingKeys : &untrustedKeys), &buf); free(result); } if (rc != RPMRC_OK) { failed = 1; } } res = failed; if (rpmIsVerbose()) { rpmlog(RPMLOG_NOTICE, "%s", buf); } else { const char *ok = (failed ? _("NOT OK") : _("OK")); rpmlog(RPMLOG_NOTICE, "%s%s%s%s%s%s%s%s\n", buf, ok, missingKeys ? _(" (MISSING KEYS:") : "", missingKeys ? missingKeys : "", missingKeys ? _(") ") : "", untrustedKeys ? _(" (UNTRUSTED KEYS:") : "", untrustedKeys ? untrustedKeys : "", untrustedKeys ? _(")") : ""); } free(missingKeys); free(untrustedKeys); exit: if (res && msg != NULL) rpmlog(RPMLOG_ERR, "%s: %s\n", fn, msg); free(msg); free(buf); rpmDigestBundleFree(hdrbundle); rpmDigestBundleFree(plbundle); fdSetBundle(fd, NULL); /* XXX avoid double-free from fd close */ sigh = rpmFreeSignature(sigh); hi = headerFreeIterator(hi); pgpDigParamsFree(sig); return res; }
// static void printBenchmarkResult(const char *bmtag, int value, int iterations) static void printBenchmarkResult(const QBenchmarkResult &result) { const char *bmtag = QTest::benchmarkResult2String(); char buf1[1024]; QTest::qt_snprintf( buf1, sizeof(buf1), "%s: %s::%s", bmtag, QTestResult::currentTestObjectName(), result.context.slotName.toAscii().data()); char bufTag[1024]; bufTag[0] = 0; QByteArray tag = result.context.tag.toAscii(); if (tag.isEmpty() == false) { QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); } char fillFormat[8]; int fillLength = 5; QTest::qt_snprintf( fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); char fill[1024]; QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); const char * unitText = QTest::benchmarkMetricUnit(result.metric); qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); char resultBuffer[100] = ""; formatResult(resultBuffer, 100, valuePerIteration, countSignificantDigits(result.value)); char buf2[1024]; QTest::qt_snprintf( buf2, sizeof(buf2), "%s %s", resultBuffer, unitText); char buf2_[1024]; QByteArray iterationText = " per iteration"; Q_ASSERT(result.iterations > 0); QTest::qt_snprintf( buf2_, sizeof(buf2_), "%s", iterationText.data()); char buf3[1024]; Q_ASSERT(result.iterations > 0); formatResult(resultBuffer, 100, result.value, countSignificantDigits(result.value)); QTest::qt_snprintf( buf3, sizeof(buf3), " (total: %s, iterations: %d)", resultBuffer, result.iterations); char buf[1024]; if (result.setByMacro) { QTest::qt_snprintf( buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3); } else { QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); } memcpy(buf, bmtag, strlen(bmtag)); outputMessage(buf); }