QString IRCServer::parseCommand(QString command, bool ircserver) { QString destChan = tab->tabText(tab->currentIndex()); if (command.startsWith("/")) { QRegExp cmd; QString pref; QString msg; cmd.setPattern("^/([A-Za-z]+)\\s(.+)$"); cmd.isMinimal(); int pos = cmd.indexIn(command); if (pos > -1) { pref = cmd.cap(1); msg = cmd.cap(2); } if (pref == "me" && (destChan.startsWith("#") || destChan == nickname)) { writeToUI(GUIUtil::HtmlEscape(nickname) + " " + GUIUtil::HtmlEscape(msg), destChan); return "PRIVMSG " + destChan + " :\001ACTION " + msg + "\001"; } else if (pref == "msg") { QStringList args = msg.split(" "); QString receiver = args.takeAt(0); QString message = args.join(" "); writeToUI("you -> " + receiver + ": " + message, nickname); return "PRIVMSG " + receiver + " :" + message; } else if (pref == "quit") { return "QUIT (Zimstake Wallet IRC v1.0.1.5)"; } else if (pref == "nick") { emit nicknameChanged(msg); return "NICK " + msg; } else // Do nothing return ""; } else if (!ircserver && destChan.startsWith("#")) { if (command.endsWith("<br />")) command = command.remove(QRegExp("<br />$")); QString htmlOut = "<span style=\"color:#B5D1EE;font-weight:600;\"><" + nickname + "></span> " + command; writeToUI(htmlOut, destChan); if (!command.startsWith(":")) command.insert(0, ":"); QString request("PRIVMSG " + destChan + " " + command); return request; } else { // Do nothing return ""; } }
inline void qx_save(Archive & ar, const QRegExp & t, const unsigned int file_version) { Q_UNUSED(file_version); QString sPattern = t.pattern(); int iCaseSensitivity = static_cast<int>(t.caseSensitivity()); int iPatternSyntax = static_cast<int>(t.patternSyntax()); bool bMinimal = t.isMinimal(); ar << boost::serialization::make_nvp("pattern", sPattern); ar << boost::serialization::make_nvp("caseSensitivity", iCaseSensitivity); ar << boost::serialization::make_nvp("patternSyntax", iPatternSyntax); ar << boost::serialization::make_nvp("minimal", bMinimal); }
void XMLUtility::write(QXmlStreamWriter& writer, const QRegExp& regExp, const QString& name) { if (regExp.isEmpty() || !regExp.isValid() || name.length() == 0) { return; } writer.writeStartElement(name); writer.writeAttribute("IsMinimal", booleanToString(regExp.isMinimal())); writer.writeAttribute("CaseSensitive", caseToString(regExp.caseSensitivity())); writer.writeAttribute("PatternSyntax", getEnumMapper().PatternSyntaxToString(regExp.patternSyntax())); writer.writeCharacters(regExp.pattern()); writer.writeEndElement(); }
// Converts a QRegExp to a JS RegExp. // The conversion is not 100% exact since ECMA regexp and QRegExp // have different semantics/flags, but we try to do our best. Heap::RegExpObject::RegExpObject(const QRegExp &re) { global = false; // Convert the pattern to a ECMAScript pattern. QString pattern = QT_PREPEND_NAMESPACE(qt_regexp_toCanonical)(re.pattern(), re.patternSyntax()); if (re.isMinimal()) { QString ecmaPattern; int len = pattern.length(); ecmaPattern.reserve(len); int i = 0; const QChar *wc = pattern.unicode(); bool inBracket = false; while (i < len) { QChar c = wc[i++]; ecmaPattern += c; switch (c.unicode()) { case '?': case '+': case '*': case '}': if (!inBracket) ecmaPattern += QLatin1Char('?'); break; case '\\': if (i < len) ecmaPattern += wc[i++]; break; case '[': inBracket = true; break; case ']': inBracket = false; break; default: break; } } pattern = ecmaPattern; } Scope scope(internalClass->engine); Scoped<QV4::RegExpObject> o(scope, this); o->d()->value = QV4::RegExp::create(scope.engine, pattern, re.caseSensitivity() == Qt::CaseInsensitive, false); o->initProperties(); }
QString WAccount::loadResourceFile(const QString &fileName) { static QRegExp regexp(QLatin1String("%localized\\{(.*)\\}%")); if (!regexp.isMinimal()) regexp.setMinimal(true); QFile file(m_themePath + fileName); file.open(QFile::ReadOnly); QString text = QString::fromUtf8(file.readAll()); int pos = 0; while ((pos = regexp.indexIn(text, pos)) != -1) { QString translation = QCoreApplication::translate("Weather", regexp.cap(1).toUtf8()); text.replace(pos, regexp.matchedLength(), translation); pos += translation.length(); } return text; }
void IRCServer::ProcessLine(QString line, QString channel) { QStringList validCommands; QRegExp linematch; QRegExp actionmatch; linematch.setPattern("^(:?([A-Za-z0-9_\\-\\\\\\[\\]{}^`|.]+)?!?(\\S+)? )?([A-Z0-9]+) ?([A-Za-z0-9_\\-\\\\\\[\\]{}^`|.*#]+)?( [@=] ([#&][^\\x07\\x2C\\s]{0,200}))?([ :]+)?([\\S ]+)?$"); validCommands << "353" << "376" << "JOIN" << "KICK" << "MODE"; validCommands << "NICK" << "NOTICE" << "PART" << "PING" << "PRIVMSG"; validCommands << "QUIT" << "TOPIC" << "372" << "432" << "433"; validCommands << "332"; actionmatch.setPattern("\\001ACTION(.+)\\001"); linematch.isMinimal(); actionmatch.isMinimal(); int pos = linematch.indexIn(line); if (pos > -1) { writeToLog("[RCV] " + line); QStringList list; QStringList splitted; QString sender = linematch.cap(2); QString userhost = linematch.cap(3); QString command = linematch.cap(4); QString receiver = linematch.cap(5); QString destination = linematch.cap(7); QString content = linematch.cap(9); QString response; QString username; QString reason; QString channel; QString topic; switch (validCommands.indexOf(command)) { case 0: // 353 (Names) if (delist == true) users.clear(); list = content.split(" "); for (int i = 0; i < list.count(); i++) { users.append(list.at(i)); } if (list.count() < 53) delist = true; else delist = false; updateUserModel(); break; case 1: // 376 (End of MOTD) joinChannel(); break; case 2: // JOIN response = GUIUtil::HtmlEscape("Join: " + sender + " (" + userhost + ")"); addUser(sender); writeToUI(response, receiver); break; case 3: // KICK splitted = content.split(" :"); username = splitted.at(0); reason = splitted.at(1); removeUser(username); response = GUIUtil::HtmlEscape(sender + " kicked " + username + ". Reason: " + reason); writeToUI(response, receiver); break; case 4: // MODE response = GUIUtil::HtmlEscape(sender + " sets mode: " + content); if (receiver.startsWith("#")) { updateUsersList(receiver); writeToUI(response, receiver); } else { writeToUI(response); } break; case 5: // NICK response = GUIUtil::HtmlEscape(sender + " is now known as `" + content); removeUser(sender); addUser(content); writeToUI(response); break; case 6: // NOTICE writeToUI(GUIUtil::HtmlEscape(content)); break; case 7: // PART response = GUIUtil::HtmlEscape("Parts: " + sender + " (" + userhost + ")"); removeUser(sender); writeToUI(response, receiver); break; case 8: // PING response = "PONG " + content; sendData(response); break; case 9: // PRIVMSG int posact; posact = actionmatch.indexIn(content); if (posact > -1) { QString actionmsg = actionmatch.cap(1); response = GUIUtil::HtmlEscape(sender + " " + actionmsg.trimmed()); } else { if (receiver == nickname) { response = GUIUtil::HtmlEscape(sender + " -> you: " + content); } else { response = GUIUtil::HtmlEscape("<" + sender + "> " + content); } } if (receiver.startsWith("#") || receiver == nickname) { writeToUI(response, receiver); } else { writeToUI(response); } break; case 10: // QUIT response = GUIUtil::HtmlEscape("Quit: " + sender + " (" + userhost + ")"); removeUser(sender); writeToUI(response); break; case 11: // TOPIC response = GUIUtil::HtmlEscape(sender + " changes topic to '" + content + "'"); writeToUI(response, receiver); break; case 12: // 372 (MOTD) writeToUI(GUIUtil::HtmlEscape(content)); break; case 13: // 432 (Invalid nickname) response = "ERROR: " + content; writeToUI(GUIUtil::HtmlEscape(response)); break; case 14: // 433 (Nick already in use) response = "Nickname is already in use, please choose another. Type /nick YOURNEWNAME"; writeToUI(GUIUtil::HtmlEscape(response)); break; case 15: // 332 (Topic on join) splitted = content.split(" :"); channel = splitted.at(0); topic = splitted.at(1); response = GUIUtil::HtmlEscape("Topic for " + channel + " is '" + topic + "'"); writeToUI(response, channel); break; default: // Do nothing break; } } else { writeToLog("[ERR] " + line); } }