void loadValue(pugi::xml_node attrib, const BoundSetter<std::vector<T> >& setValue) { std::string vec = attrib.attribute("value").value(); std::vector<T> value; T buffer; size_t pos = 0; size_t next = vec.find(';'); if(next - pos > 1) { decodeValue(vec.substr(pos + 1, next - pos - 1), buffer); value.push_back(buffer); } pos = next; while(pos != std::string::npos) { next = vec.find(';', pos + 1); if(next - pos > 1) { decodeValue(vec.substr(pos + 1, next - pos - 1), buffer); value.push_back(buffer); } pos = next; } setValue(value); }
void loadValue(pugi::xml_node attrib, const BoundSetter<Pair<T> >& setValue) { Pair<T> value = Pair<T>(); decodeValue(attrib.attribute("value1").value(), value.value1); decodeValue(attrib.attribute("value2").value(), value.value2); setValue(value); }
void loadValue(pugi::xml_node attrib, const BoundSetter<Quadruplet<T> >& setValue) { Quadruplet<T> value = Quadruplet<T>(); decodeValue(attrib.attribute("value1").value(), value.value1); decodeValue(attrib.attribute("value2").value(), value.value2); decodeValue(attrib.attribute("value3").value(), value.value3); decodeValue(attrib.attribute("value4").value(), value.value4); setValue(value); }
char *decode(long long value, int pos){ int cnt = 0; char *buf = (char * )malloc(sizeof(char) * 12); for(int j = 0;j < LENGTH;j++){ buf[j] = decodeValue(0); } while(value > 0){ //tmp = value % 4; buf[cnt++] = decodeValue(value % 4); value /= 4; } return buf; //return buf[pos]; }
void Asterisk::onSocketReadyRead() { // qDebug("<ready-read>"); QVariantHash headers; while (socket.canReadLine()) { QByteArray line = socket.readLine(); // qDebug() << "Line:" << line; if (line != "\r\n") { QStringList header = QString(line.trimmed()).split(':'); headers.insertMulti(header[0], decodeValue(header[1].trimmed())); } else { if (headers.contains("Response")) responses.insert(headers.take("ActionID").toString(), headers); else if (headers.contains("Event")) emit eventReceived(headers.take("Event").toString(), headers); headers.clear(); } } // qDebug("</ready-read>"); }
Recognizer::ErrorCode Recognizer::errorCorrection(const QStringList & encodedValue, QStringList * const variants) { // making map of possible characters for each illegible character // and calculating checksum for each combination for make list of // success combinations "variants" // possible characters have only one different item // if it has IllegibleValues we are testing ONLY them QString value = decodeValue(encodedValue); bool hasIllegibleValues = value.contains("?"); QList <QList<int> > map; for (int k=0; k<value.size(); ++k) { QList<int> list; if (hasIllegibleValues && value[k] != '?') { map.append(list); continue; } QStringList illegibleValue; for (int i=0; i<3; ++i) // 3 since last line is empty illegibleValue.append(encodedValue[i].mid(k*3,3)); list = possibleCharacters(illegibleValue); map.append(list); } // testing each possible variant for checksum and adding correct one to "variants" list for (int i=0; i<value.size(); ++i) { for (int j=0; j<map[i].size(); ++j) { QString testValue = value; testValue.replace(i,1,QString::number(map[i][j])); if (checkSum(testValue) == OK) variants->append(testValue); } } if (variants->count() == 0) return ILL; else if (variants->count() == 1) return OK; else return AMB; return ERR; }
v8::Local<v8::Object> decodeObject(bson_iterator *it, bool bArray) { v8::Local<v8::Object> obj; if (bArray) obj = v8::Array::New(isolate); else obj = v8::Object::New(isolate); while (bson_iterator_next(it)) decodeValue(obj, it); return obj; }
void Recognizer::parseFile(const QString & infileName, const QString & outfileName) { QFile inFile(infileName); if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QFile outFile(outfileName); if (!outfileName.isEmpty() && !outFile.open(QIODevice::WriteOnly | QIODevice::Text)) return; // use textstream instead of direct file reading for prevent // problems with different RETURN symbol on different platforms // textstream always returns trimmed string QTextStream in(&inFile); QTextStream out(&outFile); QStringList lineList; QString line; do { line = in.readLine(); lineList.append(line); // 4 lines read so starting to process them if (lineList.count() == 4) { QString accountNumber = decodeValue(lineList); ErrorCode code = checkSum(accountNumber); // correct errors if possible QStringList possibleVariants; if (code == ILL || code == ERR) { code = errorCorrection(lineList, &possibleVariants); } QString formattedString; // was value corrected or or it's iginal if (possibleVariants.size() == 1) formattedString.append(possibleVariants[0]); else formattedString.append(accountNumber); // status if (code == AMB) { formattedString += " " + errorToString(code) + " [\'" + possibleVariants.join("\',\'") + "\']"; } else formattedString += " " + errorToString(code); if (outfileName.isEmpty()) std::cout << formattedString.toStdString() << std::endl; else out << formattedString << "\n"; lineList.clear(); possibleVariants.clear(); } } while(!line.isNull()); inFile.close(); if (outFile.isOpen()) outFile.close(); }
SkPDFImage::SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha, const SkIRect& srcRect) : fIsAlpha(isAlpha), fSrcRect(srcRect) { if (bitmap.isImmutable()) { fBitmap = bitmap; } else { bitmap.deepCopyTo(&fBitmap); fBitmap.setImmutable(); } if (stream != NULL) { this->setData(stream); fStreamValid = true; } else { fStreamValid = false; } SkColorType colorType = fBitmap.colorType(); insertName("Type", "XObject"); insertName("Subtype", "Image"); bool alphaOnly = (kAlpha_8_SkColorType == colorType); if (!isAlpha && alphaOnly) { // For alpha only images, we stretch a single pixel of black for // the color/shape part. SkAutoTUnref<SkPDFInt> one(new SkPDFInt(1)); insert("Width", one.get()); insert("Height", one.get()); } else { insertInt("Width", fSrcRect.width()); insertInt("Height", fSrcRect.height()); } if (isAlpha || alphaOnly) { insertName("ColorSpace", "DeviceGray"); } else if (kIndex_8_SkColorType == colorType) { SkAutoLockPixels alp(fBitmap); insert("ColorSpace", make_indexed_color_space(fBitmap.getColorTable()))->unref(); } else { insertName("ColorSpace", "DeviceRGB"); } int bitsPerComp = 8; if (kARGB_4444_SkColorType == colorType) { bitsPerComp = 4; } insertInt("BitsPerComponent", bitsPerComp); if (kRGB_565_SkColorType == colorType) { SkASSERT(!isAlpha); SkAutoTUnref<SkPDFInt> zeroVal(new SkPDFInt(0)); SkAutoTUnref<SkPDFScalar> scale5Val( new SkPDFScalar(8.2258f)); // 255/2^5-1 SkAutoTUnref<SkPDFScalar> scale6Val( new SkPDFScalar(4.0476f)); // 255/2^6-1 SkAutoTUnref<SkPDFArray> decodeValue(new SkPDFArray()); decodeValue->reserve(6); decodeValue->append(zeroVal.get()); decodeValue->append(scale5Val.get()); decodeValue->append(zeroVal.get()); decodeValue->append(scale6Val.get()); decodeValue->append(zeroVal.get()); decodeValue->append(scale5Val.get()); insert("Decode", decodeValue.get()); } }
static bool parseTestSource(const std::string &path, TestFile &tests) { auto file = std::ifstream { path }; std::string name, lhs, rhs; Target target; Value value; TestData *data = nullptr; for (std::string line; std::getline(file, line); ) { line = trim(line); if (!line.size()) { continue; } // Decode test name if (line.back() == ':') { name = line; name.erase(name.end() - 1); data = &tests.tests[name]; } // Decode input if (line.find("# in ") == 0) { line.erase(0, std::strlen("# in ")); if (!parseAssignment(line, lhs, rhs)) { return false; } if (!decodeLHS(lhs, target)) { return false; } if (!decodeValue(rhs, target, value)) { return false; } data->fields[target].setInput(value); } // Decode output if (line.find("# out ") == 0) { line.erase(0, std::strlen("# out ")); if (!parseAssignment(line, lhs, rhs)) { return false; } if (!decodeLHS(lhs, target)) { return false; } if (!decodeValue(rhs, target, value)) { return false; } data->fields[target].setOutput(value); } } return true; }
QString SmtpConfiguration::smtpPassword() const { return decodeValue(value("smtppassword")); }
void loadValue(pugi::xml_node attrib, const BoundSetter<T>& setValue) { T value = T(); decodeValue(attrib.attribute("value").value(), value); setValue(value); }