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


C++ replace_string函数代码示例

本文整理汇总了C++中replace_string函数的典型用法代码示例。如果您正苦于以下问题:C++ replace_string函数的具体用法?C++ replace_string怎么用?C++ replace_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ReadStringFromFile

static bool ReadStringFromFile (const char* pathName, std::string& output)
{
	FILE* file = fopen( pathName, "rb" );
	if (file == NULL)
		return false;
	fseek(file, 0, SEEK_END);
	int length = ftell(file);
	fseek(file, 0, SEEK_SET);
	if (length < 0)
	{
		fclose( file );
		return false;
	}
	output.resize(length);
	int readLength = fread(&*output.begin(), 1, length, file);
	fclose(file);
	if (readLength != length)
	{
		output.clear();
		return false;
	}

	replace_string(output, "\r\n", "\n", 0);
	return true;
}
开发者ID:CSRedRat,项目名称:glsl-optimizer,代码行数:25,代码来源:glsl_optimizer_tests.cpp

示例2: create

void create()
{
   string filename=__DIR__"find.map";
   string buf, *buf1;
   string dir, name;
   int size, i;

   seteuid(getuid());
   set("name", "监控精灵");
   set("id", "miscd");

   maps=([]);

   buf=read_file(filename);
   if(!buf) return; //no data available.

   buf1=explode(buf,"\n");
   size=sizeof(buf1);
   if(!size) return;

   for(i=0;i<size;i++) {
     if(sscanf(buf1[i],"%s %s",dir,name)==2) {
       name=replace_string(name," ","");
       if(strlen(dir)>2 && strlen(name)>2) {
         maps+=([dir:name]);
       }
     }
开发者ID:gongfuPanada,项目名称:mhxy2002,代码行数:27,代码来源:miscd.c

示例3: cmd_message

int cmd_message(string str) {
    string what, msg, extra;

    if(!str) {
	notify_fail("Which message? What is the message?\n");
	return 0;
    }
    if(sscanf(str, "%s %s", what, msg) != 2) {
	notify_fail("Correct syntax: <message [in | out] [msg]>\n");
	return 0;
    }
    if(what != "in" && what != "out") {
	notify_fail("You may only set your messages in and out.\n");
	return 0;
    }
    if((int)this_player()->query_mp() < 10) {
	notify_fail("Too low on magic power.\n");
	return 0;
    }
    this_player()->add_mp(-10);
    msg = replace_string(msg, "%^BLACK%^", "%^BOLD%^%^BLACK%^");
    while(sscanf(msg, "%snortheast%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%ssoutheast%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%snorthwest%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%ssouthwest%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%seast%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%swest%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%snorth%s", msg, extra) == 2) msg += "$D" + extra;
    while(sscanf(msg, "%ssouth%s", msg, extra) == 2) msg += "$D" + extra;
    if(what == "in") this_player()->setenv("MIN", "$N "+msg);
    else this_player()->setenv("MOUT", "$N "+msg+" $D");
    return 1;
}
开发者ID:ehershey,项目名称:pd,代码行数:33,代码来源:_message.c

示例4: cmd

mixed cmd(string args) {
    object ob, cre_ob, jeans, shirt, robe, hat, book, staff;
    string filec, filep, nom, home_dir;
    filep = player_save_file(args);
    filec = replace_string(filep, "players", "creators");

    if( !(master()->valid_apply(({ PRIV_ASSIST, PRIV_SECURE, LIB_CONNECT }))) )
开发者ID:thathat,项目名称:ciscomud,代码行数:7,代码来源:encre.c

示例5: TEST

TEST(find_command, IF(not_windows))
{
	opt_handlers_setup();

	replace_string(&cfg.shell, "/bin/sh");

	assert_success(chdir(TEST_DATA_PATH));
	strcpy(lwin.curr_dir, test_data);

	assert_success(exec_commands("set findprg='find %s %a %u'", &lwin,
				CIT_COMMAND));

	/* Nothing to repeat. */
	assert_failure(exec_commands("find", &lwin, CIT_COMMAND));

	assert_success(exec_commands("find a", &lwin, CIT_COMMAND));
	assert_int_equal(3, lwin.list_rows);

	assert_success(exec_commands("find . -name aaa", &lwin, CIT_COMMAND));
	assert_int_equal(1, lwin.list_rows);

	assert_success(exec_commands("find -name '*.vifm'", &lwin, CIT_COMMAND));
	assert_int_equal(4, lwin.list_rows);

	view_teardown(&lwin);
	view_setup(&lwin);

	/* Repeat last search. */
	strcpy(lwin.curr_dir, test_data);
	assert_success(exec_commands("find", &lwin, CIT_COMMAND));
	assert_int_equal(4, lwin.list_rows);

	opt_handlers_teardown();
}
开发者ID:acklinr,项目名称:vifm,代码行数:34,代码来源:commands.c

示例6: look_room

int look_room(object me, object env)
{
	int i;
	object *inv;
	mapping exits;
	string str, *dirs;

	if( !env ) {
		write("你的四周灰蒙蒙地一片,什麽也没有。\n");
		return 1;
	}
	str = sprintf( "\n▲ %s - %s\n  %s\n%s",
		env->query("short"),
		file_name(env),
		replace_string(env->query("long"), "\n", ""),
		env->query("outdoors")? NATURE_D->outdoor_room_description() : "" );

	if( mapp(exits = env->query("exits")) ) {
		dirs = keys(exits);
		for(i=0; i<sizeof(dirs); i++)
			if( (int)env->query_door(dirs[i], "status") & DOOR_CLOSED )
				dirs[i] = 0;
		dirs -= ({ 0 });
		if( sizeof(dirs)==0 )
			str += "  这里没有任何明显的出路。\n";
		else if( sizeof(dirs)==1 )
			str += "  这里唯一的出口是 " + BOLD + dirs[0] + NOR + "。\n";
		else
			str += sprintf("  这里明显的出口是 " + BOLD + "%s" + NOR + " 和 " + BOLD + "%s" + NOR + "。\n",
				implode(dirs[0..sizeof(dirs)-2], "、"), dirs[sizeof(dirs)-1]);
	}
开发者ID:mudchina,项目名称:es2-utf8,代码行数:31,代码来源:look.c

示例7: parse_timemaster_settings

static int parse_timemaster_settings(char **settings,
				     struct timemaster_config *config)
{
	char *name, *value;

	for (; *settings; settings++) {
		parse_setting(*settings, &name, &value);
		if (!strcasecmp(name, "ntp_program")) {
			if (!strcasecmp(value, "chronyd")) {
				config->ntp_program = CHRONYD;
			} else if (!strcasecmp(value, "ntpd")) {
				config->ntp_program = NTPD;
			} else {
				pr_err("unknown ntp program %s", value);
				return 1;
			}
		} else if (!strcasecmp(name, "rundir")) {
			replace_string(value, &config->rundir);
		} else {
			pr_err("unknown timemaster setting %s", name);
			return 1;
		}
	}

	return 0;
}
开发者ID:HeXingxing,项目名称:linuxptp-as,代码行数:26,代码来源:timemaster.c

示例8: CheckGLSL

static bool CheckGLSL (bool vertex, bool gles, const char* prefix, const std::string& source)
{
	std::string src;
	if (gles)
	{
		src += "#define lowp\n";
		src += "#define mediump\n";
		src += "#define highp\n";
		src += "#define texture2DLodEXT texture2DLod\n";
	}
	src += source;
	if (gles)
	{
		replace_string (src, "GL_EXT_shader_texture_lod", "GL_ARB_shader_texture_lod", 0);
	}
	const char* sourcePtr = src.c_str();
	
	
	GLhandleARB shader = glCreateShaderObjectARB (vertex ? GL_VERTEX_SHADER_ARB : GL_FRAGMENT_SHADER_ARB);
	glShaderSourceARB (shader, 1, &sourcePtr, NULL);
	glCompileShaderARB (shader);
	GLint status;
	glGetObjectParameterivARB (shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
	bool res = true;
	if (status == 0)
	{
		char log[4096];
		GLsizei logLength;
		glGetInfoLogARB (shader, sizeof(log), &logLength, log);
		printf ("  glsl compile error on %s:\n%s\n", prefix, log);
		res = false;
	}
	glDeleteObjectARB (shader);
	return res;
}
开发者ID:DerSaidin,项目名称:OpenWolf,代码行数:35,代码来源:glsl_optimizer_tests.cpp

示例9: event_exit

void event_exit(object ob, varargs string msg, object dest, mixed avoid)
{
  string new_name;

  ::event_exit(ob, msg, dest, avoid);

  if (!msg || !strlen(msg))
    return;

  // items added to our inventory also trigger event_enter
  if (environment(ob) == this_object())
    return;

  if (avoid)
  {
    if (pointerp(avoid) && (member_array(this_object(), avoid) != -1))
      return;
    else if (objectp(avoid) && (avoid == this_object()))
      return;
  }

  if (living(ob) && environment(this_object()))
  {
    if (this_object()->check_dark(environment(this_object())->query_light()) == 0)
    {
      // change player appereance from /table/hud_table.c, neverbot 10/04
      new_name = (string)HUD->query_colored_name(this_object(), ob, ob->query_cap_name(), 1);
      msg = replace_string(msg, ob->query_cap_name(), new_name);

      write(msg);
    }
    else
      write(_LANG_EVENTS_SOMEBODY_LEAVES);
  }
}
开发者ID:houseofmaldorne,项目名称:ccmudlib,代码行数:35,代码来源:events.c

示例10: filter_thumbnail

/*
 *	group1/M00/0D/F3/3MIv8U0JrcoAAAAAAABNcGtWhC0409=320X100)!.jpg
 * 	return 320X100
 */
int filter_thumbnail(char *filename, char thumbnail_str[], int len) {
	int i;
	if (NULL == filename)
		return 0;
	if (!is_image_ext(filename, image_ext, IMAGE_EXT_LEN))
		return 0;
	memset(thumbnail_str, 0, len);
	char *thum_start = NULL;
	char *thum_end = NULL;
	if (NULL == (thum_start = strrchr(filename, '='))) {
		return 0;
	}
	thum_start++;
	//modify for .jpg.jpg
	if (NULL == (thum_end = strchr(thum_start, '.'))) {
		return 0;
	}
	if (thum_end - thum_start + 1 >= len)
		return 0;
	len = thum_end - thum_start + 1;
	snprintf(thumbnail_str, len, "%s", thum_start);
	int trim_str_len = strlen(thum_end);
	thum_start--;
	for (i = 0; i < trim_str_len; i++) {
		*(thum_start++) = *(thum_end++);
	}
	*thum_start = '\0';
	replace_string(thumbnail_str, len);
	return 1;
}
开发者ID:lixy,项目名称:nginx-fastdfs,代码行数:34,代码来源:fdfs_thumbnail.c

示例11: send_msg

// This is the interface to the intermud channels
void send_msg(string channel, string id, string name, string msg, int emoted,
	mixed filter)
{
	string *names;
	int i;
	mapping muds;
	mapping svcs;
	mapping minfo;

	if( !this_player()		// Prevent from being called by ourself.
	||	!ACCESS_CHECK(previous_object())) return;

#ifdef DEBUG
	set("channel_id", "网路频道精灵");
	CHANNEL_D->do_channel(this_object(), "sys", "prepare to send gchannel message.");
#endif
	muds = (mapping)DNS_MASTER->query_muds();
	svcs = (mapping)DNS_MASTER->query_svc();
	msg = replace_string(msg, "|", "");
	msg = replace_string(msg, "@@@", "");
	// use keys(svcs) because none of the muds not in svcs can possibley
	// receive the message
	names = keys(svcs);
	i = sizeof(names);
	while(i--)
		if( (names[i] != mud_nname())
		&&	evaluate(filter, muds[names[i]])) {
			minfo = muds[names[i]];
			if(!mapp(minfo) || !mapp(svcs[names[i]])
			|| !(svcs[names[i]]["gwizmsg"] & SVC_UDP))
				continue;
#ifdef DEBUG
	set("channel_id", "网路频道精灵");
	CHANNEL_D->do_channel(this_object(), "sys",
		sprintf("gchannel message sent to %s.", minfo["NAME"]));
#endif
			DNS_MASTER->send_udp(minfo["HOSTADDRESS"], minfo["PORTUDP"],
				"@@@" + DNS_GCHANNEL +
				"||NAME:" + Mud_name() +
				"||PORTUDP:" + udp_port() +
				"||USRNAME:" + capitalize(id) +
				"||CNAME:" + name +
				"||MSG:" + msg +
				"||CHANNEL:" + channel +
				(emoted?"||EMOTE:1":"") + "@@@\n");
		}
}
开发者ID:gongfuPanada,项目名称:jy,代码行数:48,代码来源:gchannel.c

示例12: cmd

mixed cmd(string args) {
    string *arr;
    string ret = "";
    string dss = replace_string(dump_socket_status(),"-- 0","--\n 0");
    foreach(mixed key, mixed val in network_stats()){
        val = val+"";
        ret += sprintf("%:-30s %s",key, val)+"\n";
    }
开发者ID:Elohim,项目名称:FGmud,代码行数:8,代码来源:netstat.c

示例13: va_arg

/* function for lower case hex substitution (unsigned int) */
char *replace_x(char *base, char *directive, va_list ap) {
	unsigned int val = va_arg(ap, unsigned int);
	char *str = unsigned_to_string(val, 16);
	char *ret;
	ret = replace_string(base, directive, str);
	free (str);
	return ret;
}
开发者ID:jm689336,项目名称:low,代码行数:9,代码来源:replace_functions_1.c

示例14: cfg_set_shell

void
cfg_set_shell(const char shell[])
{
	if(replace_string(&cfg.shell, shell) == 0)
	{
		stats_update_shell_type(cfg.shell);
	}
}
开发者ID:phantasea,项目名称:vifm,代码行数:8,代码来源:config.c

示例15: imc2_mud_name

varargs string imc2_mud_name(string name){ 
    string mudname;

    if(name) mudname = name;
    else mudname = mud_name();

    return replace_string(mudname," ","_");
}
开发者ID:RandolfShanksCarter,项目名称:DeadStars,代码行数:8,代码来源:mud_info.c


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