Exemple #1
0
TEST(String, Replace)
{
    regex_t regex;
    char *result;

    /* basic replace */
    POINTERS_EQUAL(NULL, string_replace (NULL, NULL, NULL));
    POINTERS_EQUAL(NULL, string_replace ("string", NULL, NULL));
    POINTERS_EQUAL(NULL, string_replace (NULL, "search", NULL));
    POINTERS_EQUAL(NULL, string_replace (NULL, NULL, "replace"));
    POINTERS_EQUAL(NULL, string_replace ("string", "search", NULL));
    POINTERS_EQUAL(NULL, string_replace ("string", NULL, "replace"));
    POINTERS_EQUAL(NULL, string_replace (NULL, "search", "replace"));

    STRCMP_EQUAL("test abc def", string_replace("test abc def", "xyz", "xxx"));
    STRCMP_EQUAL("test xxx def", string_replace("test abc def", "abc", "xxx"));
    STRCMP_EQUAL("xxx test xxx def xxx",
                 string_replace("abc test abc def abc", "abc", "xxx"));

    /* replace with regex */
    WEE_REPLACE_REGEX(-1, NULL, NULL, NULL, NULL, '$', NULL);
    WEE_REPLACE_REGEX(0, NULL, NULL, "", NULL, '$', NULL);
    WEE_REPLACE_REGEX(0, "string", "string", "", NULL, '$', NULL);
    WEE_REPLACE_REGEX(0, "test abc def", "test abc def", "xyz", "xxx", '$', NULL);
    WEE_REPLACE_REGEX(0, "test xxx def", "test abc def", "abc", "xxx", '$', NULL);
    WEE_REPLACE_REGEX(0, "foo", "test foo", "^(test +)(.*)", "$2", '$', NULL);
    WEE_REPLACE_REGEX(0, "test / ***", "test foo", "^(test +)(.*)", "$1/ $.*2", '$', NULL);
    WEE_REPLACE_REGEX(0, "%%%", "test foo", "^(test +)(.*)", "$.%+", '$', NULL);

    /* replace with a callback */
    /* TODO: write tests for string_replace_with_callback */
}
Exemple #2
0
bool HHVM_FUNCTION(mail,
                   const String& to,
                   const String& subject,
                   const String& message,
                   const String& additional_headers /* = null_string */,
                   const String& additional_parameters /* = null_string */) {

  // replace \0 with spaces
  String to2 = string_replace(to, s_zero, s_space);
  String subject2 = string_replace(subject, s_zero, s_space);
  String message2 = string_replace(message, s_zero, s_space);
  String headers2;
  if (!additional_headers.empty()) {
    headers2 = string_replace(additional_headers, s_zero, s_space);
  }
  String params2;
  if (!additional_parameters.empty()) {
    params2 = string_replace(additional_parameters, s_zero, s_space);
  }

  to2 = php_trim(to2);
  subject2 = php_trim(subject2);

  if (!RuntimeOption::MailForceExtraParameters.empty()) {
    params2 = string_escape_shell_cmd(
      RuntimeOption::MailForceExtraParameters.c_str());
  } else {
    params2 = string_escape_shell_cmd(params2.c_str());
  }

  return php_mail(to2, subject2, message2, headers2, params2);
}
Exemple #3
0
		ResourceDotHFile(const char * file)
		{          
			assert(file != NULL);        
			CCFileData data(GameResourceManager::sharedManager()->storedFullPathFromRelativePath(file), "rb");
			const char* buffer = (const char*)data.getBuffer();
			std::string strBuffer(buffer);
			std::stringstream ss(stringstream::in | stringstream::out);
			ss << strBuffer<<"\r\n";

			do 
			{
				// read the file from hardware
				char strTemp[1024];
				std::string strVal;   

				while(!ss.eof())
				{
					strTemp[0] = '\0';
					ss.getline(strTemp, 1024);
					//CCLog("line : %s", strTemp);
					strVal = strTemp;
					string_replace(strVal, "\r\n", "");
					string_replace(strVal, "\t" ," ");
					string_tripleft(strVal);

					std::string split = " ";

					int i0 = strVal.find_first_of(split);
					if (-1 == i0)
						continue;

					std::string def = strVal.substr(0, i0);

					strVal = strVal.substr(i0, strVal.length() - i0);
					string_tripleft(strVal);                    
					int i1 = strVal.find_first_of(split);
					if (-1 == i1)
						continue;                    
					std::string macro = strVal.substr(0, i1);

					std::string val = strVal.substr(i1, strVal.length() - i1);    
					string_tripleft(val);

					if (def.empty() == false && 
						val.empty() == false &&
						def.compare("#define") == 0 && 
						val.length() > 0)
					{
						string_replace(macro, " ", "");
						string_replace(val, " ", "");

						m_mapMacro2Value[macro] = atoi(val.c_str());
					}

					//CCLog("key : %s = Value %s\n", macro.c_str(), val.c_str());
				}

			} while (0);                                                
		}
