Variable* XDVariableParser::parseVar(QDomNode& node, Variable* parent, bool fullname) { QDomElement e = node.toElement(); PHPVariable* var = new PHPVariable(parent); int children = e.attributeNode("numchildren").value().toInt(); QString type = e.attributeNode("type").value(); QString fname = fullname?"fullname":"name"; var->setName(e.attributeNode(fname).value()); if(type == "object") { PHPObjectValue* objValue = new PHPObjectValue(var); var->setValue(objValue); objValue->setScalar(false); objValue->setClassType(e.attributeNode("classname").value()); objValue->setList(parseList(e.childNodes(), var)); } else if(children) { PHPArrayValue* arrayValue = new PHPArrayValue(var, children); var->setValue(arrayValue); arrayValue->setScalar(false); if (e.childNodes().count() > 0) { arrayValue->setList(parseList(e.childNodes(), var, false)); } } else { PHPScalarValue* value = new PHPScalarValue(var); var->setValue(value); if(type == "null") { value->setType(PHPScalarValue::Undefined); value->set("null"); } else if(type == "int") { value->setType(PHPScalarValue::Integer); value->set(e.text()); } else if(type == "string") { value->setType(PHPScalarValue::String); value->set(QString("\"") + QString(KCodecs::base64Decode (e.text().utf8())) + QString("\"")); } else if(type == "float") { value->setType(PHPScalarValue::Double); value->set(e.text()); } } return var; }
/// Parses current character transforms (x,y,dx,dy,rotate) void ArtisticTextLoadingContext::parseCharacterTransforms(const KoXmlElement &element, SvgGraphicsContext *gc) { m_currentAbsolutePosX = parseList(element.attribute("x"), gc, XLength); m_currentAbsolutePosY = parseList(element.attribute("y"), gc, YLength); m_currentRelativePosX = parseList(element.attribute("dx"), gc, XLength); m_currentRelativePosY = parseList(element.attribute("dy"), gc, YLength); m_currentRotations = parseList(element.attribute("rotate"), gc, Number); if (m_textPosition.x() == HUGE_VAL && m_currentAbsolutePosX.data.count()) { m_textPosition.setX(m_currentAbsolutePosX.data.first()); } if (m_textPosition.y() == HUGE_VAL && m_currentAbsolutePosY.data.count()) { m_textPosition.setY(m_currentAbsolutePosY.data.first()); } }
lcpp::Ptr<lcpp::LispObject> lcpp::Reader::read(ezStringIterator& input, bool resetSyntaxChecker) { if(resetSyntaxChecker) { m_pSyntaxCheckResult->reset(); } skipSeparators(input); if(!input.IsValid()) { return LCPP_VOID; } switch(input.GetCharacter()) { case ')': throw exceptions::InvalidInput("Unexpected character ')'."); case '\'': // TODO read quote throw exceptions::NotImplemented("Not supporting quote yet."); break; case '"': return parseString(input); break; case '(': return parseList(input); break; } return parseAtom(input); }
Sexp* parse() { Sexp* ret; int t = yylex(); if(t == TOKEN) { ret = new Sexp; ret->val = copyString(yytext); ret->next = NULL; ret->list = NULL; } else if(t == STRING) { ret = new Sexp; ret->val = unescapeString(yytext); ret->next = NULL; ret->list = NULL; } else if(t == LPAREN) { ret = parseList(); } else { ret = NULL; } return ret; }
void SlideShare::listDocuments() { qDebug() << ">>>>>>>>> SlideShare::listDocuments()"; QDateTime *time = new QDateTime(QDateTime::currentDateTime()); QString ts; ts.setNum(time->toTime_t()); QByteArray data = this->secretKey->toAscii(); data += ts; QList<QPair<QString, QString> > params; params.append(qMakePair(QString("api_key"), *this->apiKey)); params.append(qMakePair(QString("ts"), ts)); params.append(qMakePair(QString("hash"), QString(QCryptographicHash::hash(data, QCryptographicHash::Sha1).toHex()))); params.append(qMakePair(QString("username"), *this->username)); params.append(qMakePair(QString("password"), *this->password)); params.append(qMakePair(QString("username_for"), *this->username)); QUrl url("http://www.slideshare.net/api/2/get_slideshows_by_user"); url.setQueryItems(params); QNetworkRequest request; request.setUrl(url); reply = manager.get(request); connect(reply, SIGNAL(finished()), this, SLOT(parseList())); }
void RequestParameters::parseUrl(const QUrl & url) { if (!url.hasQuery()) { return; } QList<QPair<QString, QVariant >> parameters; for (const QString & parameter : url.query().split('&')) { int splitIndex = parameter.indexOf('='); if (splitIndex<=0) { continue; } QString key = parameter.left(splitIndex); QString value = parameter.mid(splitIndex + 1); parameters << QPair<QString, QVariant>(key, value); } parseList(parameters); }
void RequestParameters::parseMultiPart(const MultiPart & multiPart) { QList<QPair<QString, QVariant >> parameters; for (const Part & part : multiPart.getParts()) { HttpHeader contentDisposition = part.getHeader(http::ContentDisposition); HttpHeaderElement element = contentDisposition.getElement(); if (element.getName()=="form-data") { QString name = element.getParameter("name"); if (part.hasHeader(http::ContentType)) { UploadedFile uploadedFile; uploadedFile.setContent(part.getContent()); if (element.isSet("filename")) { uploadedFile.setFilename(element.getParameter("filename")); } parameters << QPair<QString, QVariant>(name, uploadedFile.toQVariant()); } else { parameters << QPair<QString, QVariant>(name, QString(part.getContent())); } } } parseList(parameters); }
void GmlParser::createObjectTree(istream &is, bool doCheck) { initPredefinedKeys(); m_error = false; m_objectTree = 0; m_is = &is; m_doCheck = doCheck; // indicates more extensive checking // initialize line buffer (note: GML specifies a maximal line length // of 254 characters!) m_rLineBuffer = new char[256]; if (m_rLineBuffer == 0) OGDF_THROW(InsufficientMemoryException); *m_rLineBuffer = '\n'; m_lineBuffer = m_rLineBuffer+1; m_pCurrent = m_pStore = m_lineBuffer; m_cStore = 0; // forces getNextSymbol() to read first line // create object tree m_objectTree = parseList(gmlEOF,gmlListEnd); delete[] m_rLineBuffer; }
void Packed::poll(bool can_read) { if (!can_read) return; m_socket.peek(); std::streamsize count; while ((count = m_socket.rdbuf()->in_avail()) > 0) { for (int i = 0; i < count; ++i) { int next = m_socket.rdbuf()->sbumpc(); switch (m_state.top()) { case PARSE_STREAM: parseStream(next); break; case PARSE_MAP: parseMap(next); break; case PARSE_LIST: parseList(next); break; case PARSE_MAP_BEGIN: parseMapBegin(next); break; case PARSE_LIST_BEGIN: parseListBegin(next); break; case PARSE_INT: parseInt(next); break; case PARSE_FLOAT: parseFloat(next); break; case PARSE_STRING: parseString(next); break; case PARSE_NAME: parseName(next); break; } } } }
QVariantList parseLispFile(QString filePath) { QFile f(filePath); if (!f.open(QFile::ReadOnly)) { qCritical("Can't open file %s", qPrintable(filePath)); return QVariantList(); } QByteArray data = f.readAll(); f.close(); ParserState st; st.ptr = data.data(); st.end = st.ptr + data.size(); try { return parseList(st); } catch (ParserError &e) { qCritical("Parser: %s", qPrintable(e)); return QVariantList(); } }
//----------------------------------------------------------------------------- size_t* getNewSize(const char* suffix, const char* kernelName, size_t dimensions) { unsigned int suffixLength = strlen(suffix); // Read the environment variable: kernelName_suffix. size_t kernelNameSize = strlen(kernelName); size_t envVarSize = kernelNameSize + suffixLength; char varName[envVarSize]; memset(varName, 0, envVarSize); strncpy(varName, kernelName, kernelNameSize); strncat(varName, suffix, suffixLength); char* envVarValue = getEnvString(varName); if(envVarValue == NULL) { free(envVarValue); return NULL; } size_t* newSize = (size_t*) malloc(dimensions * sizeof(size_t)); memset(newSize, 0, dimensions * sizeof(size_t)); if(dimensions == 1) newSize[0] = (size_t) atoi(envVarValue); else if(dimensions == 2) parseList(envVarValue, newSize, newSize + 1); free(envVarValue); return newSize; }
PyObject* VRPyFactory::setupLod(VRPyFactory* self, PyObject* args) { if (self->obj == 0) { PyErr_SetString(err, "VRPyFactory::setupLod - Object is invalid"); return NULL; } vector<PyObject*> vec = parseList(args); vector<string> svec; for (auto o : vec) svec.push_back( PyString_AsString(o) ); return VRPyTypeCaster::cast( self->obj->setupLod( svec ) ); }
int parseCommand(token *tok, char **s) { int line; int r; if (matchNumber(tok, s)) { line = tok->n; if (!matchWhiteSpace(tok, s)) // delete line return deleteLine(line); else // add line { matchString(tok, s); return insertLine(line, tok->s); } } if (matchSize(tok, s)) { puts(itos(programGetSize())); return 1; } if (matchFree(tok, s)) { puts(itos(programGetFree())); return 1; } if (matchClear(tok, s)) { programInit(); return 1; } if (matchBye(tok, s)) { exit(0); } if (parseRun(tok, s)) return 1; else if (errorGet() != ERROR_OK) return 0; if (parseList(tok, s)) return 1; else if (errorGet() != ERROR_OK) return 0; programSetMode(progModeImmediate); r = parseLine(tok, s); programSetMode(progModeStored); return r; }
std::set<std::string> IdSliceParser::parseSet(const std::string& aStringSlice) { std::vector<std::string> lIdList = parseList(aStringSlice); std::set<std::string> lIdSet(lIdList.begin(), lIdList.end()); if ( lIdList.size() != lIdSet.size()) { throw SliceSetParsingDuplicatesFound(); } return lIdSet; }
void mergeLists(PathName& list, const PathName& serverList, const PathName& clientList) { ParsedList onClient, onServer, merged; parseList(onClient, clientList); parseList(onServer, serverList); // do not expect too long lists, therefore use double loop for (unsigned c = 0; c < onClient.getCount(); ++c) { for (unsigned s = 0; s < onServer.getCount(); ++s) { if (onClient[c] == onServer[s]) { merged.push(onClient[c]); break; } } } makeList(list, merged); }
Sexp* parseList() { Sexp* ret = new Sexp; ret->val = NULL; ret->list = NULL; ret->next = NULL; Sexp* last = NULL; Sexp* next = NULL; int t = yylex(); while(true) { if(t == RPAREN || t == END) { return ret; } if(t == TOKEN) { next = new Sexp; next->val = copyString(yytext); next->next = NULL; next->list = NULL; } if(t == STRING) { next = new Sexp; next->val = unescapeString(yytext); next->next = NULL; next->list = NULL; } if(t == LPAREN) { next = parseList(); } if(!last) { ret->list = next; } else { last->next = next; } last = next; t = yylex(); } }
ExpPtr parseTermPrefix (Lexer& lex) { Token tok = lex.current(); switch (tok.tok) { case tNumberInt: tok = lex.advance(); return Exp::make(eInt, tok.valueInt, {}, tok.span); case tNumberReal: tok = lex.advance(); return Exp::make(eReal, tok.valueReal, {}, tok.span); case tString: tok = lex.advance(); return Exp::make(eString, tok.str, {}, tok.span); case tTrue: case tFalse: tok = lex.advance(); return Exp::make(eBool, tok == tTrue, {}, tok.span); case tIdent: tok = lex.advance(); return Exp::make(eVar, tok.str, bool(true), {}, tok.span); case tLParen: return parseTuple(lex); case tIf: return parseCond(lex); case tLCurl: return parseBlock(lex); case tLBrack: return parseList(lex); case tFunc: case tLambda: return parseLambda(lex); case tiMake: return parseiMake(lex); case tiGet: return parseiGet(lex); case tiPut: return parseiPut(lex); case tiCall: return parseiCall(lex); default: //lex.expect("term"); lex.unexpect(); return nullptr; } }
CommandBase* ParserList::tryParse(string userCommand) { string instruction; string arguments; if (!getInstructionAndArguments(userCommand, instruction, arguments)) { return NULL; } if (!checkInstruction(instruction)) { return NULL; } return parseList(arguments); }
SExpression* parse(TokenStream& Tokens) { if (!Tokens.hasNext()) { return NULL; } IToken* Token = Tokens.next(); if (dynamic_cast<OpenParen*>(Token)) { return parseList(Tokens); } else if (dynamic_cast<Symbol*>(Token)) { return parseSymbol(dynamic_cast<Symbol*>(Token)); } else if (dynamic_cast<CloseParen*>(Token)) { throw invalid_syntax(); } else if (dynamic_cast<String*>(Token)) { return parseString(dynamic_cast<String*>(Token)); } else { return NULL; } }
JLDDoc* JLDIO::parseDoc(std::istringstream& iss) { ignoreWhiteSpace(iss); char charBuffer; iss.get(charBuffer); assert(charBuffer == '{' && "Input is not a doc"); JLDDoc* out = new JLDDoc(); // empty list ignoreWhiteSpace(iss); if(iss.peek() == '}') { iss.get(charBuffer); return out; } do { auto keyObj = parseString(iss); std::string key = keyObj->getValue(); delete keyObj; ignoreWhiteSpace(iss); assert(iss.peek() == ':' && ": expected after a keyword"); iss.get(charBuffer); ignoreWhiteSpace(iss); JLDData* valueObj; switch (iss.peek()) { case '{': valueObj = parseDoc(iss); break; case '[': valueObj = parseList(iss); break; case '\'': case '\"': valueObj = parseString(iss); break; default: assert(0 && "Unexpected value"); break; } out->push_back(key, valueObj); } while(moreItems(iss, '}')); iss.get(charBuffer); return out; }
void GdbMi::parseValue(const char *&from, const char *to) { //qDebug() << "parseValue: " << QByteArray(from, to - from); switch (*from) { case '{': parseTuple(from, to); break; case '[': parseList(from, to); break; case '"': m_type = Const; m_data = parseCString(from, to); break; default: break; } }
QVariantList parseList(ParserState &st) { skipSpaces(st); checkEndOfFile(st); if (*st.ptr != '(') { throw ParserError("list must be started with '('"); } st.ptr++; QVariantList list; QString i = parseIdentifier(st); list.append(i); while (st.ptr < st.end) { if (*st.ptr == ')') { st.ptr++; return list; } parseSpace(st); if (*st.ptr == ')') { st.ptr++; return list; } if (*st.ptr == '(') { QVariant v = parseList(st); list.append(v); } else { list.append(parseAtom(st)); } } throw ParserError("unexpected end of file"); }
void CommandHandler::parse(int argc, char** argv) { if (argc == 0) { UIManager ui; ui.setController(_gameController); ui.start(); return; } std::string command(*argv); if (command == "add") parseAdd(argc, argv); if (command == "remove" || command == "rm") parseRemove(argc, argv); if (command == "list" || command == "ls") parseList(argc, argv); if (command == "lsp") parseListPlatform(argc, argv); if (command == "lsc") parseListCategory(argc, argv); if (command == "run") parseRun(argc, argv); }
/** * shell function */ int shell() { debug("shell init"); checkLogin(); char input[MAXLENGTH]; for (;;) { printf("%s>", getUser()); read_line(input); if (sequals(input, "exit")) { debug("shut down"); shellExit(); } else if (begins(input, "set ")) { debug("exec set cmd"); parseSet(input + 4); } else if (begins(input, "list ")) { debug("exec list cmd"); parseList(input + 5); } else if (begins(input, "search ")) { debug("exec find cmd from search"); find(input + 7); } else if (begins(input, "find ")) { debug("exec find cmd"); find(input + 5); } else if (begins(input, "buy ")) { debug("exec buy cmd"); buy(input + 4); } else if (begins(input, "help")) { debug("exec help cmd"); printInternHelp(); } else if (begins(input, "balance")) { debug("exec balance cmd"); balanceUser(); } else { debug("no match found in shell"); printf("Don't know what you mean...\n"); } } return 0; }
void fuckingtest(){ int TEST_TIMES = 100000; srand(time(0)); for(int i=0; i<TEST_TIMES; i++){ int a = rand() % 100000000, b = rand() % 100000000; //a = 1, b = 99999; int sum = a + b; ListNode* l1 = createList(a); ListNode* l2 = createList(b); //printList(l1); //printList(l2); //printList(addList(l1, l2)); ListNode* res = addTwoNumbers(l1, l2); int sum2 = parseList(res); if(sum != sum2){ printf("F**K!%d a=%d, b=%d, sum1 = %d, sum2 = %d ", i, a, b,sum, sum2); break; } } printf("F*****G OK!!!"); }
void parseList( POETParseList* op, POETCode* elemType, POETCode* sep) { if (r1 == 0 || r1 == EMPTY) { res = EMPTY; return; } POETCode* r1_head = get_head(r1); if (get_head(r1)->get_enum()==SRC_STRING && !backtrack && !op->match_lookahead(this, r1)) { res = EMPTY; return; } POETCode* r1save = r1; apply(elemType, EMPTY); if (r1save == r1 && res == EMPTY) return; if (r1 == 0 || r1 == EMPTY) { if (res->get_enum() == SRC_LIST) res = fac->new_list(res, 0); return; } POETCode* firstResult = res; if (sep != EMPTY) { if (sep == get_head(r1)) { r1 = NextToken(r1); } else { res = firstResult; if (res->get_enum() == SRC_LIST) res = fac->new_list(res, 0); return; } } POETCode* _r1 = r1; try { parseList(op, elemType, sep); } catch (ParseError err) { if (!backtrack || sep!=EMPTY || fullmatch==0) throw err; else { r1 = _r1; res = firstResult; if (res->get_enum() == SRC_LIST) res = fac->new_list(res, 0); return; } } if (res != 0 && res!=EMPTY && res->get_enum() != SRC_LIST) res = fac->new_list(res, 0); if (firstResult != EMPTY) { if (res == EMPTY) res = 0; res = fac->new_list(firstResult, res); } }
JLDList* JLDIO::parseList(std::istringstream& iss) { ignoreWhiteSpace(iss); char charBuffer; iss.get(charBuffer); assert(charBuffer == '[' && "Input is not a list"); JLDList* out = new JLDList(); // empty list ignoreWhiteSpace(iss); if(iss.peek() == ']') { iss.get(charBuffer); return out; } do { ignoreWhiteSpace(iss); JLDData* valueObj; switch (iss.peek()) { case '{': valueObj = parseDoc(iss); break; case '[': valueObj = parseList(iss); break; case '\'': case '\"': valueObj = parseString(iss); break; default: assert(0 && "Unexpected value"); break; } out->push_back(valueObj); } while(moreItems(iss, ']')); iss.get(charBuffer); return out; }
static bool parseComma(ParseTreeNode* parentNode) { // Store current state for rolling back if we fail int curToken = said_token; int curTreePos = said_tree_pos; ParseTreeNode* curRightChild = parentNode->right; if (said_tokens[said_token] == TOKEN_COMMA) { said_token++; bool found = parseList(parentNode); if (found) return true; } // Rollback said_token = curToken; said_tree_pos = curTreePos; parentNode->right = curRightChild; return false; }
void Bencoder::parseNextType(const std::string& str, unsigned int& pos, ListPtr list) { m_logger->log(logger::Logger::FINE, "Bencoder::parseNextType()"); switch (str[pos]) { case 'd': break; case 'l': { ListPtr l = parseList(str, pos); //m_lists.push_back( reinterpret_cast<AnyType>(l) ); break; } case 'i': { list->push_back( parseInteger(str, pos) ); break; } default: list->push_back( parseString(str, pos) ); break; } }
static bool parseExpr(ParseTreeNode* parentNode) { // Store current state for rolling back if we fail int curToken = said_token; int curTreePos = said_tree_pos; ParseTreeNode* curRightChild = parentNode->right; ParseTreeNode* newNode = said_branch_node(said_next_node(), 0, 0); bool ret = false; bool found; ParseTreeNode* newParent = parentNode; found = parseList(newNode); if (found) { ret = true; said_attach_subtree(newParent, 0x141, 0x14F, newNode); newParent = newParent->right; } found = parseRef(newParent); if (found || ret) return true; // Rollback said_token = curToken; said_tree_pos = curTreePos; parentNode->right = curRightChild; return false; }