Response parseResponse(char const* str) { // Parse an HTTP response auto version = parseToken(str); auto code = parseStatus(version.ch); auto message = parseUntil(code.ch, [](char ch) { return ch == '\r'; }); auto response = Response(); if (version.value != "HTTP/1.1") { throw Error("bad HTTP version"); } auto ch = parseCrLf(message.ch).ch; while (*ch != '\0' && *ch != '\r') { auto name = parseUntil(ch, [](char ch) { return ch == ':'; }); if (*name.ch) { name.ch++; // For ":" } auto ws = parseWhile(name.ch, isspace); auto value = parseUntil(ws.ch, [](char ch) { return ch == '\r'; }); response.headerIs(name.value, value.value); if (name.value == "Set-Cookie") { response.cookieIs(Cookie(value.value)); } ch = parseCrLf(value.ch).ch; } ch = parseCrLf(ch).ch; response.statusIs(code.value); response.dataIs(ch); return response; }
Bott::Bott(string filename) { string name, value; infos.clear(); fin.open(filename.c_str(), fstream::in); while (fin >> name) { if (name == SOURCE_CODE_BEGIN) src = parseUntil(SOURCE_CODE_END); else if (name == COMPILE_INFO_BEGIN) ce_info = parseUntil(COMPILE_INFO_END); else if (name == DATA_DETAIL_BEGIN) data_detail = parseUntil(DATA_DETAIL_END); else if (name == CHALLENGE_DETAIL_BEGIN) cha_detail = parseUntil(CHALLENGE_DETAIL_END); else { getline(fin, value); infos[name] = value; } } fin.close(); if (infos.count("<type>")) type = stringToInt(infos["<type>"]); if (infos.count("<runid>")) runid = trim(infos["<runid>"]); if (infos.count("<cha_id>")) cha_id = trim(infos["<cha_id>"]); if (infos.count("<language>")) language = trim(infos["<language>"]); if (infos.count("<pid>")) pid = trim(infos["<pid>"]); if (infos.count("<testcases>")) number_of_testcases = trim(infos["<testcases>"]); if (infos.count("<time_limit>")) time_limit = trim(infos["<time_limit>"]); if (infos.count("<case_limit>")) case_limit = trim(infos["<case_limit>"]); if (infos.count("<memory_limit>")) memory_limit = trim(infos["<memory_limit>"]); if (infos.count("<special>")) spj = trim(infos["<special>"]); if (infos.count("<vname>")) vname = trim(infos["<vname>"]); if (infos.count("<vid>")) vid = trim(infos["<vid>"]); if (infos.count("<memory_used>")) memory_used = trim(infos["<memory_used>"]); if (infos.count("<time_used>")) time_used = trim(infos["<time_used>"]); if (infos.count("<result>")) result = trim(infos["<result>"]); if (infos.count("<data_type>")) data_type = trim(infos["<data_type>"]); if (infos.count("<data_lang>")) data_lang = trim(infos["<data_lang>"]); if (infos.count("<challenge_result>")) cha_result = trim(infos["<challenge_result>"]); }
PgnStream::TokenType PgnStream::readNext() { if (m_phase == OutOfGame) return NoToken; m_tokenType = NoToken; m_tokenString.clear(); char c; while ((c = readChar()) != 0) { switch (c) { case ' ': case '\t': case '\n': case '\r': case '.': break; case '%': // Escape mechanism (skip this line) parseUntil("\n\r"); m_tokenString.clear(); break; case '[': if (m_phase != InTags) { rewindChar(); m_phase = OutOfGame; return NoToken; } m_tokenType = PgnTag; parseTag(); return m_tokenType; case '(': case '{': m_tokenType = PgnComment; parseComment(c); return m_tokenType; case ';': m_tokenType = PgnLineComment; parseUntil("\n\r"); return m_tokenType; case '$': // NAG (Numeric Annotation Glyph) m_tokenType = PgnNag; parseUntil(" \t\n\r"); return m_tokenType; case '*': // Unfinished game m_tokenType = PgnResult; m_tokenString = "*"; m_phase = OutOfGame; return m_tokenType; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': // Move number or result m_tokenString.append(c); parseUntil(". \t\n\r"); if (m_tokenString == "1-0" || m_tokenString == "0-1" || m_tokenString == "1/2-1/2") { m_tokenType = PgnResult; m_phase = OutOfGame; } else { if (m_tokenString.endsWith('.')) m_tokenString.chop(1); m_tokenType = PgnMoveNumber; m_phase = InGame; } return m_tokenType; default: m_tokenType = PgnMove; m_tokenString.append(c); parseUntil(" \t\n\r"); m_phase = InGame; return m_tokenType; } } return NoToken; }