Example #1
0
/* Load a sub module. */
int module_load_sub(const char *path, const char *submodule, char **prefixes)
{
        GString *full_path;
	char *exppath, *name, *rootmodule;
        int start, end, ret;

	g_return_val_if_fail(path != NULL, FALSE);
	g_return_val_if_fail(submodule != NULL, FALSE);

        exppath = convert_home(path);

	name = module_get_name(exppath, &start, &end);
	rootmodule = module_get_root(name, prefixes);
	g_free(name);

        full_path = g_string_new(exppath);
	if (strcmp(submodule, "core") == 0)
		g_string_insert(full_path, end, "_core");
	else {
		g_string_insert_c(full_path, start, '_');
		g_string_insert(full_path, start, submodule);
	}

	ret = module_load_full(full_path->str, rootmodule, submodule,
			       start, end, NULL);

	g_string_free(full_path, TRUE);
	g_free(rootmodule);
	g_free(exppath);
        return ret;
}
Example #2
0
void PE_escape_name(GString* name) {
   int pos = 0;

   // Note: name->len and name->str can change as we modify name...
   while (pos < name->len) {
      switch (name->str[pos]) {
      case ' ':
         // space -> "\s"
         g_string_erase(name, pos, 1);
         g_string_insert(name, pos, "\\s");
         pos += 2;
         break;
      case ',':
         // comma -> "\c"
         g_string_erase(name, pos, 1);
         g_string_insert(name, pos, "\\c");
         pos += 2;         
         break;
      case '\\':
         // backslash -> "\\"
         g_string_erase(name, pos, 1);
         g_string_insert(name, pos, "\\");
         pos += 2;         
         break;
      default:
         ++pos;
         break;
      }
   }
}
Example #3
0
static void
escape_string (GString *string)
{
  const char *p = string->str;
  gunichar wc;

  while (p < string->str + string->len)
    {
      gboolean safe;
	    
      wc = g_utf8_get_char_validated (p, -1);
      if (wc == (gunichar)-1 || wc == (gunichar)-2)  
	{
	  gchar *tmp;
	  guint pos;

	  pos = p - string->str;

	  /* Emit invalid UTF-8 as hex escapes 
           */
	  tmp = g_strdup_printf ("\\x%02x", (guint)(guchar)*p);
	  g_string_erase (string, pos, 1);
	  g_string_insert (string, pos, tmp);

	  p = string->str + (pos + 4); /* Skip over escape sequence */

	  g_free (tmp);
	  continue;
	}
      if (wc == '\r')
	{
	  safe = *(p + 1) == '\n';
	}
      else
	{
	  safe = CHAR_IS_SAFE (wc);
	}
      
      if (!safe)
	{
	  gchar *tmp;
	  guint pos;

	  pos = p - string->str;
	  
	  /* Largest char we escape is 0x0a, so we don't have to worry
	   * about 8-digit \Uxxxxyyyy
	   */
	  tmp = g_strdup_printf ("\\u%04x", wc); 
	  g_string_erase (string, pos, g_utf8_next_char (p) - p);
	  g_string_insert (string, pos, tmp);
	  g_free (tmp);

	  p = string->str + (pos + 6); /* Skip over escape sequence */
	}
      else
	p = g_utf8_next_char (p);
    }
}
Example #4
0
void
nemo_action_activate (NemoAction *action, GList *selection, NemoFile *parent)
{
    GList *l;
    GString *exec = g_string_new (action->exec);

    gchar *ptr;
    TokenType token_type;

    ptr = find_token_type (exec->str, &token_type);

    while (ptr != NULL) {
        gint shift = ptr - exec->str;

        gchar *insertion = get_insertion_string (token_type, selection, parent);
        exec = g_string_erase (exec, shift, 2);
        exec = g_string_insert (exec, shift, insertion);

        token_type = TOKEN_NONE;
        g_free  (insertion);
        ptr = find_token_type (exec->str, &token_type);
    }

    if (action->use_parent_dir) {
        exec = g_string_prepend (exec, G_DIR_SEPARATOR_S);
        exec = g_string_prepend (exec, action->parent_dir);
    }

    DEBUG ("Spawning: %s\n", exec->str);
    g_spawn_command_line_async (exec->str, NULL);

    nemo_file_list_free (selection);
    g_string_free (exec, TRUE);
}
Example #5
0
/**
 * Replaces all instances of before with after in the supplied source
 * string.
 *
 * @return the number of replacements made.
 */
