QPair<QString, QString> ErbParser::parseEndPercentTag() { QString string; QString defaultVal; bool defaultFlag = false; while (pos < erbData.length()) { if (posMatchWith("%>")) { pos += 2; QChar c = erbData[pos - 3]; if (c == QLatin1Char('-') || c == QLatin1Char('+')) { // -%> or +%> if (defaultFlag) { defaultVal.chop(1); } else { string.chop(1); } if (c == QLatin1Char('-')) skipWhiteSpacesAndNewLineCode(); } else if (trimMode == StrongTrim) { // StrongTrim:2 skipWhiteSpacesAndNewLineCode(); } else if (trimMode == NormalTrim) { // NormalTrim:1 if (startTag == QLatin1String("<%") || startTag.startsWith("<%#")) { skipWhiteSpacesAndNewLineCode(); } } else if (trimMode == TrimOff) { // TrimOff:0 // do not skip whitespaces } else { qCritical("Invalid arguments: trim mode: %d", trimMode); } break; } if (posMatchWith("%|%")) { defaultFlag = true; pos += 3; } QChar c = erbData[pos]; if (c == QLatin1Char('\'') || c == QLatin1Char('"')) { if (defaultFlag) { defaultVal += parseQuote(); } else { string += parseQuote(); } } else { if (defaultFlag) { defaultVal += c; } else { string += c; } ++pos; } } return qMakePair(string, defaultVal); }
bool qdbbot::refreshCache() { std::cout << "qdbbot: refreshing cache" << std::endl; bashBuffer* buffer = webget(baseURL + "/random"); //dump html doc into string std::string stuff(buffer->begin(), buffer->end()); //dump string into string stream; std::stringstream html(stuff); // std::cout << "this is teh massive html: " << html.str(); delete buffer; std::cout << "qdbbot: parsing quotes" << std::endl; while(!html.eof()) { std::cout << "qdbbot: parsed bash "<< cache->size() << std::endl; cacheMutex->lock(); cache->push_back(parseQuote(&html)); cacheMutex->unlock(); } std::cout << "qdbbot: cache refreshed" << std::endl; std::cout << "qdbbot: cache size now " << cache->size() << std::endl; return true; }
qdbbot::bashQuote* qdbbot::bashNum(std::string number) { std::cout << "qdbbot: bashnum url: " << baseURL << "/" << number << std::endl; bashBuffer* buffer = webget(baseURL + "/" + number); std::string stuff(buffer->begin(), buffer->end()); //dump string into string stream; std::stringstream html(stuff); std::cout << "qdbbot: bashnum is parsing the quote" << std::endl; qdbbot::bashQuote* quote = parseQuote(&html); delete buffer; return quote; }
void Yahoo::fileDone (bool d) { if (d) { // QString ss(tr("Network error aborting")); // printStatusLogMessage(ss); // printStatusLogMessage(stringDone); // downloadComplete(); // return; } else { if (method->currentText().contains("History")) parseHistory(); else { if (method->currentText().contains("Quote")) parseQuote(); else parseFundamental(); } } currentUrl = url.next(); if (! currentUrl) { downloadComplete(); printStatusLogMessage(stringDone); printErrorList(); progressBar->reset(); return; } errorLoop = 0; startDownload(); }
NFAUNode * WCPattern::parse(const bool inParen, const bool inOr, NFAUNode ** end) { NFAUNode * start, *cur, *next = NULL; CMString t; int grc = groupCount++; bool inv, quo; bool ahead = 0, pos = 0, noncap = 0, indep = 0; unsigned long oldFlags = flags; if (inParen) { if (pattern[curInd] == '?') { ++curInd; --groupCount; if (pattern[curInd] == ':') { noncap = 1; ++curInd; grc = --nonCapGroupCount; } else if (pattern[curInd] == '=') { ++curInd; ahead = 1; pos = 1; } else if (pattern[curInd] == '!') { ++curInd; ahead = 1; pos = 0; } else if (pattern.Mid(curInd, 2) == L"<=") { curInd += 2; return parseBehind(1, end); } else if (pattern.Mid(curInd, 2) == L"<!") { curInd += 2; return parseBehind(0, end); } else if (pattern[curInd] == '>') { ++curInd; indep = 1; } else { bool negate = false, done = false; while (!done) { if (curInd >= pattern.GetLength()) { raiseError(); return NULL; } else if (negate) { switch (pattern[curInd]) { case 'i': flags &= ~WCPattern::CASE_INSENSITIVE; break; case 'd': flags &= ~WCPattern::UNIX_LINE_MODE; break; case 'm': flags &= ~WCPattern::MULTILINE_MATCHING; break; case 's': flags &= ~WCPattern::DOT_MATCHES_ALL; break; case ':': done = true; break; case ')': ++curInd; *end = registerNode(new NFALookBehindUNode(L"", true)); return *end; case '-': default: raiseError(); return NULL; } } else { switch (pattern[curInd]) { case 'i': flags |= WCPattern::CASE_INSENSITIVE; break; case 'd': flags |= WCPattern::UNIX_LINE_MODE; break; case 'm': flags |= WCPattern::MULTILINE_MATCHING; break; case 's': flags |= WCPattern::DOT_MATCHES_ALL; break; case ':': done = true; break; case '-': negate = true; break; case ')': ++curInd; *end = registerNode(new NFALookBehindUNode(L"", true)); return *end; default: raiseError(); return NULL; } } ++curInd; } noncap = 1; grc = --nonCapGroupCount; } if (noncap) cur = start = registerNode(new NFAGroupHeadUNode(grc)); else cur = start = registerNode(new NFASubStartUNode); } else cur = start = registerNode(new NFAGroupHeadUNode(grc)); } else cur = start = registerNode(new NFASubStartUNode); while (curInd < pattern.GetLength()) { wchar_t ch = pattern[curInd++]; next = NULL; if (error) return NULL; switch (ch) { case '^': if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAStartOfLineUNode); else next = registerNode(new NFAStartOfInputUNode); break; case '$': if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAEndOfLineUNode); else next = registerNode(new NFAEndOfInputUNode(0)); break; case '|': --groupCount; cur->next = registerNode(new NFAAcceptUNode); cur = start = registerNode(new NFAOrUNode(start, parse(inParen, 1))); break; case '\\': if (curInd < pattern.GetLength()) { bool eoi = 0; switch (pattern[curInd]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': next = parseBackref(); break; case 'A': ++curInd; next = registerNode(new NFAStartOfInputUNode); break; case 'B': ++curInd; next = registerNode(new NFAWordBoundaryUNode(0)); break; case 'b': ++curInd; next = registerNode(new NFAWordBoundaryUNode(1)); break; case 'G': ++curInd; next = registerNode(new NFAEndOfMatchUNode); break; case 'Z': eoi = 1; case 'z': ++curInd; next = registerNode(new NFAEndOfInputUNode(eoi)); break; default: t = parseEscape(inv, quo); //printf("inv quo classes { %c %c %s }\n", inv ? 't' : 'f', quo ? 't' : 'f', t.c_str()); if (!quo) { if (t.GetLength() > 1 || inv) { if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACIClassUNode(t, inv)); else next = registerNode(new NFAClassUNode(t, inv)); } else next = registerNode(new NFACharUNode(t[0])); } else next = parseQuote(); } } else raiseError(); break; case '[': if ((flags & WCPattern::CASE_INSENSITIVE) == 0) { NFAClassUNode * clazz = new NFAClassUNode(); CMString s = parseClass(); for (int i = 0; i < (int)s.GetLength(); ++i) clazz->vals[s[i]] = 1; next = registerNode(clazz); } else { NFACIClassUNode * clazz = new NFACIClassUNode(); CMString s = parseClass(); for (int i = 0; i < s.GetLength(); ++i) clazz->vals[to_lower(s[i])] = 1; next = registerNode(clazz); } break; case '.': { bool useN = 1, useR = 1; NFAClassUNode * clazz = new NFAClassUNode(1); if ((flags & WCPattern::UNIX_LINE_MODE) != 0) useR = 0; if ((flags & WCPattern::DOT_MATCHES_ALL) != 0) useN = useR = 0; if (useN) clazz->vals['\n'] = 1; if (useR) clazz->vals['\r'] = 1; next = registerNode(clazz); } break; case '(': { NFAUNode *end, *t1, *t2; t1 = parse(1, 0, &end); if (!t1) raiseError(); else if (t1->isGroupHeadNode() && (t2 = quantifyGroup(t1, end, grc)) != NULL) { cur->next = t2; cur = t2->next; } else { cur->next = t1; cur = end; } } break; case ')': if (!inParen) raiseError(); else if (inOr) { --curInd; cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return start; } else { if (ahead) { cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return *end = registerNode(new NFALookAheadUNode(start, pos)); } else if (indep) { cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return *end = registerNode(new NFAPossessiveQuantifierUNode(this, start, 1, 1)); } else { // capping or noncapping, it doesnt matter *end = cur = cur->next = registerNode(new NFAGroupTailUNode(grc)); next = quantifyGroup(start, *end, grc); if (next) { start = next; *end = next->next; } flags = oldFlags; return start; } } break; case '{': // registered pattern cur->next = parseRegisteredWCPattern(&next); if (cur->next) cur = next; break; case '*': case '+': case '?': // case '}': // case ']': raiseError(); break; default: if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACICharUNode(ch)); else next = registerNode(new NFACharUNode(ch)); break; } if (next) cur = cur->next = quantify(next); } if (inParen) raiseError(); else { if (inOr) cur = cur->next = registerNode(new NFAAcceptUNode); if (end) *end = cur; } flags = oldFlags; if (error) return NULL; return start; }