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


C++ AString::str方法代码示例

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


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

示例1: AddPatternToFile

bool ADVBPatterns::AddPatternToFile(const AString& filename, const AString& pattern)
{
	const ADVBConfig& config = ADVBConfig::Get();
	AStdFile fp;
	bool done = false;
	bool added = false;

	if (fp.open(filename)) {
		AString line;

		while (line.ReadLn(fp) >= 0) {
			if (line == pattern) {
				done = true;
				break;
			}
		}

		fp.close();
	}

	if (!done) {
		if (fp.open(filename, "a")) {
			fp.printf("%s\n", pattern.str());
			fp.close();

			config.logit("Add pattern '%s' to file '%s'", pattern.str(), filename.str());

			added = true;
		}
	}

	return added;
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: CheckConnection

/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::CheckConnection(const AString& host)
{
	AString connstr;

	connstr.printf("postgresql://%s", host.str());

	bool success = (PQping(connstr) == PQPING_OK);
	debug("Checking connection to %s...%s\n", host.str(), success ? "success" : "**failure**");
	return success;
}
开发者ID:richardxday,项目名称:rdlib,代码行数:11,代码来源:PostgresDatabase.cpp

示例3: CreateDatabase

/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::CreateDatabase(const AString& name)
{
	bool success = false;

	if ((success = RunSQL(AString::Formatify("create database %s", name.str()))) == false) {
		AString errmsg = GetErrorMessage();
		if (errmsg.PosNoCase("already exists") < 0) {
			debug("Failed to create database '%s': %s\n", name.str(), errmsg.str());
		}
		else success = true;
	}

	return success;
}
开发者ID:richardxday,项目名称:rdlib,代码行数:15,代码来源:PostgresDatabase.cpp

示例4: AddUser

/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::AddUser(const AString& username, const AString& password)
{
	bool success = false;

	if ((success = RunSQL(AString::Formatify("create user %s with password '%s'", username.str(), password.str()))) == false) {
		AString errmsg = GetErrorMessage();
		if (errmsg.PosNoCase("already exists") < 0) {
			debug("Failed to create user '%s': %s\n", username.str(), errmsg.str());
		}
		else success = true;
	}

	return success;
}
开发者ID:richardxday,项目名称:rdlib,代码行数:15,代码来源:PostgresDatabase.cpp

示例5: ReadReplacementsFile

bool ADVBConfig::ReadReplacementsFile(std::vector<REPLACEMENT>& replacements, const AString& filename) const
{
	AStdFile fp;
	bool success = false;

	if (fp.open(filename)) {
		AString line;

		//printf("Reading replacements file '%s':", filename.str());

		while (line.ReadLn(fp) >= 0) {
			int p = 0;

			if ((line.Word(0)[0] != ';') && ((p = line.Pos("=")) >= 0)) {
				REPLACEMENT repl = {
					line.Left(p).Word(0).DeQuotify(),
					line.Mid(p + 1).Word(0).DeQuotify(),
				};

				//printf("Replacement: '%s' -> '%s'", repl.search.str(), repl.replace.str());

				replacements.push_back(repl);
			}
		}

		fp.close();

		success = true;
	}
	else logit("Failed to open replacements file '%s'", filename.str());

	return success;
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例6: main

int main(int argc, char *argv[])
{
	ASocketServer server;
	AStdSocket    socket(server);

	if (argc < 2) {
		fprintf(stderr, "cmdsender " VER_STRING "\n");
		fprintf(stderr, "Usage: cmdsender <host> [<port>]\n");
		exit(1);
	}
	
	if (socket.open("0.0.0.0",
					0,
					ASocketServer::Type_Datagram)) {
		uint_t port = 1722;

		if (argc >= 3) port = (uint_t)AString(argv[2]);
		
		if (socket.setdatagramdestination(argv[1], port)) {
			AString line;
			while (line.ReadLn(Stdin) >= 0) {
				if (socket.printf("%s\n", line.str()) <= 0) break;
			}
		}
		
		socket.close();
	}
	
	return 0;
}
开发者ID:richardxday,项目名称:rdutils,代码行数:30,代码来源:cmdsender.cpp

示例7: TriggerServerCommand

bool TriggerServerCommand(const AString& cmd)
{
	const ADVBConfig& config = ADVBConfig::Get();
	AString host = config.GetServerHost();
	bool success = false;

	if (host.Valid()) {
		static ASocketServer server;
		static AStdSocket    socket(server);

		if (!socket.isopen()) {
			if (socket.open("0.0.0.0", 0, ASocketServer::Type_Datagram)) {
				uint_t port = config.GetServerPort();

				if (!socket.setdatagramdestination(host, port)) {
					config.printf("Failed to set %s:%u as UDP destination for server command triggers", host.str(), port);
				}
			}
			else config.printf("Failed to open UDP socket for server command triggers");
		}

		success = (socket.printf("%s\n", cmd.str()) > 0);
	}

	return success;
}
开发者ID:richardxday,项目名称:rddvb,代码行数:26,代码来源:dvbmisc.cpp

示例8: MoveFile

bool MoveFile(const AString& src, const AString& dst, bool binary)
{
	const ADVBConfig& config = ADVBConfig::Get();
	bool success = false;

	if (SameFile(src, dst)) {
		config.printf("File move: '%s' and '%s' are the same file", src.str(), dst.str());
		success = true;
	}
	else if	(rename(src, dst) == 0) success = true;
	else if (CopyFile(src, dst, binary)) {
		if (remove(src) == 0) success = true;
		else config.logit("Failed to remove '%s' after copy", src.str());
	}

	return success;
}
开发者ID:richardxday,项目名称:rddvb,代码行数:17,代码来源:dvbmisc.cpp

示例9: Open

/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::Open(const AString& host, const AString& username, const AString& password, const AString& database)
{
	bool success = false;

	if (!conn) {
		AString str;

		ClearResult();

		connstr.Delete();
		connstr.printf("postgresql://%s:%[email protected]%s", username.str(), password.str(), host.str());

		if (CheckConnection()) {
			str = connstr;
			if (database.Valid()) str.printf("/%s", database.ToLower().str());

			success = (((conn = PQconnectdb(str.str())) != NULL) && (PQstatus(conn) == CONNECTION_OK));
			if (success) {
				if (database.Valid()) debug("Connected to database '%s' on %s\n", database.str(), host.str());
				isopen = true;
			}
			else {
				if (database.Valid()) debug("Failed to connect to database '%s' on %s: %s\n", database.str(), host.str(), GetErrorMessage().str());
				else				  debug("Failed to connect server %s: %s\n", host.str(), GetErrorMessage().str());

				Close();
			}
		}
		else debug("No connection to server!\n");
	}

	return success;
}
开发者ID:richardxday,项目名称:rdlib,代码行数:34,代码来源:PostgresDatabase.cpp

示例10: ChangeDirectory

bool ChangeDirectory(const AString& dir)
{
	bool success = true;

#ifdef __LINUX__
	success = (chdir(dir) == 0);
#else
	success = ::SetCurrentDirectory(dir.str());
#endif

	return success;
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例11: RunSQL

/*--------------------------------------------------------------------------------*/
bool PostgresDatabase::RunSQL(const AString& sql)
{
	bool success = false;

	if (conn) {
		ClearResult();
		success = (((res = PQexec(conn, sql.str())) != NULL) && (PQresultStatus(res) == PGRES_COMMAND_OK));
		//debug("Running SQL '%s': %s\n", sql.str(), success ? "** success **" : GetErrorMessage().str());
	}

	return success;
}
开发者ID:richardxday,项目名称:rdlib,代码行数:13,代码来源:PostgresDatabase.cpp

示例12: CopyFile

bool CopyFile(const AString& src, const AString& dst, bool binary)
{
	const ADVBConfig& config = ADVBConfig::Get();
	AStdFile fp1, fp2;
	bool success = false;

	if (SameFile(src, dst)) {
		config.printf("File copy: '%s' and '%s' are the same file", src.str(), dst.str());
		success = true;
	}
	else if (fp1.open(src, binary ? "rb" : "r")) {
		if (fp2.open(dst, binary ? "wb" : "w")) {
			success = CopyFile(fp1, fp2);
			if (!success) config.logit("Failed to copy '%s' to '%s': transfer failed", src.str(), dst.str());
		}
		else config.logit("Failed to copy '%s' to '%s': failed to open '%s' for writing", src.str(), dst.str(), dst.str());
	}
	else config.logit("Failed to copy '%s' to '%s': failed to open '%s' for reading", src.str(), dst.str(), src.str());

	return success;
}
开发者ID:richardxday,项目名称:rddvb,代码行数:21,代码来源:dvbmisc.cpp

示例13: RunAndLogCommand

bool RunAndLogCommand(const AString& cmd)
{
	const ADVBConfig& config = ADVBConfig::Get();
	AString cmd1 = cmd;

	if (config.IsOutputDisabled()) cmd1.printf(" >>\"%s\" 2>&1", config.GetLogFile(ADateTime().GetDays()).str());
	else						   cmd1.printf(" 2>&1 | tee -a \"%s\"", config.GetLogFile(ADateTime().GetDays()).str());

	if (config.LogRemoteCommands()) {
		config.logit("Running '%s'", cmd1.str());
	}

	bool success = (system(cmd1) == 0);
	if (!success) config.logit("Command '%s' failed", cmd.str());

	return success;
}
开发者ID:richardxday,项目名称:rddvb,代码行数:17,代码来源:dvbmisc.cpp

示例14: CreateDirectory

bool CreateDirectory(const AString& dir)
{
	AString parentdir = dir.PathPart();
	FILE_INFO file;
	bool success = true;

	if (parentdir.Valid() && (parentdir != "/") && !::GetFileInfo(parentdir, &file)) success = CreateDirectory(parentdir);

	if (success && (dir.FilePart().Valid()) && !::GetFileInfo(dir, &file)) {
#ifdef __LINUX__
		success = (mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH) == 0);
#else
		success = ::CreateDirectoryA(dir.str(), NULL);
#endif
	}

	return success;
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例15: SQLQuery

PostgresDatabase::PostgresQuery::PostgresQuery(PostgresDatabase *_db, const AString& query) : SQLQuery(),
																							  db(_db),
																							  conn(db->GetConnection()),
																							  res(NULL),
																							  nfields(0),
																							  nrows(0),
																							  row(0),
																							  success(false)
{
	ExecStatusType status;

	if (((res = PQexec(conn, query.str())) != NULL) &&
		(((status = PQresultStatus(res)) == PGRES_COMMAND_OK) ||
		 (status == PGRES_TUPLES_OK))) {
		nfields = PQnfields(res);
		nrows   = PQntuples(res);
		//debug("Query '%s' returns %u rows x %u columns\n", query.str(), nrows, nfields);
		success = true;
	}
	//else debug("Query '%s' failed: %s (%u)\n", query.str(), GetErrorMessage().str(), res ? (uint_t)PQresultStatus(res) : 0);
}
开发者ID:richardxday,项目名称:rdlib,代码行数:21,代码来源:PostgresDatabase.cpp


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