static
guint g_string_replace (GString* source, const gchar* before,
			const gchar* after)
{
    gchar* pos;
    gchar* spot;
    guint beflen = strlen(before);
    guint aftlen = strlen(after);
    guint replacements = 0;

    /* sanity checks */
    g_return_val_if_fail(source != NULL, 0);
    g_return_val_if_fail(before != NULL, 0);
    g_return_val_if_fail(after != NULL, 0);
    g_return_val_if_fail(beflen > 0, 0);

    pos = source->str;
    while ((spot = strstr(pos, before)) != NULL) {
	replacements++;
	/* erase the match and insert the new stuff */
	g_string_erase(source, spot-source->str, beflen);
	g_string_insert(source, spot-source->str, after);
	/* move the pointer on up */
	pos += spot-source->str + aftlen;
    }

    return replacements;
}
Example #6
0
/* add argument to specified position */
static void mode_add_arg(GString *str, int pos, int updating, const char *arg)
{
	char *p;

	for (p = str->str; *p != '\0'; p++) {
		if (*p != ' ')
			continue;

		if (pos == 0)
			break;
		pos--;
	}

	pos = (int) (p-str->str);
	if (updating && *p != '\0') {
		/* remove the old argument */
                p++;
		while (*p != '\0' && *p != ' ') p++;
                g_string_erase(str, pos, (int) (p-str->str)-pos);
	}

	/* .. GLib shouldn't fail when inserting at the end of the string */
	if (pos == str->len) {
		g_string_append_c(str, ' ');
		g_string_append(str, arg);
	} else {
		g_string_insert_c(str, pos, ' ');
		g_string_insert(str, pos+1, arg);
	}
}
Example #7
0
/**
 * g_dbus_address_escape_value:
 * @string: an unescaped string to be included in a D-Bus address
 *     as the value in a key-value pair
 *
 * Escape @string so it can appear in a D-Bus address as the value
 * part of a key-value pair.
 *
 * For instance, if @string is "/run/bus-for-:0",
 * this function would return "/run/bus-for-%3A0",
 * which could be used in a D-Bus address like
 * "unix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-%3A0".
 *
 * Returns: (transfer full): a copy of @string with all
 *     non-optionally-escaped bytes escaped
 *
 * Since: 2.36
 */
