QStringList CSite::traffic(quint16 &busy) const { QStringList zeeiList = m_zeei.split("\n"); QStringList btsList = zeeiList.filter("BTS-"); busy = 0; QStringList btss; for (int i = 0; i < btsList.count(); i++) { QStringList btsLine = btsList[i].split(" "); btsLine.removeAll(""); QString state = btsLine[btsLine.indexOf(btsLine.filter("BTS-").first()) + 2]; if (state.contains("BL-")) { btss << state; continue; } QString fr = btsLine.takeLast(); QString hr = btsLine.takeLast(); quint8 btsBusy = fr.toUShort() + hr.toUShort(); if (!btsBusy) btss << "EMPTY"; else if (i < m_caps.count() && btsBusy > m_caps[i] - BUSY_LIMIT) btss << "FULL"; else btss << QString::number(btsBusy); busy += btsBusy; } return btss; }
void Lexer::consumeEscapeSequenceNumber() { char type; QString allowedChars; short maxSize; if(_currentChar == 'x' || _currentChar == 'X') { type = 'x'; allowedChars = "0123456789abcdef"; maxSize = 2; consume(); } else if(_currentChar == 'u' || _currentChar == 'U') { type = 'u'; allowedChars = "0123456789abcdef"; maxSize = 4; consume(); } else { type = 'o'; allowedChars = "01234567"; maxSize = 3; } QString number = ""; while(number.size() < maxSize) { if(isEof()) throw lexerException("unexpected EOF found in an escape sequence number"); if(!allowedChars.contains(_currentChar, Qt::CaseInsensitive)) break; number.append(_currentChar); consume(); } if(number.isEmpty()) throw lexerException("invalid escape sequence number"); bool ok; ushort code = type == 'o' ? number.toUShort(&ok, 8) : number.toUShort(&ok, 16); if(!ok) throw lexerException("invalid number in escape sequence"); if(type != 'u' && code > 0xFF) throw lexerException("invalid number in escape sequence"); }
static ushort unicode(const QString &string) { if (string.length() == 1) return string.at(0).unicode(); uint n = string.toUShort(); if (!n) n = string.toUShort(0,16); if (!n) n = string.toUShort(0,8); return n; }
void OscapScannerRemoteSsh::splitTarget(const QString& in, QString& target, unsigned short& port) { // NB: We dodge a bullet here because the editor will always pass a port // as the last component. A lot of checking and parsing does not need // to be done. // // 'in' is in the format of username@hostname:port, the port always // being there and always being the last component. // FIXME: Ideally, this should split from the right side and stop after one split QStringList split = in.split(':'); const QString portString = split.back(); split.removeLast(); { bool status = false; const unsigned short portCandidate = portString.toUShort(&status, 10); // FIXME: Error reporting? port = status ? portCandidate : 22; } target = split.join(":"); }
bool GlyphElement::readMathMLAttributes( const KXmlElement& element ) { // MathML Section 3.2.9.2 m_fontFamily = element.attribute( "fontfamily" ); if ( m_fontFamily.isNull() ) { kWarning( DEBUGID ) << "Required attribute fontfamily not found in glyph element"; return false; } QString indexStr = element.attribute( "index" ); if ( indexStr.isNull() ) { kWarning( DEBUGID ) << "Required attribute index not found in glyph element"; return false; } bool ok; ushort index = indexStr.toUShort( &ok ); if ( ! ok ) { kWarning( DEBUGID ) << "Invalid index value in glyph element"; return false; } m_char = QChar( index ); m_alt = element.attribute( "alt" ); if ( m_alt.isNull() ) { kWarning( DEBUGID ) << "Required attribute alt not found in glyph element"; return false; } // TODO: Check whether we have needed fontfamily return true; }
IlwisTypes Domain::ilwType(const QString &value) { std::set<QString> booleans ={ "yes","no","true","false"}; if ( booleans.find(value.toLower()) != booleans.end()) return itBOOL; bool ok; ushort vu = value.toUShort(&ok); if ( ok && vu < 255) return itUINT8; if ( ok) return itUINT16; short vs = value.toShort(&ok); if ( ok && vs > -128 && vs < 128) return itINT8; if ( ok) return itINT16; value.toULong(&ok); if ( ok) return itUINT32; value.toLong(&ok); if ( ok) return itINT32; value.toLongLong(&ok); if ( ok) return itINT64; value.toDouble(&ok); if ( ok) return itDOUBLE; return IlwisObject::findType(value); }
void SearchWidget::changeList2(QNetworkReply *reply) { qDebug()<<"danny error type"<<reply->error(); if(reply->error()== QNetworkReply::NoError) { lyricList.clear(); //QString text = reply->readAll(); QByteArray bytes = reply->readAll(); //获取字节 QString result(bytes); //转化为字符串 qDebug()<<"changeList2 result:"<<result; qDebug()<<"changeList2 reply:"<<bytes; QTextCodec *codec = QTextCodec::codecForName("utf-8"); //QString str = "0891683108500145F1240D91685143256178F0000831214281659423044F60597D"; QString t = result; QStringList s; for(int i = 0;i < t.length();i += 4) { s.append(t.mid(i,4)); } QString t1; foreach (const QString &t, s) { t1.append(t.toUShort(0,16)); }
/** * @brief SessionsModel::slotLoadSession * @param nameroots absolute file paths without the trailing _summary/_data/_meta/_targets */ void SessionsModel::slotLoadSession(QStringList nameroots){ OctaveProxy* proxy = Master::getInstance()->getOctaveProxy(); for(int i=0; i<nameroots.length(); ++i){ beginInsertRows(QModelIndex(), this->sessions.length(), this->sessions.length()); QString subject; QString phrase; QDateTime created; QString dimStint; QString highlightStint; QString repeats; bool clean = parseSummaryFile(nameroots.at(i)+"_summary", subject, phrase, created, dimStint, highlightStint, repeats); P3SessionInfo* info = proxy->loadP3Session(nameroots.at(i)); if(info!=NULL){ P3SessionInfo* infoFull = new P3SessionInfo(subject, phrase, clean, created, info->getSession(), dimStint.toUInt(), highlightStint.toUInt(), repeats.toUShort()); this->sessions.push_back(infoFull); }else{ qWarning()<<"Problems loading session "<<nameroots.at(i)<<". Ignoring and continuing."; } endInsertRows(); qDebug()<<"Emitting dataChanged()"; emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, columnCount()-1)); } }
ushort XMLEntities::GetEntityCode(const QString name) { ushort code = 0; if (name.startsWith("&") && name.endsWith(";")) { QString root; int n = name.length(); root = name.mid(1,n-2); if (root.startsWith("#")) { bool ok; int base = 10; root = root.mid(1); if (root.startsWith('x', Qt::CaseInsensitive)) { base = 16; root = root.mid(1); } int rcode = root.toUShort(&ok, base); if (ok) code = rcode; } else { if (m_EntityCode.contains(root)) { code = m_EntityCode.value(root, 0); } } } return code; }
void SetValue(void* Pointer, const QString &Value, int Type) { if (!Pointer) return; switch (Type) { case QMetaType::Char: *((char*)Pointer) = Value.isEmpty() ? 0 : Value.at(0).toLatin1(); return; case QMetaType::UChar: *((unsigned char*)Pointer) = Value.isEmpty() ? 0 :Value.at(0).toLatin1(); return; case QMetaType::QChar: *((QChar*)Pointer) = Value.isEmpty() ? 0 : Value.at(0); return; case QMetaType::Bool: *((bool*)Pointer) = ToBool(Value); return; case QMetaType::Short: *((short*)Pointer) = Value.toShort(); return; case QMetaType::UShort: *((ushort*)Pointer) = Value.toUShort(); return; case QMetaType::Int: *((int*)Pointer) = Value.toInt(); return; case QMetaType::UInt: *((uint*)Pointer) = Value.toUInt(); return; case QMetaType::Long: *((long*)Pointer) = Value.toLong(); return; case QMetaType::ULong: *((ulong*)Pointer) = Value.toULong(); return; case QMetaType::LongLong: *((qlonglong*)Pointer) = Value.toLongLong(); return; case QMetaType::ULongLong: *((qulonglong*)Pointer) = Value.toULongLong(); return; case QMetaType::Double: *((double*)Pointer) = Value.toDouble(); return; case QMetaType::Float: *((float*)Pointer) = Value.toFloat(); return; case QMetaType::QString: *((QString*)Pointer) = Value; return; case QMetaType::QByteArray: *((QByteArray*)Pointer) = Value.toUtf8(); return; case QMetaType::QTime: *((QTime*)Pointer) = QTime::fromString(Value, Qt::ISODate); return; case QMetaType::QDate: *((QDate*)Pointer) = QDate::fromString(Value, Qt::ISODate); return; case QMetaType::QDateTime: { QDateTime dt = QDateTime::fromString(Value, Qt::ISODate); dt.setTimeSpec(Qt::UTC); *((QDateTime*)Pointer) = dt; return; } default: break; } }
bool str2DataType(const QString &str, U2DataType &res) { bool conversionOk = false; // hope that "U2DataType" typedef won't change SAFE_POINT(sizeof(U2DataType) == sizeof(qint16), "Unexpected data type detected", false); res = str.toUShort(&conversionOk); return conversionOk; }
void network_layer::snd_lower_thread() { while(!_quit){ QDomDocument* doc = _rcv_upper_doc_que.pop(!_quit); if(!doc){ continue; } const QString& id = _rcv_upper_ip_que.pop(); const char* packet = _xml_frm_util_ptr->Xml2DataFrame(doc, eEncode_utf8, _protocol_type); delete doc; int pkt_len = _xml_frm_util_ptr->GetMsgLength(); if(!pkt_len){ continue; } QStringList ids = id.split(':'); QString ip = ids.at(0); QString port = ids.at(1); bool ret = _sock_layer_ptr->send_data(ip, port.toUShort(), packet, pkt_len); delete[] packet; QString tips = ret ? "successfully" : "failed"; QString info = QString("network_layer: snd_lower_thread, snd data %1, len: %2").arg(tips).arg(pkt_len); qInfo(info.toStdString().c_str()); emit progress_log_signal(info); } }
Row::Row(QString line, int number, const FORMAT &format, const TYPE &type) : type(type) { this->number = number; bool ok = false; switch (format) { case Row::binary : this->opcode = line.toUShort(&ok, 2); break; case Row::hexa : this->opcode = line.toUShort(&ok, 16); break; case Row::mnemonic : this->opcode = convertMnemonic(line); break; } }
ushort FromString<unsigned short>(const QString& str){ bool ok = false; ushort res = str.toUShort(&ok); if (!ok) { throw UException("Cast error"); } return res; }
// Channel text conversion helpers. unsigned short qtractorMidiControlForm::channelFromText ( const QString& sText ) const { if (sText == "*" || sText.isEmpty()) return qtractorMidiControl::TrackParam; else return sText.toUShort() - 1; }
void runClient(QCoreApplication& app, const QString& portOrPath) { using namespace qhttp::client; QUrl url; if ( portOrPath.toUShort() > 0 ) { url.setScheme("http"); url.setHost("localhost"); url.setPort(portOrPath.toUShort()); } else { url = QUrl::fromLocalFile(portOrPath); } QHttpClient client(&app); bool success = client.request(qhttp::EHTTP_GET, url, [](QHttpResponse* res) { // response handler, called when the HTTP headers of the response are ready res->collectData(128); // called when all data in HTTP response have been read. res->onEnd([res]() { // print the XML body of the response puts("\n[incoming response:]"); puts(res->collectedData().constData()); puts("\n\n"); QCoreApplication::instance()->quit(); }); // just for fun! print headers: puts("\n[Headers:]"); const qhttp::THeaderHash& hs = res->headers(); for ( auto cit = hs.constBegin(); cit != hs.constEnd(); cit++) { printf("%s : %s\n", cit.key().constData(), cit.value().constData()); } fflush(stdout); }); if ( !success ) { fprintf(stderr, "can not send a request to %s\n", qPrintable(url.toString())); return; } app.exec(); }
QString Row::showAsHexa() { // Convert to binary and cut into address and command QString s = showAsBin(); QString command = s.left(4); QString address = s.right(12); // Convert command and address into hexadecimals // and combine them into one string bool ok = false; QString res = QString::number(address.toUShort(&ok,2), 16); while(res.length() < 3) { res.insert(0, "0"); } res.insert(0, QString::number(command.toUShort(&ok, 2), 16)); return res; }
// abstract cDefinable void cCorpse::processNode( const cElement* Tag ) { QString TagName = Tag->name(); QString Value = Tag->value(); if ( TagName == "bodyid" ) bodyId_ = Value.toUShort(); else cItem::processNode( Tag ); }
void Utility::setApplicationProxy(int type, QString location, QString port, QString username, QString password) { QNetworkProxy proxy; proxy.setType((QNetworkProxy::ProxyType)type); proxy.setHostName(location); proxy.setPort(port.toUShort ()); proxy.setUser (username); proxy.setPassword (password); QNetworkProxy::setApplicationProxy(proxy); }
void Widget::toUShortFunction() { //! [80] QString str = "FF"; bool ok; ushort hex = str.toUShort(&ok, 16); // hex == 255, ok == true ushort dec = str.toUShort(&ok, 10); // dec == 0, ok == false //! [80] }
void RegSettingsDlg::getPort(QString port) { bool ok = false; mPort = port.toUShort(&ok); if (!ok) mPort = 0xFFFF; setBtnOkEnabled(); }
void QAssistantClient::readPort() { QString p = proc->readLineStdout(); Q_UINT16 port = p.toUShort(); if ( port == 0 ) { emit error( tr( "Cannot connect to Qt Assistant." ) ); return; } socket->connectToHost( host, port ); disconnect( proc, SIGNAL( readyReadStdout() ), this, SLOT( readPort() ) ); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QCoreApplication::setApplicationName("HttpServer"); QCoreApplication::setApplicationVersion(QT_VERSION_STR); QCommandLineParser commandLineParser; commandLineParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); commandLineParser.setApplicationDescription(QStringLiteral("HTTP Test server")); commandLineParser.addHelpOption(); commandLineParser.addVersionOption(); QCommandLineOption portOption(QStringLiteral("p"), QStringLiteral("Port (default: ") + QString::number(defaultPort) + QLatin1Char(')'), QStringLiteral("port")); commandLineParser.addOption(portOption); commandLineParser.addPositionalArgument(QStringLiteral("[directory]"), QStringLiteral("Directory to serve.")); commandLineParser.process(a); const QStringList args = commandLineParser.positionalArguments(); if (args.size() != 1) commandLineParser.showHelp(1); const QString directory = QDir::cleanPath(args.front()); if (!QFileInfo(directory).isDir()) { std::wcerr << '"' << QDir::toNativeSeparators(directory) << "\" is not a directory.\n"; return -1; } unsigned short port = defaultPort; if (commandLineParser.isSet(portOption)) { const QString portV = commandLineParser.value(portOption); bool ok; port = portV.toUShort(&ok); if (!ok) { std::wcerr << portV << " is not a valid port number.\n"; return -1; } } std::wcout << "Serving \"" << QDir::toNativeSeparators(directory) << "\":\n\n" << QDir(directory).entryList(QDir::Files).join(QLatin1Char('\n')) << "\n\non http://localhost:" << port << '\n'; TestHTTPServer server(port); server.serveDirectory(directory); return a.exec(); }
bool QmlProfilerApplication::parseArguments() { for (int argPos = 1; argPos < arguments().size(); ++argPos) { const QString arg = arguments().at(argPos); if (arg == QLatin1String("-attach") || arg == QLatin1String("-a")) { if (argPos + 1 == arguments().size()) { return false; } m_hostName = arguments().at(++argPos); m_runMode = AttachMode; } else if (arg == QLatin1String("-port") || arg == QLatin1String("-p")) { if (argPos + 1 == arguments().size()) { return false; } const QString portStr = arguments().at(++argPos); bool isNumber; m_port = portStr.toUShort(&isNumber); if (!isNumber) { logError(QString("'%1' is not a valid port").arg(portStr)); return false; } } else if (arg == QLatin1String("-fromStart")) { m_qmlProfilerClient.setRecording(true); m_v8profilerClient.setRecording(true); } else if (arg == QLatin1String("-help") || arg == QLatin1String("-h") || arg == QLatin1String("/h") || arg == QLatin1String("/?")) { return false; } else if (arg == QLatin1String("-verbose") || arg == QLatin1String("-v")) { m_verbose = true; } else if (arg == QLatin1String("-version")) { print(QString("QML Profiler based on Qt %1.").arg(qVersion())); ::exit(1); return false; } else { if (m_programPath.isEmpty()) { m_programPath = arg; m_tracePrefix = QFileInfo(m_programPath).fileName(); } else { m_programArguments << arg; } } } if (m_runMode == LaunchMode && m_programPath.isEmpty()) return false; if (m_runMode == AttachMode && !m_programPath.isEmpty()) return false; return true; }
//Wavelength information is given in a hex string which represents an array of ushort values. This function //converts a certain index to a ushort value. Each element is also backwards so it needs to be flipped. ushort Laser::getIndex16(QString inString, int index){ QStringList indexList = inString.split(" "); QString outString; if(index <= ((indexList.length()-1)*2)){ outString = indexList[(index*2) + 1] + indexList[(index*2)]; outString.replace("h", ""); }else{ outString = "FFFF"; //Error catch. } bool ok; ushort outInt = outString.toUShort(&ok, 16); return outInt; }
bool CRQParamHandler::startElement( const QString&, const QString&, const QString& qName, const QXmlAttributes& attr) { /* process begin tag */ const QString &tag = qName; if( tag == "Viewer" ) { if((paramObject = new CRMainParameters()) == NULL ) { cerr << "Erro a criar o objecto parameters\n"; return false; } // process attributes const QString host = attr.value( QString( "Host" )); if ( !host.isNull() ) paramObject->serverAddr = host; const QString port = attr.value( QString( "Port" )); if ( !port.isNull() ) paramObject->port = port.toUShort(); const QString lowerColor = attr.value ( QString( "Lowercolor" )); if ( !lowerColor.isNull() ) paramObject->lowerColor = lowerColor; const QString higherColor = attr.value( QString( "Highercolor" )); if ( !higherColor.isNull() ) paramObject->higherColor = higherColor; const QString control = attr.value( QString( "Control" )); if ( !control.isNull() ) paramObject->control = control[0].toAscii(); const QString autoC = attr.value( QString( "AutoConnect" )); if ( !autoC.isNull() ) paramObject->autoConnect = autoC[0].toAscii(); const QString autoS = attr.value( QString( "AutoStart" )); if ( !autoS.isNull() ) paramObject->autoStart = autoS[0].toAscii(); return true; } else return false; }
void InterestsInfo::fill() { ICQUserData *data = m_data; if (data == NULL) data = &m_client->data.owner; unsigned i = 0; QString str = data->Interests.str(); while (str.length()){ QString info = getToken(str, ';', false); QString n = getToken(info, ','); unsigned short category = n.toUShort(); switch (i){ case 0: edtBg1->setText(unquoteChars(info,";")); initCombo(cmbBg1, category, interests); break; case 1: edtBg2->setText(unquoteChars(info,";")); initCombo(cmbBg2, category, interests); break; case 2: edtBg3->setText(unquoteChars(info,";")); initCombo(cmbBg3, category, interests); break; case 3: edtBg4->setText(unquoteChars(info,";")); initCombo(cmbBg4, category, interests); break; } i++; } for (; i < 4; i++){ switch (i){ case 0: initCombo(cmbBg1, 0, interests); break; case 1: initCombo(cmbBg2, 0, interests); break; case 2: initCombo(cmbBg3, 0, interests); break; case 3: initCombo(cmbBg4, 0, interests); break; } } if (m_data == NULL) cmbChanged(0); }
void NetworkHandler::setUdpPort(const QString &port) { bool ok = false; udpPort_ = port.toUShort(&ok,10); if(ok) { QSettings settings("rgbled","rgbled"); settings.setValue("udp_port",udpPort_); qDebug() << "UDP port ok: " << udpPort_; } else { qDebug() << "UDP port not ok: " << udpPort_; } }
/* If the last 4 characters of s form a hex digit replaces them with the unicode character they describe. */ static void compose( QString &s ) { if ( s.length() < 4 ) return; QString hex = s.right(4); for ( int i=0; i < 4; i++ ) { if ( hex[i].isSpace() ) return; } bool ok; unsigned short int unicode = hex.toUShort( &ok, 16 ); if ( ok && unicode >= ' ' && unicode < 0xffff ) { s.truncate( s.length() - 4 ); s += QChar( unicode ); } }
bool QLandmarkFileHandlerLmx::readCategory(QString &name) { /* <xsd:complexType name="categoryType"> <xsd:sequence> <xsd:element name="id" type="xsd:unsignedShort" minOccurs="0" /> <xsd:element name="name" type="xsd:string" /> </xsd:sequence> </xsd:complexType> */ Q_ASSERT(m_reader->isStartElement() && (m_reader->name() == "category")); if (!m_reader->readNextStartElement()) { m_reader->raiseError("The element \"category\" did not have the required child element \"name\"."); return false; } QString idString; if (m_reader->name() == "id") { bool ok = false; idString = m_reader->readElementText(); (void)idString.toUShort(&ok); if (!ok) { m_reader->raiseError(QString("The element \"id\" expected a value convertable to type unsigned short (value was \"%1\").").arg(idString)); return false; } if (!m_reader->readNextStartElement()) { m_reader->raiseError("The element \"category\" did not have the required child element \"name\"."); return false; } } if (m_reader->name() == "name") { name = m_reader->readElementText(); if (!m_reader->readNextStartElement()) { return true; } } m_reader->raiseError(QString("The element \"category\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString())); return false; }