Exemple #4
0
/**
 * @brief Covert characters that are unsafe for use in XML
 * @param [in] str The string to be converted
 * @return The converted string
 */
static String EscapeXML(const String &str)
{
	String escapedStr = str;
	string_replace(escapedStr, _T("&"), _T("&amp;"));
	string_replace(escapedStr, _T("<"), _T("&lt;"));
	string_replace(escapedStr, _T(">"), _T("&gt;"));
	return escapedStr;
}
Exemple #5
0
string string_remove_trademark(const string &s)
{
	string result = s;
	string_replace(result, "(TM)", "");
	string_replace(result, "(R)", "");

	return string_strip(result);
}
Exemple #6
0
static string line_directive(const string& path, int line)
{
	string escaped_path = path;
	string_replace(escaped_path, "\"", "\\\"");
	string_replace(escaped_path, "\'", "\\\'");
	string_replace(escaped_path, "\?", "\\\?");
	string_replace(escaped_path, "\\", "\\\\");
	return string_printf("#line %d \"%s\"", line, escaped_path.c_str());
}
/****************************************************************************
mount smbfs
****************************************************************************/
static void cmd_mount(char *inbuf,char *outbuf)
{
	pstring mpoint;
	pstring share_name;
	pstring mount_command;
	fstring buf;
	int retval;
	char mount_point[MAXPATHLEN+1];

	if (!next_token(NULL, mpoint, NULL))
	{
		DEBUG(0,("You must supply a mount point\n"));
		return;
	}

	memset(mount_point, 0, sizeof(mount_point));

	if (realpath(mpoint, mount_point) == NULL)
	{
		DEBUG(0, ("Could not resolve mount point\n"));
		return;
	}

	/*
	 * Build the service name to report on the Unix side,
	 * converting '\' to '/' and ' ' to '_'.
	 */
	pstrcpy(share_name, service);  
	string_replace(share_name, '\\', '/');
	string_replace(share_name, ' ', '_');

	slprintf(mount_command, sizeof(mount_command)-1,"smbmnt %s -s %s", mount_point, share_name);

	while(next_token(NULL, buf, NULL))
	{
		pstrcat(mount_command, " ");
		pstrcat(mount_command, buf);
	}

	DEBUG(3, ("mount command: %s\n", mount_command));

	/*
	 * Create the background process before trying the mount.
	 * (We delay closing files to allow diagnostic messages.)
	 */
	daemonize();

	/* The parent has exited here, the child handles the connection: */
	if ((retval = system(mount_command)) != 0)
	{
		DEBUG(0,("mount failed\n"));
		exit(1);
	}
	send_fs_socket(mount_point, inbuf, outbuf);
}	
Exemple #8
0
string string_remove_trademark(const string &s)
{
	string result = s;

	/* Special case, so we don;t leave sequential spaces behind. */
	/* TODO(sergey): Consider using regex perhaps? */
	string_replace(result, " (TM)", "");
	string_replace(result, " (R)", "");

	string_replace(result, "(TM)", "");
	string_replace(result, "(R)", "");

	return string_strip(result);
}
Exemple #9
0
static NOINLINE char* _expand_string( hash_t section_current, char* str )
{
	char* expanded;
	char* variable;
	unsigned int var_pos, var_end_pos, variable_length, separator, var_offset;
	hash_t section, key;

	expanded = str;
	var_pos = string_find_string( expanded, "$(", 0 );

	while( var_pos != STRING_NPOS )
	{
		var_end_pos = string_find( expanded, ')', var_pos + 2 );
		FOUNDATION_ASSERT_MSG( var_end_pos != STRING_NPOS, "Malformed config variable statement" );
		variable = string_substr( expanded, var_pos, ( var_end_pos != STRING_NPOS ) ? ( 1 + var_end_pos - var_pos ) : STRING_NPOS );

		section = section_current;
		key = 0;
		variable_length = string_length( variable );
		separator = string_find( variable, ':', 0 );
		if( separator != STRING_NPOS )
		{
			if( separator != 2 )
				section = hash( variable + 2, separator - 2 );
			var_offset = separator + 1;
		}
		else
		{
			var_offset = 2;
		}
		key = hash( variable + var_offset, variable_length - ( var_offset + ( variable[ variable_length - 1 ] == ')' ? 1 : 0 ) ) );

		if( expanded == str )
			expanded = string_clone( str );

		if( section != HASH_ENVIRONMENT )
			expanded = string_replace( expanded, variable, config_string( section, key ), false );
		else
			expanded = string_replace( expanded, variable, _expand_environment( key, variable + var_offset ), false );
		string_deallocate( variable );

		var_pos = string_find_string( expanded, "$(", 0 );
	}
#if BUILD_ENABLE_DEBUG_CONFIG
	if( str != expanded )
		log_debugf( HASH_CONFIG, "Expanded config value \"%s\" to \"%s\"", str, expanded );
#endif

	return expanded;
}
Exemple #10
0
char *notification_fix_markup(char *str)
{
    char *replace_buf, *start, *end;

    if (str == NULL) {
        return NULL;
    }

    str = string_replace_all("&quot;", "\"", str);
    str = string_replace_all("&apos;", "'", str);
    str = string_replace_all("&amp;", "&", str);
    str = string_replace_all("&lt;", "<", str);
    str = string_replace_all("&gt;", ">", str);

    /* remove tags */
    str = string_replace_all("<b>", "", str);
    str = string_replace_all("</b>", "", str);
    str = string_replace_all("<br>", " ", str);
    str = string_replace_all("<br/>", " ", str);
    str = string_replace_all("<br />", " ", str);
    str = string_replace_all("<i>", "", str);
    str = string_replace_all("</i>", "", str);
    str = string_replace_all("<u>", "", str);
    str = string_replace_all("</u>", "", str);
    str = string_replace_all("</a>", "", str);

    while ((start = strstr(str, "<a href")) != NULL) {
        end = strstr(start, ">");
        if (end != NULL) {
            replace_buf = strndup(start, end - start + 1);
            str = string_replace(replace_buf, "", str);
            free(replace_buf);
        } else {
            break;
        }
    }

    while ((start = strstr(str, "<img src")) != NULL) {
        end = strstr(start, "/>");
        if (end != NULL) {
            replace_buf = strndup(start, end - start + 2);
            str = string_replace(replace_buf, "", str);
            free(replace_buf);
        } else {
            break;
        }
    }
    return str;

}
Exemple #11
0
static void
run_fontsel_settings_dlg(SettingsWidget *sw) {
    GtkWidget *dlg;
    const gchar *newfont;
    gchar *oldfont;

    dlg = gtk_font_selection_dialog_new(_("Select font"));
    gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dlg),
                                            gtk_label_get_text(GTK_LABEL(sw->widget)));

    if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK) {
        gtk_label_set_text(GTK_LABEL(sw->widget),
                           gtk_font_selection_dialog_get_font_name(
                               GTK_FONT_SELECTION_DIALOG(dlg)));
    }


    newfont = gtk_label_get_text(GTK_LABEL(sw->widget));
    oldfont = pango_font_description_to_string(
                  pango_context_get_font_description(
                      gtk_widget_get_pango_context(GTK_WIDGET(sw->data))));

    if (newfont && g_ascii_strcasecmp(oldfont, newfont) != 0) {
        string_replace(sw->conf, g_strdup(newfont));
        jam_widget_set_font(sw->widget, newfont);
        jam_widget_set_font(sw->data, newfont);
    }
    g_free(oldfont);

    gtk_widget_destroy(dlg);
}
DBusMessage *
gkd_dbus_introspect_handle (DBusMessage *message,
                            const gchar *data,
                            const gchar **children)
{
	DBusMessage *reply;
	GString *output = NULL;
	gchar *nodes;

	g_return_val_if_fail (message, NULL);
	g_return_val_if_fail (data, NULL);

	if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect") &&
	    dbus_message_get_args (message, NULL, DBUS_TYPE_INVALID)) {

		if (children != NULL) {
			output = g_string_new (data);
			nodes = build_child_node_xml (dbus_message_get_path (message), children);
			if (!string_replace (output, "<!--@children@-->", nodes))
				g_warning ("introspection data contained no location for child nodes");
			g_free (nodes);
			data = output->str;
		}

		reply = dbus_message_new_method_return (message);
		if (!dbus_message_append_args (reply, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID))
			g_return_val_if_reached (NULL);

		if (output)
			g_string_free (output, TRUE);
		return reply;
	}

	return NULL;
}
Exemple #13
0
static int do_file(char *from, char *to, char *s, int verbose, int noact,
                   int nooverwrite, int interactive)
{
	char *newname = NULL, *file=NULL;
	int ret = 1;

	if (access(s, F_OK) != 0) {
		warn(_("%s: not accessible"), s);
		return 2;
	}

	if (strchr(from, '/') == NULL && strchr(to, '/') == NULL)
		file = strrchr(s, '/');
	if (file == NULL)
		file = s;
	if (string_replace(from, to, file, s, &newname) != 0)
		return 0;

	if ((nooverwrite || interactive) && access(newname, F_OK) != 0)
		nooverwrite = interactive = 0;

	if (nooverwrite || (interactive && (noact || ask(newname) != 0))) {
		if (verbose)
			printf(_("Skipping existing file: `%s'\n"), newname);
		ret = 0;
	}
	else if (!noact && rename(s, newname) != 0) {
		warn(_("%s: rename to %s failed"), s, newname);
		ret = 2;
	}
	if (verbose && (noact || ret == 1))
		printf("`%s' -> `%s'\n", s, newname);
	free(newname);
	return ret;
}
Exemple #14
0
TextData* BEE::Font::draw_internal(int x, int y, std::string text, RGBA color) {
	if (is_loaded) {
		if (text.size() > 0) {
			text = string_replace(text, "\t", "    ");

			SDL_Surface* tmp_surface;
			tmp_surface = TTF_RenderUTF8_Blended(font, text.c_str(), {color.r, color.g, color.b, color.a}); // Slow but pretty
			if (tmp_surface == nullptr) {
				game->messenger_send({"engine", "font"}, BEE_MESSAGE_WARNING, "Failed to draw with font \"" + name + "\": " + TTF_GetError());
				return nullptr;
			}

			Sprite* tmp_sprite = new Sprite();

			tmp_sprite->load_from_surface(tmp_surface);
			tmp_sprite->set_is_lightable(false);
			tmp_sprite->draw(x, y, 0, false);

			SDL_FreeSurface(tmp_surface);

			TextData* textdata = new TextData(tmp_sprite, text);

			return textdata;
		}

		return nullptr;
	}

	if (!has_draw_failed) {
		game->messenger_send({"engine", "font"}, BEE_MESSAGE_WARNING, "Failed to draw text with \"" + name + "\" because it is not loaded");
		has_draw_failed = true;
	}
	return nullptr;
}
Exemple #15
0
void
jam_doc_set_usejournal(JamDoc *doc, const gchar *usejournal) {
	gchar *uj = usejournal ? g_strdup(usejournal) : NULL;
	string_replace(&doc->usejournal, uj);
	jam_doc_user_changed(doc);
	g_object_notify(G_OBJECT(doc), "usejournal");
}
Exemple #16
0
TEST(String, Replace)
{
    char *str;

    WEE_TEST_STR(NULL, string_replace (NULL, NULL, NULL));
    WEE_TEST_STR(NULL, string_replace ("string", NULL, NULL));
    WEE_TEST_STR(NULL, string_replace (NULL, "search", NULL));
    WEE_TEST_STR(NULL, string_replace (NULL, NULL, "replace"));
    WEE_TEST_STR(NULL, string_replace ("string", "search", NULL));
    WEE_TEST_STR(NULL, string_replace ("string", NULL, "replace"));
    WEE_TEST_STR(NULL, string_replace (NULL, "search", "replace"));

    WEE_TEST_STR("test abc def", string_replace("test abc def", "xyz", "xxx"));
    WEE_TEST_STR("test xxx def", string_replace("test abc def", "abc", "xxx"));
    WEE_TEST_STR("xxx test xxx def xxx",
                 string_replace("abc test abc def abc", "abc", "xxx"));
}
void CPacketDlg::OnBnClickedButton1()
{
	//添加数据包
	CString strData;
	char szPacketData[MAX_RANDOM_PACKET] = {'\0'};

	if(m_pBaseDataLogic == NULL)
	{
		MessageBox(_T("必须指定m_pBaseDataLogic指针,指针不能为空。"));
		return;
	}

	m_txtPacketData.GetWindowText(strData);
	int nSrcLen = WideCharToMultiByte(CP_ACP, 0, strData, strData.GetLength(), NULL, 0, NULL, NULL);
	int nDecLen = WideCharToMultiByte(CP_ACP, 0, strData, nSrcLen, szPacketData, MAX_RANDOM_PACKET, NULL,NULL);
	szPacketData[nDecLen] = '\0';

	//获得接收字节数
	m_txtRecvLength.GetWindowText(strData);
	int nRecvLength = _ttoi(strData);

	if(nRecvLength <= 0)
	{
		MessageBox(_T("必须指定接收数据包的长度,否则无法发送。"));
		return;
	}

	if(((CButton *)GetDlgItem(IDC_RADIO1))->GetCheck() == 1)
	{
		//二进制模式2
		m_pBaseDataLogic->InsertRandomPacket(szPacketData, nDecLen, nRecvLength, 2);
	}
	else
	{
		//文本模式1
		string strFormatData = (string)szPacketData;

		//替换\r\n
		string_replace(strFormatData, "\\r", "\r");
		string_replace(strFormatData, "\\n", "\n");

		m_pBaseDataLogic->InsertRandomPacket(strFormatData.c_str(), strFormatData.length(), nRecvLength, 1);
	}

	ShowPacketList();
}
Exemple #18
0
// Format a time in milliseconds against a format string
char* timefmt(const char* format, ulong millis) {
    char* fmt = xstrdup(format);

    char str_rem_milliseconds_int[40];
    char str_rem_seconds_int[40];
    char str_rem_minutes_int[40];
    char str_rem_hours_int[40];
    char str_total_milliseconds[40];
    char str_total_seconds_int[40];
    char str_total_seconds_float[40];
    char str_total_minutes_int[40];
    char str_total_minutes_float[40];
    char str_total_hours_int[40];
    char str_total_hours_float[40];
    char str_total_days_int[40];
    char str_total_days_float[40];
    char str_start_time_millis[40];
    char str_start_time_seconds[40];

    ulong start_time_millis = (time(NULL) * 1000) - millis;
    
    sprintf(str_rem_milliseconds_int, "%03lu", (millis /       1) % 1000);
    sprintf(str_rem_seconds_int,      "%02lu", (millis /    1000) % 60);
    sprintf(str_rem_minutes_int,      "%02lu", (millis /   60000) % 60);
    sprintf(str_rem_hours_int,        "%02lu", (millis / 3600000) % 24);
    sprintf(str_total_milliseconds,   "%lu",   millis);
    sprintf(str_total_seconds_int,    "%lu",   millis / 1000);
    sprintf(str_total_seconds_float,  "%f",    millis / 1000.0);
    sprintf(str_total_minutes_int,    "%lu",   millis / 60000);
    sprintf(str_total_minutes_float,  "%f",    millis / 60000.0);
    sprintf(str_total_hours_int,      "%lu",   millis / 3600000);
    sprintf(str_total_hours_float,    "%f",    millis / 3600000.0);
    sprintf(str_total_days_int,       "%lu",   millis / 86400000);
    sprintf(str_total_days_float,     "%f",    millis / 86400000.0);
    sprintf(str_start_time_millis,    "%lu",   start_time_millis);
    sprintf(str_start_time_seconds,   "%lu",   start_time_millis / 1000);

    str_pair_t pairs[] = {
        (str_pair_t) { "%rms",  str_rem_milliseconds_int },
        (str_pair_t) { "%rsc",  str_rem_seconds_int },
        (str_pair_t) { "%rmn",  str_rem_minutes_int },
        (str_pair_t) { "%rhr",  str_rem_hours_int },
        (str_pair_t) { "%tms",  str_total_milliseconds },
        (str_pair_t) { "%tsci", str_total_seconds_int },
        (str_pair_t) { "%tscf", str_total_seconds_float },
        (str_pair_t) { "%tmni", str_total_minutes_int },
        (str_pair_t) { "%tmnf", str_total_minutes_float },
        (str_pair_t) { "%thri", str_total_hours_int },
        (str_pair_t) { "%thrf", str_total_hours_float },
        (str_pair_t) { "%tdyi", str_total_days_int },
        (str_pair_t) { "%tdyf", str_total_days_float },
        (str_pair_t) { "%stms", str_start_time_millis },
        (str_pair_t) { "%stsc", str_start_time_seconds },
        (str_pair_t) { NULL, NULL }
    };

    return string_replace(fmt, pairs, 1);
}
Exemple #19
0
void create_suffix(struct State *S, char *sfx)
{
        char times_str[28];
        char tau_fast_str[5];
        char delay_str[5];
        char *t1, *d1;
        sprintf(tau_fast_str, "%04.1f", S->ntw.tau_fast);
        sprintf(delay_str, "%4.2f", S->ntw.delay);
        t1 = string_replace(tau_fast_str, '.', 'p');
        d1 = string_replace(delay_str, '.', 'p');
        if (S->ntw.slow_flag)
                sprintf(times_str, "_delay_%s_T1_%s_T2_%d", d1, t1, (int) S->ntw.tau_slow);
        else
                sprintf(times_str, "_delay_%s_T1_%s", d1, t1);
        sprintf(S->sim.suffix, "%s", sfx);
        strcat(S->sim.suffix, times_str);
        strcat(S->sim.suffix, ".dat");
}
/* This function wraps g_date_time_format, replacing colon with the ratio
 * character and underscores with en-space as it looks visually better
 * in time strings.
 */