gchar *
g_dbus_address_escape_value (const gchar *string)
{
  GString *s;
  gsize i;

  g_return_val_if_fail (string != NULL, NULL);

  /* There will often not be anything needing escaping at all. */
  s = g_string_sized_new (strlen (string));

  /* D-Bus address escaping is mostly the same as URI escaping... */
  g_string_append_uri_escaped (s, string, "\\/", FALSE);

  /* ... but '~' is an unreserved character in URIs, but a
   * non-optionally-escaped character in D-Bus addresses. */
  for (i = 0; i < s->len; i++)
    {
      if (G_UNLIKELY (s->str[i] == '~'))
        {
          s->str[i] = '%';
          g_string_insert (s, i + 1, "7E");
          i += 2;
        }
    }

  return g_string_free (s, FALSE);
}
Example #8
0
/* automatic word completion - called when space/enter is pressed */
char *auto_word_complete(const char *line, int *pos)
{
	GString *result;
	const char *replace;
	char *word, *wordstart, *ret;
	int startpos;

	g_return_val_if_fail(line != NULL, NULL);
	g_return_val_if_fail(pos != NULL, NULL);

	word = get_word_at(line, *pos, &wordstart);
	startpos = (int) (wordstart-line);

	result = g_string_new(line);
	g_string_erase(result, startpos, strlen(word));

	/* check for words in autocompletion list */
	replace = wordreplace_find(word);
	if (replace == NULL) {
		ret = NULL;
		g_string_free(result, TRUE);
	} else {
		*pos = startpos+strlen(replace);

		g_string_insert(result, startpos, replace);
		ret = result->str;
		g_string_free(result, FALSE);
	}

	g_free(word);
	return ret;
}
Example #9
0
static void overwrite (GString *gstr, char *text_to_insert, guint32 p1, guint32 p2) {

    glong len, ins_len;
    gsize pos;
    gchar *ins_str = NULL;

    if (p1 == p2)
        return;

    if (p1 > p2) {
        pos = p2;
        len = p1 - p2;
    }
    else{
        pos = p1;
        len = p2 - p1;
    }

    ins_len = g_utf8_strlen(text_to_insert, -1);
    if (len > ins_len) {
        len = ins_len;
    } else if (len < ins_len) {
        ins_str = g_utf8_substring(text_to_insert, 0, len);
    }

    if (!ins_str) ins_str = g_strdup(text_to_insert);

    if (pos > gstr->len)
        pos = gstr->len;

    g_string_erase(gstr, pos, len);

    g_string_insert(gstr, pos, ins_str);
    g_free(ins_str);
}
Example #10
0
static void handle_multi_line(struct web_session *session)
{
	gsize count;
	char *str;
	gchar *value;

	str = session->current_header->str;

	if (str[0] != ' ' && str[0] != '\t')
		return;

	while (str[0] == ' ' || str[0] == '\t')
		str++;

	count = str - session->current_header->str;
	if (count > 0) {
		g_string_erase(session->current_header, 0, count);
		g_string_insert_c(session->current_header, 0, ' ');
	}

	value = g_hash_table_lookup(session->result.headers,
					session->result.last_key);
	if (value != NULL) {
		g_string_insert(session->current_header, 0, value);

		str = session->current_header->str;

		g_hash_table_replace(session->result.headers,
					g_strdup(session->result.last_key),
					g_strdup(str));
	}
}
Example #11
0
/* Replace all occurences of from in string str to to. */
void
LGSD(replace_all) (gchar **str, gchar *from, gchar *to)
{
	GString *newstr;
	gchar *found;

	g_return_if_fail (str != NULL);
	g_return_if_fail (from != NULL);
	g_return_if_fail (to != NULL);

	newstr = g_string_new (*str);
	found = strstr (newstr->str, from);
	while (found != NULL)
	{
		gint pos;

		pos = found - newstr->str;
		g_string_erase (newstr, pos, strlen (from));
		g_string_insert (newstr, pos, to);
		found = newstr->str + pos + strlen (to);
		found = strstr (found, from);
	}

	g_free (*str);
	*str = newstr->str;
	g_string_free (newstr, FALSE);
}
Example #12
0
/**
 @brief convert an integer to hebrew string UTF-8 (logical)

 @param n The int to convert
 @attention ( 0 < n < 10000)
 @warning uses a static string, so output should be copied away.
*/
void
hdate_int_to_hebrew (GString *res, int n)
{
	int oldlen = res->len;
	int length;
	static const char *digits[3][10] = {
		{" ", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט"},
		{"ט", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ"},
		{" ", "ק", "ר", "ש", "ת"}
	};

	/* sanity checks */
	if (n < 1 || n > 10000)
	{
		return;
	}

	if (n >= 1000)
	{
		g_string_append (res, digits[0][n / 1000]);
		n %= 1000;
	}
	while (n >= 400)
	{
		g_string_append (res, digits[2][4]);
		n -= 400;
	}
	if (n >= 100)
	{
		g_string_append (res, digits[2][n / 100]);
		n %= 100;
	}
	if (n >= 10)
	{
		if (n == 15 || n == 16)
			n -= 9;
		g_string_append (res, digits[1][n / 10]);
		n %= 10;
	}
	if (n > 0)
		g_string_append (res, digits[0][n]);

	length = g_utf8_strlen (res->str + oldlen, -1);

	/* Note: length is in characters */

	/* add the ' and " to hebrew numbers */
	if (length < 2)
		g_string_append (res, UNICODE_GERESH);
	else
		g_string_insert
			(res,
			 g_utf8_offset_to_pointer (res->str + oldlen,
						   length - 1) - res->str,
			 UNICODE_GERSHAYIM);
}
Example #13
0
void gui_entry_insert_text(const char *str)
{
	g_return_if_fail(str != NULL);

	g_string_insert(entry, pos, str);
	pos += strlen(str);

	entry_screenpos();
	entry_update();
}
Example #14
0
/* Overwrite the char in the working command line at pos in command;
   realloc if necessary. */
gboolean cmd_overwrite_char(struct cmdline* cmd, gchar c,
		gboolean preserve_CR) {


	if (preserve_CR) {
		/* Preserve ^Ms. */
			while (*(cmd->data->str + cmd->pos) == '\015')
				cmd->pos++;
	}

	if (cmd->is_utf8) {
		/* We examine each byte individually, but UTF-8 characters can be
		   multibyte.  So conserve a string of characters until a valid
		   UTF-8 char is created. */
		static GString* utf8_char = NULL;
		if (!utf8_char)
			utf8_char = g_string_new(NULL);

		utf8_char = g_string_append_c(utf8_char, c);

		if (g_utf8_validate(utf8_char->str, utf8_char->len, NULL)) {
			/* The UTF-8 character has been completed and it's time to put it
			   onto the command line. */

			if (cmd->pos == cmd->data->len) {
				/* We're at the end - just append the "character". */
				cmd->data = g_string_append(cmd->data, utf8_char->str);
			}
			else {
				/* We need to overwrite data.  Since the characters might not
				   be the same length, erase the old one first and then insert
				   the new one. */
				gchar* next = g_utf8_next_char(cmd->data->str + cmd->pos);
				gsize erase_len = next - (cmd->data->str + cmd->pos);
				cmd->data = g_string_erase(cmd->data, cmd->pos, erase_len);
				cmd->data = g_string_insert(cmd->data, cmd->pos,
						utf8_char->str);
			}

			cmd->pos += utf8_char->len;
			g_string_truncate(utf8_char, 0);
		}

	}
	else {
		if (cmd->pos == cmd->data->len)
			cmd->data = g_string_append_c(cmd->data, c);
		else
			*(cmd->data->str + cmd->pos) = c;
		cmd->pos++;
	}

	action_queue(A_SEND_CMD);
	return TRUE;
}
Example #15
0
static int module_load_prefixes(const char *path, const char *module,
				int start, int end, char **prefixes)
{
        GString *realpath;
        int status, ok;

        /* load module_core */
	realpath = g_string_new(path);
	g_string_insert(realpath, end, "_core");

	/* Don't print the error message the first time, since the module
	   may not have the core part at all. */
	status = module_load_name(realpath->str, module, "core", TRUE);
        ok = status > 0;

	if (prefixes != NULL) {
		/* load all the "prefix modules", like the fe-common, irc,
		   etc. part of the module */
		while (*prefixes != NULL) {
                        g_string_assign(realpath, path);
			g_string_insert_c(realpath, start, '_');
			g_string_insert(realpath, start, *prefixes);

			status = module_load_name(realpath->str, module,
						  *prefixes, TRUE);
			if (status > 0)
				ok = TRUE;

                        prefixes++;
		}
	}

	if (!ok) {
                /* error loading module, print the error message */
		g_string_assign(realpath, path);
		g_string_insert(realpath, end, "_core");
		module_load_name(realpath->str, module, "core", FALSE);
	}

	g_string_free(realpath, TRUE);
        return ok;
}
Example #16
0
static gchar* _scalliontor_getFormatedArg(gchar* argString, const gchar* home, const gchar* hostname) {
	gchar* found = NULL;
	GString* sbuffer = g_string_new(argString);

	/* replace all ~ with the home directory */
	while((found = g_strstr_len(sbuffer->str, sbuffer->len, "~"))) {
		gssize position = (gssize) (found - sbuffer->str);
		sbuffer = g_string_erase(sbuffer, position, (gssize) 1);
		sbuffer = g_string_insert(sbuffer, position, home);
	}

	/* replace all ${NODEID} with the hostname */
	while((found = g_strstr_len(sbuffer->str, sbuffer->len, "${NODEID}"))) {
		gssize position = (gssize) (found - sbuffer->str);
		sbuffer = g_string_erase(sbuffer, position, (gssize) 9);
		sbuffer = g_string_insert(sbuffer, position, hostname);
	}

	return g_string_free(sbuffer, FALSE);
}
Example #17
0
static gboolean
xlsx_func_hypgeomdist_output_handler (GnmConventionsOut *out, GnmExprFunction const *func)
{
	/* The cumulative flag is not optional.  */
	if (func->argc != 5) {
		g_string_append (out->accum, "_xlfn.HYPGEOM.DIST");
		gnm_expr_list_as_string (func->argc, func->argv, out);
		g_string_insert (out->accum, out->accum->len - 1, ",FALSE");
		return TRUE;
	}
	return FALSE;
}
Example #18
0
static void
cli_info_pad_source (GString *sb, gint source_width, const gchar *source)
{
	gint i, length;

	g_string_truncate (sb, 0);

	length = strlen (source);
	for (i = 0; i < (source_width - length); i++) {
		g_string_insert_c (sb, i, ' ');
	}
	g_string_insert (sb, i, source);
}
Example #19
0
static gboolean
string_replace (GString *string,
                const gchar *search,
                const gchar *replace)
{
	const gchar *pos;

	pos = strstr (string->str, search);
	if (pos == NULL)
		return FALSE;

	g_string_erase (string, pos - string->str, strlen (search));
	g_string_insert (string, pos - string->str, replace);
	return TRUE;
}
Example #20
0
int	main(int argc, char *argv[])
{
	GString *s;
	s = g_string_new("Hello");
	g_print("%s\n", s->str);
	s = g_string_append(s," World!");
	g_print("%s\n",s->str);
	s = g_string_erase(s,0,6);
	g_print("%s\n",s->str);
	s = g_string_prepend(s,"Also a ");
	g_print("%s\n",s->str);
	
	s = g_string_insert(s,6," Nice");
	g_print("%s\n",s->str);
}
Example #21
0
static void
string_replace (GString *string,
                const gchar *find,
                const gchar *replace)
{
        const gchar *at;
        gssize pos;

        at = strstr (string->str, find);
        if (at != NULL) {
                pos = at - string->str;
                g_string_erase (string, pos, strlen (find));
                g_string_insert (string, pos, replace);
        }
}
Example #22
0
static void
on_relative_path_entry_insert_text (GtkEditable            *editable,
                                    gchar                  *new_text,
                                    gint                    new_text_length,
                                    gint                   *position,
                                    GladeProjectProperties *properties) 
{
  GString *fullpath = g_string_new (gtk_entry_get_text (GTK_ENTRY(editable)));

  g_string_insert (fullpath, *position, new_text);
  
  if (g_path_is_absolute (fullpath->str))
    g_signal_stop_emission_by_name (editable, "insert-text");
  
  g_string_free (fullpath, TRUE);
}
Example #23
0
/**
 * @brief get_spotify_artist_albums Get the number of artist albums on Spotify
 * @param spotify_uri Spotify uri for the artist
 * @return Number of number of artist albums on Spotify
 */
guint get_spotify_artist_albums(const gchar *spotify_uri){
  GString *url = g_string_new(ARTIST_LOOKUP_URI);
  url = g_string_insert(url, 41, spotify_uri);

  GError *error = NULL;
  JsonParser *parser = json_parser_new(); 
  GFile * file = g_file_new_for_uri(url->str);

  g_print("Opening %s for reading\n", url->str);
  GInputStream * fis = (GInputStream*)g_file_read (file, NULL, &error);
  g_print("Opened!\n");

  if (error){
    g_debug("** ERROR **: %s (domain: %s, code: %d) at %d (in get_spotify_artist_albums)\n", \
	     error->message, g_quark_to_string (error->domain), error->code, \
	     __LINE__);
    g_object_unref(file);
    g_object_unref(fis);
    g_object_unref (parser);
    g_string_free(url, TRUE);
    return 0;
  }

  json_parser_load_from_stream(parser, fis, NULL, &error);
  if (error){
    g_debug("Unable to parse `%s': %s\n", url->str, error->message);
    g_object_unref(file);
    g_object_unref(fis);
    g_object_unref (parser);
    g_string_free(url, TRUE);
    return 0;
  }

  JsonNode *root = json_parser_get_root(parser);
  JsonObject * content = json_node_get_object(root);
  JsonNode * node = json_object_get_member(content, "artist");
  content = json_node_get_object(node);
  node = json_object_get_member(content, "albums");
  JsonArray * AlbumsArray = json_node_get_array(node);
  guint AlbumsArrayLength = json_array_get_length(AlbumsArray);

  g_object_unref(file);
  g_object_unref(fis);
  g_object_unref (parser);
  g_string_free(url, TRUE);
  return AlbumsArrayLength;
}
Example #24
0
static gboolean writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused)
{
	GString *t;
	GList *iter, *urls, *next;
	int c = 0;

	if (purple_message_get_flags(msg) & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE))
		return FALSE;

	urls = g_object_get_data(G_OBJECT(conv), "TinyURLs");
	if (urls != NULL) /* message was cancelled somewhere? Reset. */
		g_list_foreach(urls, free_urls, NULL);
	g_list_free(urls);
	urls = extract_urls(purple_message_get_contents(msg));
	if (!urls)
		return FALSE;

	t = g_string_new(g_strdup(purple_message_get_contents(msg)));
	for (iter = urls; iter; iter = next) {
		next = iter->next;
		if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) {
			int pos, x = 0;
			gchar *j, *s, *str, *orig;
			glong len = g_utf8_strlen(iter->data, -1);
			s = g_strdup(t->str);
			orig = s;
			str = g_strdup_printf("[%d]", ++c);
			while ((j = strstr(s, iter->data))) { /* replace all occurrences */
				pos = j - orig + (x++ * 3);
				s = j + len;
				t = g_string_insert(t, pos + len, str);
				if (*s == '\0') break;
			}
			g_free(orig);
			g_free(str);
			continue;
		} else {
			g_free(iter->data);
			urls = g_list_delete_link(urls, iter);
		}
	}
	purple_message_set_contents(msg, t->str);
	g_string_free(t, TRUE);
	if (conv != NULL)
		g_object_set_data(G_OBJECT(conv), "TinyURLs", urls);
	return FALSE;
}
Example #25
0
static gchar *
as_node_insert_line_breaks (const gchar *text, guint break_len)
{
	GString *str;
	guint i;
	guint new_len;

	/* allocate long enough for the string, plus the extra newlines */
	new_len = strlen (text) * (break_len + 1) / break_len;
	str = g_string_new_len (NULL, new_len + 2);
	g_string_append (str, "\n");
	g_string_append (str, text);

	/* insert a newline every break length */
	for (i = break_len + 1; i < str->len; i += break_len + 1)
		g_string_insert (str, i, "\n");
	g_string_append (str, "\n");
	return g_string_free (str, FALSE);
}
Example #26
0
void channel_set_singlemode(IRC_CHANNEL_REC *channel, const char *nicks,
			    const char *mode)
{
	GString *str;
	int num, modepos;
	char **nick, **nicklist;

	g_return_if_fail(IS_IRC_CHANNEL(channel));
	g_return_if_fail(nicks != NULL && mode != NULL);
	if (*nicks == '\0') return;

	num = modepos = 0;
	str = g_string_new(NULL);

	nicklist = g_strsplit(nicks, " ", -1);
	for (nick = nicklist; *nick != NULL; nick++) {
		if (**nick == '\0')
			continue;

		if (num == 0)
		{
			g_string_sprintf(str, "MODE %s %s",
					 channel->name, mode);
			modepos = str->len;
		} else {
			/* insert the mode string */
			g_string_insert(str, modepos, mode);
		}

		g_string_sprintfa(str, " %s", *nick);

		if (++num == channel->server->max_modes_in_cmd) {
			/* max. modes / command reached, send to server */
			irc_send_cmd(channel->server, str->str);
			num = 0;
		}
	}
	if (num > 0) irc_send_cmd(channel->server, str->str);

	g_strfreev(nicklist);
	g_string_free(str, TRUE);
}
Example #27
0
/**
 * @brief Pastes text content from clipboard into entry
 *
 * @param text an AtkEditableText
 * @param position start position of cursor
 */
