当前位置: 首页>>代码示例>>C++>>正文


C++ util::startsWith方法代码示例

本文整理汇总了C++中util::startsWith方法的典型用法代码示例。如果您正苦于以下问题:C++ util::startsWith方法的具体用法?C++ util::startsWith怎么用?C++ util::startsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在util的用法示例。


在下文中一共展示了util::startsWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: teval

void teval(vector<string> args) {
	random_device randomDevice;
	auto seed = randomDevice();

	Database db{config::databaseFileName};
	Options opts{};
	opts.seed = seed;
	Bot pbrane{db, opts, Clock{}, setupBot};

	pbrane.vars.set("bot.owner", "jac");
	pbrane.vars.set("bot.admins", "jac");

	if(!args.empty()) {
		for(auto &arg : args) {
			if(arg.empty() || startsWith(arg, "--"))
				continue;
			cout << ": " << arg << endl;

			try {
				auto expr = Parser::parse(arg);
				cout << "expr: " << (expr ? "true" : "false") << endl;

				// print computed AST
				cout << "final: " << endl;
				cout << expr->pretty() << endl;
				cout << "stringify: " << expr->toString() << endl;

				cout << "result: " << expr->evaluate(pbrane.vm, "jac").toString() << endl;
				// TODO: other exception types...
			} catch(ParseException e) {
				cout << e.pretty() << endl;
			} catch(StackTrace &e) {
				cout << e.toString() << endl;
			} catch(string &s) {
				cout << "\t: " << s << endl;
			}
		}
		return;
	}

	while(cin.good() && !cin.eof()) {
		string nick, line;
		getline(cin, nick);
		getline(cin, line);
		if(nick.empty() || line.empty())
			break;

		try {
			auto expr = Parser::parse(line);

			cerr << "eval'ing: " << line << " as " << nick << endl;
			cerr << "final AST: " << endl;
			cerr << expr->pretty() << endl;
			cerr << "stringify: " << expr->toString() << endl;

			string res = expr->evaluate(pbrane.vm, nick).toString();
			cerr << "result: " << res << endl;
			cout << nick + ": " << res << endl;

			// TODO: other exception types
		} catch(ParseException e) {
			cerr << e.pretty() << endl;
		} catch(StackTrace &e) {
			cout << e.toString() << endl;
		} catch(string &s) {
			cerr << "\texception: " << s << endl;
			cout << nick + ": error: " + s << endl;
		}
	}
}
开发者ID:JAChapmanII,项目名称:PINKSERV2,代码行数:70,代码来源:pbrane.cpp

示例2: main

int main(int argc, char **argv) {
	vector<string> args;
	for(int i = 1; i < argc; ++i)
		args.push_back(argv[i]);

	Options opts{};
	for(auto &arg : args) {
		if (arg == "--teval") {
			teval(args);
			return 0;
		}
		if(arg == "--pprint") {
			for(auto &arg2 : args)
				if(!startsWith(arg2, "--"))
					prettyPrint(arg2);
			return 0;
		}
		if(arg == "--importGoogle") {
			importGoogleNGramData();
			return 0;
		}

		if(arg == "--import") {
			opts.import = true;
			cerr << "pbrane: import mode enabled" << endl;
		} else if(arg == "--debugSQL") {
			opts.debugSQL = true;
			cerr << "pbrane: debug sql enabled" << endl;
		} else if(arg == "--debugEventSystem") {
			opts.debugEventSystem = true;
			cerr << "pbrane: debug event system enabled" << endl;
		} else if(arg == "--debugFunctionBodies") {
			opts.debugFunctionBodies = true;
			cerr << "pbrane: debug function bodies enabled" << endl;
		} else if(arg == "--importLog") {
			opts.import = true;
			opts.importLog = true;
			cerr << "pbrane: import log enabled" << endl;
		} else {
			opts.seed = fromString<unsigned int>(argv[1]);
		}
	}

	if(args.empty()) {
		random_device randomDevice;
		opts.seed = randomDevice();
	}

	Database db{config::databaseFileName};
	Bot pbrane{db, opts, Clock{}, setupBot};

	// while there is more input coming
	while(!cin.eof() && !pbrane.done) {
		// read the current line of input
		string line;
		getline(cin, line);

		if(line.find_first_not_of(" \t\r\n") == string::npos)
			continue;

		string network;
		auto ts = Clock{}.now();

		if(!opts.importLog) {
			network = line.substr(0, line.find(" "));
			line = line.substr(line.find(" ") + 1);

			if(line.find_first_not_of(" \t\r\n") == string::npos)
				continue;
		} else {
			auto fs = util::split(line, "|");
			if(fs.size() < 3) {
				cerr << "unable to parse log line" << endl;
				cerr << "line: " << line << endl;
				return 32;
			}

			ts = util::fromString<sqlite_int64>(fs[0]);
			network = fs[1];
			line = util::join(fs.begin() + 2, fs.end(), " ");
		}

		Entry entry{ts, network, line};
		pbrane.journal.upsert(entry);

		auto fields = split(line);
		if(fields.empty()) continue;

		if(entry.type == EntryType::Text) {
			auto nick = entry.nick();
			auto message = entry.arguments;
			auto target = entry.where;

			if(target == pbrane.vars.get("bot.nick").toString())
				target = nick;

			// TODO: simplify construction?
			pbrane.vars.set("nick", nick);
			pbrane.vars.set("where", target);
			pbrane.vars.set("text", message);
//.........这里部分代码省略.........
开发者ID:JAChapmanII,项目名称:PINKSERV2,代码行数:101,代码来源:pbrane.cpp


注:本文中的util::startsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。