本文整理汇总了C++中BaseString::append方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseString::append方法的具体用法?C++ BaseString::append怎么用?C++ BaseString::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseString
的用法示例。
在下文中一共展示了BaseString::append方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFile
bool LocalConfig::readFile(const char * filename, bool &fopenError)
{
char line[1024];
fopenError = false;
FILE * file = fopen(filename, "r");
if(file == 0){
BaseString::snprintf(line, sizeof(line),
"Unable to open local config file: %s", filename);
setError(0, line);
fopenError = true;
return false;
}
BaseString theString;
while(fgets(line, sizeof(line), file)){
BaseString tmp(line);
tmp.trim(" \t\n\r");
if(tmp.length() > 0 && tmp.c_str()[0] != '#'){
theString.append(tmp);
break;
}
}
while (fgets(line, sizeof(line), file)) {
BaseString tmp(line);
tmp.trim(" \t\n\r");
if(tmp.length() > 0 && tmp.c_str()[0] != '#'){
theString.append(";");
theString.append(tmp);
}
}
BaseString err;
bool return_value = parseString(theString.c_str(), err);
if (!return_value) {
BaseString tmp;
tmp.assfmt("Reading %s: %s", filename, err.c_str());
setError(0, tmp.c_str());
}
fclose(file);
return return_value;
}
示例2: BaseString
BaseString
set_env_var(const BaseString& existing,
const BaseString& name,
const BaseString& value)
{
/* Split existing on space
* (may have issues with env vars with spaces)
* Split assignments on =
* Where name == name, output new value
*/
BaseString newEnv;
Vector<BaseString> assignments;
int assignmentCount = existing.split(assignments, BaseString(" "));
for (int i=0; i < assignmentCount; i++)
{
Vector<BaseString> terms;
int termCount = assignments[i].split(terms, BaseString("="));
if (termCount)
{
if (strcmp(name.c_str(), terms[0].c_str()) == 0)
{
/* Found element */
newEnv.append(name);
newEnv.append('=');
newEnv.append(value);
}
else
{
newEnv.append(assignments[i]);
}
}
newEnv.append(' ');
}
return newEnv;
}
示例3: native
static
bool
create_directory(const char * path)
{
BaseString native(path);
to_native(native);
BaseString tmp(path);
Vector<BaseString> list;
if (tmp.split(list, "/") == 0)
{
g_logger.error("Failed to create directory: %s", tmp.c_str());
return false;
}
BaseString cwd = IF_WIN("","/");
for (unsigned i = 0; i < list.size(); i++)
{
cwd.append(list[i].c_str());
cwd.append("/");
NdbDir::create(cwd.c_str(),
NdbDir::u_rwx() | NdbDir::g_r() | NdbDir::g_x(),
true);
}
struct stat sbuf;
if (lstat(native.c_str(), &sbuf) != 0 ||
!S_ISDIR(sbuf.st_mode))
{
g_logger.error("Failed to create directory: %s (%s)",
native.c_str(),
cwd.c_str());
return false;
}
return true;
}
示例4:
int
startPostUpgradeChecks(NDBT_Context* ctx, NDBT_Step* step)
{
/**
* This will restart *self* in new version
*/
BaseString extraArgs;
if (ctx->getProperty("RestartNoDDL", Uint32(0)))
{
/* Ask post-upgrade steps not to perform DDL
* (e.g. for 6.3->7.0 upgrade)
*/
extraArgs.append(" --noddl ");
}
/**
* mysql-getopt works so that passing "-n X -n Y" is ok
* and is interpreted as "-n Y"
*
* so we restart ourselves with testcase-name and "--post-upgrade" appended
* e.g if testcase is "testUpgrade -n X"
* this will restart it as "testUpgrade -n X -n X--post-upgrade"
*/
BaseString tc;
tc.assfmt("-n %s--post-upgrade %s",
ctx->getCase()->getName(),
extraArgs.c_str());
ndbout << "About to restart self with extra arg: " << tc.c_str() << endl;
AtrtClient atrt;
int process_id = atrt.getOwnProcessId();
if (process_id == -1)
{
g_err << "Failed to find own process id" << endl;
return NDBT_FAILED;
}
if (!atrt.changeVersion(process_id, tc.c_str()))
return NDBT_FAILED;
// Will not be reached...
return NDBT_OK;
}
示例5: require
static
bool
pr_fix_ndb_connectstring(Properties& props, proc_rule_ctx& ctx, int)
{
const char * val;
atrt_cluster& cluster = *ctx.m_cluster;
if (cluster.m_options.m_features & atrt_options::AO_NDBCLUSTER)
{
if (!cluster.m_options.m_loaded.get(ndbcs, &val))
{
/**
* Construct connect string for this cluster
*/
BaseString str;
for (unsigned i = 0; i<cluster.m_processes.size(); i++)
{
atrt_process* tmp = cluster.m_processes[i];
if (tmp->m_type == atrt_process::AP_NDB_MGMD)
{
if (str.length())
{
str.append(";");
}
const char * port;
require(tmp->m_options.m_loaded.get("--PortNumber=", &port));
str.appfmt("%s:%s", tmp->m_host->m_hostname.c_str(), port);
}
}
cluster.m_options.m_loaded.put(ndbcs, str.c_str());
cluster.m_options.m_generated.put(ndbcs, str.c_str());
cluster.m_options.m_loaded.get(ndbcs, &val);
}
for (unsigned i = 0; i<cluster.m_processes.size(); i++)
{
cluster.m_processes[i]->m_proc.m_env.appfmt(" NDB_CONNECTSTRING=%s",
val);
}
}
return true;
}
示例6: c_str
BaseString NDBT_ResultRow::c_str() const {
BaseString str;
char buf[10];
for(int i = 0; i<cols; i++){
if(data[i]->isNULL()){
sprintf(buf, "NULL");
str.append(buf);
}else{
Uint32* p = (Uint32*)data[i]->aRef();
Uint32 sizeInBytes = data[i]->get_size_in_bytes();
for (Uint32 j = 0; j < sizeInBytes; j+=(sizeof(Uint32))){
str.append("H'");
if (j + 4 < sizeInBytes)
{
sprintf(buf, "%.8x", *p);
}
else
{
Uint32 tmp = 0;
memcpy(&tmp, p, sizeInBytes - j);
sprintf(buf, "%.8x", tmp);
}
p++;
str.append(buf);
if ((j + sizeof(Uint32)) < sizeInBytes)
str.append(", ");
}
}
str.append("\n");
}
str.append("*");
//ndbout << "NDBT_ResultRow::c_str() = " << str.c_str() << endl;
return str;
}
示例7: getcwd
//.........这里部分代码省略.........
logger.error("Cannot redirect %u to/from '%s' : %s\n", i,
redirects[i]->c_str(), strerror(errno));
_exit(1);
}
dup2(f, i);
#ifdef _WIN32
close(f);
#endif
}
#ifndef _WIN32
/* Close all filedescriptors */
for(i = STDERR_FILENO+1; (int)i < getdtablesize(); i++)
close(i);
execv(m_path.c_str(), argv);
/* XXX If we reach this point, an error has occurred, but it's kind of hard
* to report it, because we've closed all files... So we should probably
* create a new logger here */
logger.error("Exec failed: %s\n", strerror(errno));
/* NOTREACHED */
#else
// Get full path to cygwins shell
FILE *fpipe = _popen("sh -c 'cygpath -w `which sh`'", "rt");
char buf[MAX_PATH];
require(fgets(buf, MAX_PATH - 1, fpipe));
fclose(fpipe);
BaseString sh;
sh.assign(buf);
sh.trim("\n");
sh.append(".exe");
BaseString shcmd;
shcmd.assfmt("%s -c '%s %s'", sh.c_str(), m_path.c_str(), m_args.c_str());
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {sizeof(STARTUPINFO), 0};
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdInput = (HANDLE)_get_osfhandle(0);
si.hStdOutput = (HANDLE)_get_osfhandle(1);
si.hStdError = (HANDLE)_get_osfhandle(2);
if(!CreateProcessA(sh.c_str(),
(LPSTR)shcmd.c_str(),
NULL,
NULL,
TRUE,
CREATE_SUSPENDED, // Resumed after assigned to Job
NULL,
NULL,
&si,
&pi))
{
char* message;
DWORD err = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
示例8: main
int main(int argc, char** argv) {
NDB_INIT(argv[0]);
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
#ifndef DBUG_OFF
opt_debug= "d:t:O,/tmp/ndb_mgm.trace";
#endif
if ((ho_error=handle_options(&argc, &argv, my_long_options,
ndb_std_get_one_option)))
exit(ho_error);
char buf[MAXHOSTNAMELEN+10];
if(argc == 1) {
BaseString::snprintf(buf, sizeof(buf), "%s", argv[0]);
opt_connect_str= buf;
} else if (argc >= 2) {
BaseString::snprintf(buf, sizeof(buf), "%s:%s", argv[0], argv[1]);
opt_connect_str= buf;
}
if (!isatty(0) || opt_execute_str)
{
prompt= 0;
}
signal(SIGPIPE, handler);
com = new Ndb_mgmclient(opt_connect_str,1);
int ret= 0;
BaseString histfile;
if (!opt_execute_str)
{
#ifdef HAVE_READLINE
char *histfile_env= getenv("NDB_MGM_HISTFILE");
if (histfile_env)
histfile.assign(histfile_env,strlen(histfile_env));
else if(getenv("HOME"))
{
histfile.assign(getenv("HOME"),strlen(getenv("HOME")));
histfile.append("/.ndb_mgm_history");
}
if (histfile.length())
read_history(histfile.c_str());
#endif
ndbout << "-- NDB Cluster -- Management Client --" << endl;
while(read_and_execute(_try_reconnect));
#ifdef HAVE_READLINE
if (histfile.length())
{
BaseString histfile_tmp;
histfile_tmp.assign(histfile);
histfile_tmp.append(".TMP");
if(!write_history(histfile_tmp.c_str()))
my_rename(histfile_tmp.c_str(), histfile.c_str(), MYF(MY_WME));
}
#endif
}
else
{
com->execute(opt_execute_str,_try_reconnect, 0, &ret);
}
delete com;
ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
return ret;
}
示例9: main
int main()
{
BaseString s("abc");
BaseString t(s);
s.assign("def");
t.append("123");
assert(s == "def");
assert(t == "abc123");
s.assign("");
t.assign("");
for (unsigned i = 0; i < 1000; i++) {
s.append("xyz");
t.assign(s);
assert(strlen(t.c_str()) % 3 == 0);
}
{
BaseString s(":123:abc:;:foo:");
Vector<BaseString> v;
assert(s.split(v, ":;") == 7);
assert(v[0] == "");
assert(v[1] == "123");
assert(v[2] == "abc");
assert(v[3] == "");
assert(v[4] == "");
assert(v[5] == "foo");
assert(v[6] == "");
}
{
BaseString s(":123:abc:foo:bar");
Vector<BaseString> v;
assert(s.split(v, ":;", 4) == 4);
assert(v[0] == "");
assert(v[1] == "123");
assert(v[2] == "abc");
assert(v[3] == "foo:bar");
BaseString n;
n.append(v, "()");
assert(n == "()123()abc()foo:bar");
n = "";
n.append(v);
assert(n == " 123 abc foo:bar");
}
{
assert(BaseString("hamburger").substr(4,2) == "");
assert(BaseString("hamburger").substr(3) == "burger");
assert(BaseString("hamburger").substr(4,8) == "urge");
assert(BaseString("smiles").substr(1,5) == "mile");
assert(BaseString("012345").indexOf('2') == 2);
assert(BaseString("hej").indexOf('X') == -1);
}
{
assert(BaseString(" 1").trim(" ") == "1");
assert(BaseString("1 ").trim(" ") == "1");
assert(BaseString(" 1 ").trim(" ") == "1");
assert(BaseString("abc\t\n\r kalleabc\t\r\n").trim("abc\t\r\n ") == "kalle");
assert(BaseString(" ").trim(" ") == "");
}
return 0;
}
示例10: main
int main(int argc, char** argv){
NDB_INIT(argv[0]);
ndb_opt_set_usage_funcs(short_usage_sub, usage);
load_defaults("my",load_default_groups,&argc,&argv);
int ho_error;
#ifndef DBUG_OFF
opt_debug= "d:t:O,/tmp/ndb_mgm.trace";
#endif
if ((ho_error=handle_options(&argc, &argv, my_long_options,
ndb_std_get_one_option)))
exit(ho_error);
BaseString connect_str(opt_ndb_connectstring);
if(argc == 1) {
connect_str.assfmt("%s", argv[0]);
} else if (argc >= 2) {
connect_str.assfmt("%s:%s", argv[0], argv[1]);
}
if (!isatty(0) || opt_execute_str)
{
prompt= 0;
}
com = new Ndb_mgmclient(connect_str.c_str(), opt_verbose);
int ret= 0;
BaseString histfile;
if (!opt_execute_str)
{
#ifdef HAVE_READLINE
char *histfile_env= getenv("NDB_MGM_HISTFILE");
if (histfile_env)
histfile.assign(histfile_env,strlen(histfile_env));
else if(getenv("HOME"))
{
histfile.assign(getenv("HOME"),strlen(getenv("HOME")));
histfile.append("/.ndb_mgm_history");
}
if (histfile.length())
read_history(histfile.c_str());
#endif
ndbout << "-- NDB Cluster -- Management Client --" << endl;
while(read_and_execute(opt_try_reconnect))
;
#ifdef HAVE_READLINE
if (histfile.length())
{
BaseString histfile_tmp;
histfile_tmp.assign(histfile);
histfile_tmp.append(".TMP");
if(!write_history(histfile_tmp.c_str()))
my_rename(histfile_tmp.c_str(), histfile.c_str(), MYF(MY_WME));
}
#endif
}
else
{
com->execute(opt_execute_str, opt_try_reconnect, 0, &ret);
}
delete com;
ndb_end(opt_ndb_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
// Don't allow negative return code
if (ret < 0)
ret = 255;
return ret;
}