static void
eail_multibuttonentry_paste_text(AtkEditableText *text,
                                 gint position)
{
   Evas_Object *widget;
   Evas_Object *entry = NULL;
   GString *s;
   const char *tmp;

   widget = eail_widget_get_widget(EAIL_WIDGET(text));
   if (!widget || !elm_multibuttonentry_editable_get(entry))
     return;

   entry = elm_multibuttonentry_entry_get(widget);
   s = g_string_new(elm_entry_entry_get(entry));
   tmp = eail_clipboard_get_text();
   s = g_string_insert(s, position, tmp);
   elm_entry_entry_set(entry, s->str);
   g_string_free(s, TRUE);
}
Example #28
0
static void add_header_field(struct web_session *session)
{
	gsize count;
	guint8 *pos;
	char *str;
	gchar *value;
	gchar *key;

	str = session->current_header->str;

	pos = memchr(str, ':', session->current_header->len);
	if (pos != NULL) {
		*pos = '\0';
		pos++;

		key = g_strdup(str);

		/* remove preceding white spaces */
		while (*pos == ' ')
			pos++;

		count = (char *) pos - str;

		g_string_erase(session->current_header, 0, count);

		value = g_hash_table_lookup(session->result.headers, key);
		if (value != NULL) {
			g_string_insert_c(session->current_header, 0, ' ');
			g_string_insert_c(session->current_header, 0, ';');

			g_string_insert(session->current_header, 0, value);
		}

		str = session->current_header->str;
		g_hash_table_replace(session->result.headers, key,
							g_strdup(str));

		g_free(session->result.last_key);
		session->result.last_key = g_strdup(key);
	}
}
Example #29
0
static GString *
expand_action_string (NemoAction *action, GList *selection, NemoFile *parent, GString *str)
{
    gchar *ptr;
    TokenType token_type;

    ptr = find_token_type (str->str, &token_type);

    while (ptr != NULL) {
        gint shift = ptr - str->str;

        gchar *insertion = get_insertion_string (action, token_type, selection, parent);
        str = g_string_erase (str, shift, 2);
        str = g_string_insert (str, shift, insertion);

        token_type = TOKEN_NONE;
        g_free  (insertion);
        ptr = find_token_type (str->str, &token_type);
    }

    return str;
}
Example #30
0
/* set the comment, setting to NULL is allowed, or changing */
void gtodo_todo_item_set_comment(GTodoItem *item, gchar *comment)
{
	if(comment == NULL)
	{
		if(item->comment != NULL) g_free(item->comment);
		item->comment = NULL;
	}
	else{
		GString *string;
		int i;
		string = g_string_new(comment);
		for(i=0;i < string->len;i++)
		{
			if(string->str[i] == '&')
			{
				g_string_insert(string, i+1, "amp;");
			}
		}
		if(item->comment != NULL) g_free(item->comment);
		item->comment = string->str;
		g_string_free(string, FALSE);
	}
}