static char *
date_time_format (GDateTime *datetime,
                  const char *format)
{
	char *replaced_format;
	char *ret;
	char *no_ratio, *no_enspace;
	gboolean is_utf8;

	is_utf8 = g_get_charset (NULL);

	/* First, replace ratio with plain colon */
	no_ratio = string_replace (format, "∶", ":");
	/* Then do the same with en-space and underscore before passing it to
	 * g_date_time_format.  */
	no_enspace = string_replace (no_ratio, " ", "_");
	g_debug ("no_enspace: %s", no_enspace);
	replaced_format = g_date_time_format (datetime, no_enspace);
	g_debug ("replaced_format: %s", replaced_format);

	g_free (no_ratio);
	g_free (no_enspace);

	if (is_utf8) {
		char *tmp;
		/* Then, after formatting, replace the plain colon with ratio,
		 * and prepend it with an LTR marker to force direction. */
		tmp = string_replace (replaced_format, ":", "\xE2\x80\x8E∶");

		/* Finally, replace double spaces with a single en-space.*/
		ret = string_replace (tmp, "_", " ");

		g_free (tmp);
	} else {
		/* Colon instead of ratio is already fine, but replace the
		 * underscore with double spaces instead of en-space */
		ret = string_replace (replaced_format, "_", "  ");
	}

	g_free (replaced_format);
	g_debug ("is_utf8: %s", is_utf8 ? "TRUE" : "FALSE");
	g_debug ("ret: %s", ret);
	return ret;
}
Exemple #21
0
static void
exec_cmd(const char * base_cmd, const char * key)
{
	char * cmd;
	int ret;

	cmd = string_replace(base_cmd, "KEY", key);
	ret = system(cmd);
	if (ret  == -1) pfatal("system");	
}
Exemple #22
0
gchar *
um_realm_calculate_login (UmRealmCommon *realm,
                          const gchar *username)
{
        GString *string;
        const gchar *const *formats;
        gchar *login = NULL;

        formats = um_realm_common_get_login_formats (realm);
        if (formats[0] != NULL) {
                string = g_string_new (formats[0]);
                string_replace (string, "%U", username);
                string_replace (string, "%D", um_realm_common_get_name (realm));
                login = g_string_free (string, FALSE);
        }

        return login;

}
const std::string getMaskedParameter(const char* paramName){
    std::string paramValue = getParameter(paramName);
    for (std::map<std::string,std::string>::const_iterator param = parameters.begin(),
                                                     param_end = parameters.end();
                                                     param != param_end; ++param){
        const std::string mask = std::string("<") + param->first + ">";
        paramValue = string_replace(paramValue, mask, param->second);
    }
    return paramValue;
}
Exemple #24
0
static void fixtarname(char *tptr, const char *fp, size_t l)
{
	/* add a '.' to start of file name, convert from ugly dos \'s in path
	 * to lovely unix /'s :-} */
	*tptr++='.';
	l--;

	StrnCpy(tptr, fp, l-1);
	string_replace(tptr, '\\', '/');
}
Exemple #25
0
static void
command_changed_cb(GtkOptionMenu *omenu, SettingsWidget *sw) {
    CommandList *cmds = sw->data;
    int cur = gtk_option_menu_get_history(GTK_OPTION_MENU(sw->widget));

    jam_widget_set_visible(sw->data2, cmds[cur].label == NULL);
    if (cmds[cur].label != NULL) {
        const char *cmd = cmds[cur].command;
        string_replace((char**)sw->conf, cmd ? g_strdup(cmd) : NULL);
        gtk_entry_set_text(GTK_ENTRY(sw->subwidget), cmd ? cmd : "");
    }
}
Exemple #26
0
gboolean
jam_doc_save_as_draft(JamDoc *doc, const char *title, JamAccount *acc, GError **err) {
	LJEntry *entry;
	
	entry = jam_doc_get_entry(doc);
	string_replace(&entry->subject, g_strdup(title));
	entry->itemid = 0;
	if (!save_draft(entry, acc, err)) {
		lj_entry_free(entry);
		return FALSE;
	}
	/* retrieve the new draft id. */
	doc->entry->itemid = entry->itemid;
	lj_entry_free(entry);

	string_replace(&doc->filename, NULL);

	jam_doc_set_dirty(doc, FALSE);

	return TRUE;
}
Exemple #27
0
gboolean
conf_rename_host(JamHost *host, const char *newname, GError **err) {
	char *oldpath, *newpath;

	/* disallow:
	 *   [empty string]
	 *   .
	 *   ..
	 *   ./../foo
	 *   /foo
	 * allow:
	 *   .lAmE.sErVeR.
	 */
	if ((newname[0] == 0) ||
			(newname[0] == '.' &&
				(newname[1] == '.' || newname[1] == '/' || newname[1] == 0)) ||
			(newname[0] == '/')) {
		g_set_error(err, 0, 0, _("new host name is invalid"));
		return FALSE;
	}
	oldpath = g_build_filename(app.conf_dir, "servers", host->name, NULL);
	if (!g_file_test(oldpath, G_FILE_TEST_EXISTS)) {
		string_replace(&host->name, g_strdup(newname));
		g_free(oldpath);
		return TRUE;
	}
	newpath = g_build_filename(app.conf_dir, "servers", newname, NULL);
	if (rename(oldpath, newpath) < 0) {
		g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errno),
				_("renaming '%s' to '%s': %s"), oldpath, newpath,
				g_strerror(errno));
		g_free(oldpath);
		g_free(newpath);
		return FALSE;
	}
	string_replace(&host->name, g_strdup(newname));
	g_free(oldpath);
	g_free(newpath);
	return TRUE;
}
ExternalPlugin* external_plugin_construct (GType object_type, DBusGConnection* connection, const char* service_name) {
	GError * _inner_error_;
	ExternalPlugin * self;
	char* _tmp0_;
	char* _tmp1_;
	char* root_object;
	DBusGProxy* props;
	GValue value = {0};
	GValue _tmp3_ = {0};
	GValue _tmp2_ = {0};
	const char* _tmp4_;
	char* title;
	char* _tmp6_;
	const char* _tmp5_;
	char* _tmp8_;
	const char* _tmp7_;
	RygelResourceInfo* resource_info;
	g_return_val_if_fail (connection != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_inner_error_ = NULL;
	_tmp0_ = NULL;
	_tmp1_ = NULL;
	root_object = (_tmp1_ = g_strconcat ("/", _tmp0_ = string_replace (service_name, ".", "/"), NULL), _tmp0_ = (g_free (_tmp0_), NULL), _tmp1_);
	props = dbus_g_proxy_new_for_name (connection, service_name, root_object, EXTERNAL_PLUGIN_PROPS_IFACE);
	_dynamic_Get4 (props, EXTERNAL_PLUGIN_OBJECT_IFACE, "DisplayName", &_tmp2_, &_inner_error_);
	value = (_tmp3_ = _tmp2_, G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL, _tmp3_);
	if (_inner_error_ != NULL) {
		root_object = (g_free (root_object), NULL);
		(props == NULL) ? NULL : (props = (g_object_unref (props), NULL));
		G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
		g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, _inner_error_->message);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp4_ = NULL;
	title = (_tmp4_ = g_value_get_string (&value), (_tmp4_ == NULL) ? NULL : g_strdup (_tmp4_));
	self = (ExternalPlugin*) rygel_plugin_construct (object_type, service_name, title);
	_tmp6_ = NULL;
	_tmp5_ = NULL;
	self->service_name = (_tmp6_ = (_tmp5_ = service_name, (_tmp5_ == NULL) ? NULL : g_strdup (_tmp5_)), self->service_name = (g_free (self->service_name), NULL), _tmp6_);
	_tmp8_ = NULL;
	_tmp7_ = NULL;
	self->root_object = (_tmp8_ = (_tmp7_ = root_object, (_tmp7_ == NULL) ? NULL : g_strdup (_tmp7_)), self->root_object = (g_free (self->root_object), NULL), _tmp8_);
	resource_info = rygel_resource_info_new (RYGEL_CONTENT_DIRECTORY_UPNP_ID, RYGEL_CONTENT_DIRECTORY_UPNP_TYPE, RYGEL_CONTENT_DIRECTORY_DESCRIPTION_PATH, RYGEL_TYPE_EXTERNAL_CONTENT_DIR);
	rygel_plugin_add_resource ((RygelPlugin*) self, resource_info);
	root_object = (g_free (root_object), NULL);
	(props == NULL) ? NULL : (props = (g_object_unref (props), NULL));
	G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
	title = (g_free (title), NULL);
	(resource_info == NULL) ? NULL : (resource_info = (rygel_resource_info_unref (resource_info), NULL));
	return self;
}
Exemple #29
0
std::string player_morale::morale_point::get_name() const
{
    std::string name = get_morale_data( type );

    if( item_type != nullptr ) {
        name = string_replace( name, item_name_placeholder, item_type->nname( 1 ) );
    } else if( name.find( item_name_placeholder ) != std::string::npos ) {
        debugmsg( "Morale #%d (%s) requires item_type to be specified.", type,
                  name.c_str() );
    }

    return name;
}
Exemple #30
0
// Xml encode the passed string
String xdebug_xmlize(char *string, int len) {
  String str(string, CopyString);
  if (len) {
    str = string_replace(str, "&","&amp;");
    str = string_replace(str, ">", "&gt;");
    str = string_replace(str, "<", "&lt;");
    str = string_replace(str, "\"", "&quot;");
    str = string_replace(str, "'", "&#39;");
    str = string_replace(str, "\n", "&#10;");
    str = string_replace(str, "\r", "&#13;");
    str = string_replace(str, "\0", "&#0;");
    return str;
  }
  return str;
}