main() { // Create regular expression patterns RegExp X=RegExp("x[ \t]*="); RegExp Y=RegExp("y[ \t]*="); RegExp End=RegExp("end"); // Instantiate array buffer of BUFSIZE array x=array(0,0,BUFSIZE),y; // Read the file ReadFile f=ReadFile("data"); // Open file "data" for reading if(!f.isvalid()) exit(); f.setendofline("#"); // #... is handled as comment int ix=0,iy=0; while(f.read()) { // Parse lines if(X==f.argv[0]) x[ix++]=atof(f.argv[3]); else if(Y==f.argv[0]) y[iy++]=atof(f.argv[3]); else if(f.argv[0]==End) break; } // Resize the array buffer if(ix<=iy) int truesize=ix; else int truesize=iy; x.resize(truesize); y.resize(truesize); // Plot XY graph with some calculation (you need 'xgraph') plot << x << y << y*y/5 << endl; }
bool UserFiltersModel::Add (const RuleOptionDialog& dia) { const auto& itemRx = dia.GetType () == FilterOption::MTRegexp ? RegExp (dia.GetString (), dia.GetCase ()) : RegExp (); FilterOption fo; fo.Case_ = dia.GetCase (); fo.MatchType_ = dia.GetType (); fo.Domains_ = dia.GetDomains (); fo.NotDomains_ = dia.GetNotDomains (); const FilterItem item { dia.GetString ().toUtf8 (), itemRx, fo.MatchType_ == FilterOption::MTPlain ? QByteArrayMatcher (dia.GetString ().toUtf8 ()) : QByteArrayMatcher (), fo }; auto& container = dia.IsException () ? Filter_.Exceptions_ : Filter_.Filters_; const int size = dia.IsException () ? Filter_.Exceptions_.size () : rowCount (); beginInsertRows (QModelIndex (), size, size); container << item; endInsertRows (); WriteSettings (); return !dia.IsException (); }
PlaintextLanguage(): Language( "Plaintext", RegExp("*.txt"), plaintextSyntax() ) {}
RegExpManager::RegExpResult RegExpManager::ChangeRegExp( const UnicodeString& regexp, const UnicodeString& newRegexp) { UnicodeString decodedRegExp = Decode(regexp); UnicodeString decodedNewRegExp = Decode(newRegexp); RegExpResult result; result.Success = false; result.ErrorMessage = "No matching regexp"; for (RegExpContainer::iterator i = regExps_.begin(); i != regExps_.end(); ++i) { if (i->GetRegExp() == decodedRegExp) { try { *i = RegExp(decodedNewRegExp, i->GetReply(), locale_); SaveRegExps(); result.Success = true; break; } catch (Exception& e) { result.ErrorMessage = e.GetMessage(); result.Success = false; } } } return result; }
CxxLanguage(): Language( "C++", RegExp("*.((h|c){0..1:(pp|xx|++|h|c)}|(m|mm))"), cxxSyntax(), cppDiscoverySyntax() ) {}
void replaceRTF(QString &Text) { QString NewText; QRegExp RegExp("\\\\par(.+)\\\\par"); RegExp.setMinimal(true); int pos = 0; while ((pos = RegExp.indexIn(Text, pos)) != -1) { NewText += "<p>" + RegExp.cap(1) + "</p>"; pos += RegExp.matchedLength(); } NewText.remove(QRegExp("\\\\\\S+")); NewText.remove("Terms of Use"); Text = NewText; }
String AndroidSDK::FindDefaultBuildToolsRelease() const { Vector<String> releases = FindBuildToolsReleases(); if(releases.GetCount()) { Sort(releases, StdGreater<String>()); int idx = 0; for(int i = 0; i < releases.GetCount(); i++) { if(RegExp("^[1-9][0-9.]*$").Match(releases[i])) { idx = i; break; } } return releases[idx]; } return ""; }
void CNetworkClient::login() { QStringList LoginArguments; int MHz = 0; #ifdef Q_OS_UNIX quint64 cpuHz; size_t size = sizeof(quint64); if(sysctlbyname("hw.cpufrequency_max", &cpuHz, &size, 0, 0)) { QFile CPUClockFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"); if(CPUClockFile.exists()) //Linux with correct sysfs (on some machines cpuX/cpufreq doesn't exists) { CPUClockFile.open(QIODevice::ReadOnly); MHz = CPUClockFile.readAll().trimmed().toInt() / 1000; CPUClockFile.close(); } else //Other *unix { CPUClockFile.setFileName("/proc/cpuinfo"); CPUClockFile.open(QIODevice::ReadOnly); QString CPUInfo = QString(CPUClockFile.readAll()); QRegExp RegExp("cpu MHz\\s+: (\\d+)"); RegExp.indexIn(CPUInfo); MHz = RegExp.cap(1).toInt(); CPUClockFile.close(); } } else MHz = cpuHz/1000000; #else #ifdef Q_OS_WIN32 QSettings Settings("HKEY_LOCAL_MACHINE\\HARDWARE\\Description\\System\\CentralProcessor\\0", QSettings::NativeFormat); MHz = Settings.value("~MHz").toInt(); #else #endif #endif qDebug("Detected CPU clock : %d MHz", MHz); LoginArguments << Username << Password << QString::number(MHz) << Socket.localAddress().toString() << QString("HoSpLo ") + VERSION << "\t0" << "\tsp"; execCommand("LOGIN", LoginArguments); }
String AndroidSDK::FindDefaultPlatform() const { Vector<String> platforms = FindPlatforms(); if(platforms.GetCount()) { Android::NormalizeVersions(platforms); Sort(platforms, StdGreater<String>()); Android::RemoveVersionsNormalization(platforms); int idx = 0; for(int i = 0; i < platforms.GetCount(); i++) { if(RegExp("^android-[0-9]*$").Match(platforms[i])) { idx = i; break; } } return platforms[idx]; } return ""; }
// primaryExpr ::= NUMBER // | STRING // | variable // | function '(' exprList ')' // | '(' expr ')' std::unique_ptr<Expr> FlowParser::primaryExpr() { FNTRACE(); static struct { const char* ident; long long nominator; long long denominator; } units[] = { { "byte", 1, 1 }, { "kbyte", 1024llu, 1 }, { "mbyte", 1024llu * 1024, 1 }, { "gbyte", 1024llu * 1024 * 1024, 1 }, { "tbyte", 1024llu * 1024 * 1024 * 1024, 1 }, { "bit", 1, 8 }, { "kbit", 1024llu, 8 }, { "mbit", 1024llu * 1024, 8 }, { "gbit", 1024llu * 1024 * 1024, 8 }, { "tbit", 1024llu * 1024 * 1024 * 1024, 8 }, { "sec", 1, 1 }, { "min", 60llu, 1 }, { "hour", 60llu * 60, 1 }, { "day", 60llu * 60 * 24, 1 }, { "week", 60llu * 60 * 24 * 7, 1 }, { "month", 60llu * 60 * 24 * 30, 1 }, { "year", 60llu * 60 * 24 * 365, 1 }, { nullptr, 1, 1 } }; FlowLocation loc(location()); switch (token()) { case FlowToken::Ident: { std::string name = stringValue(); nextToken(); Symbol* symbol = scope()->lookup(name, Lookup::All); if (!symbol) { // XXX assume that given symbol is a auto forward-declared handler. Handler* href = (Handler*) globalScope()->appendSymbol(std::make_unique<Handler>(name, loc)); return std::make_unique<HandlerRefExpr>(href, loc); } if (auto variable = dynamic_cast<Variable*>(symbol)) return std::make_unique<VariableExpr>(variable, loc); if (auto handler = dynamic_cast<Handler*>(symbol)) return std::make_unique<HandlerRefExpr>(handler, loc); if (symbol->type() == Symbol::BuiltinFunction) { if (token() != FlowToken::RndOpen) return std::make_unique<FunctionCallExpr>((BuiltinFunction*) symbol, ExprList()/*args*/, loc); nextToken(); ExprList args; bool rv = listExpr(args); consume(FlowToken::RndClose); if (!rv) return nullptr; return std::make_unique<FunctionCallExpr>((BuiltinFunction*) symbol, std::move(args), loc); } reportError("Unsupported symbol type of '%s' in expression.", name.c_str()); return nullptr; } case FlowToken::Boolean: { std::unique_ptr<BoolExpr> e = std::make_unique<BoolExpr>(booleanValue(), loc); nextToken(); return std::move(e); } case FlowToken::RegExp: { std::unique_ptr<RegExpExpr> e = std::make_unique<RegExpExpr>(RegExp(stringValue()), loc); nextToken(); return std::move(e); } case FlowToken::InterpolatedStringFragment: return interpolatedStr(); case FlowToken::String: case FlowToken::RawString: { std::unique_ptr<StringExpr> e = std::make_unique<StringExpr>(stringValue(), loc); nextToken(); return std::move(e); } case FlowToken::Number: { // NUMBER [UNIT] auto number = numberValue(); nextToken(); if (token() == FlowToken::Ident) { std::string sv(stringValue()); for (size_t i = 0; units[i].ident; ++i) { if (sv == units[i].ident || (sv[sv.size() - 1] == 's' && sv.substr(0, sv.size() - 1) == units[i].ident)) { nextToken(); // UNIT number = number * units[i].nominator / units[i].denominator; loc.update(end()); break; } } } return std::make_unique<NumberExpr>(number, loc); } case FlowToken::IP: { std::unique_ptr<IPAddressExpr> e = std::make_unique<IPAddressExpr>(lexer_->ipValue(), loc); nextToken(); return std::move(e); } case FlowToken::Cidr: { std::unique_ptr<CidrExpr> e = std::make_unique<CidrExpr>(lexer_->cidr(), loc); nextToken(); return std::move(e); } case FlowToken::StringType: case FlowToken::NumberType: case FlowToken::BoolType: return castExpr(); case FlowToken::Begin: { // lambda-like inline function ref char name[64]; static unsigned long i = 0; ++i; snprintf(name, sizeof(name), "__lambda_%lu", i); FlowLocation loc = location(); auto st = std::make_unique<SymbolTable>(scope(), name); enter(st.get()); std::unique_ptr<Stmt> body = compoundStmt(); leave(); if (!body) return nullptr; loc.update(body->location().end); Handler* handler = new Handler(name, std::move(st), std::move(body), loc); // TODO (memory leak): add handler to unit's global scope, i.e. via: // - scope()->rootScope()->insert(handler); // - unit_->scope()->insert(handler); // to get free'd return std::make_unique<HandlerRefExpr>(handler, loc); } case FlowToken::RndOpen: { nextToken(); std::unique_ptr<Expr> e = expr(); consume(FlowToken::RndClose); e->setLocation(loc.update(end())); return e; } default: TRACE(1, "Expected primary expression. Got something... else."); reportUnexpectedToken(); return nullptr; } }
#include "morfologik.hpp" #include "logging.hpp" #include "config.hpp" #include <iostream> #include <boost/algorithm/string.hpp> #include <boost/algorithm/string/join.hpp> #include <boost/assign.hpp> const std::string Morfologik::TAG_SEPARATORS = "+,|"; const std::vector<std::string> Morfologik::DICTIONARIES = boost::assign::list_of ("morfologik")("morfeusz")("combined"); std::list<std::pair<RegExp, std::string> > Morfologik::BREAK_FORMS_RULES = boost::assign::list_of (std::pair<RegExp, std::string>(RegExp(":m:"), std::string(":m1.m2.m3:"))) (std::pair<RegExp, std::string>(RegExp(":m$"), std::string(":m1.m2.m3"))) ; Morfologik::Morfologik(const boost::program_options::variables_map& options) : level_(3), dictionary_("MORFOLOGIK"), annotationManager_(NULL), foundLemma_(false) { if (options.count("level") > 0) setLevel(options["level"].as<int>()); if (options.count("dict") > 0) setDictionary(options["dict"].as<std::string>()); keepOriginal_ = options.count("keep-original") ? true : false; jenv_ = NULL; JavaVirtualMachine *jvm = JavaVirtualMachine::Instance(); jenv_ = jvm->getENV(); initializeDictionary_();