Ejemplo n.º 1
0
static gchar * request_master_m3u8_playlist (HTTPStreaming *httpstreaming, RequestData *request_data)
{
        gchar *master_m3u8_playlist, *buf, *replace;
        GRegex *regex;

        /* master m3u8 request? */
        buf = gstreamill_get_master_m3u8playlist (httpstreaming->gstreamill, request_data->uri);
        regex = g_regex_new ("(<%parameters%>)", 0, 0, NULL);
        if (g_strcmp0 (request_data->parameters, "") == 0) {
                master_m3u8_playlist = g_regex_replace (regex, buf, -1, 0, "", 0, NULL);

        } else {
                replace = g_strdup_printf ("?%s", request_data->parameters);
                master_m3u8_playlist = g_regex_replace (regex, buf, -1, 0, replace, 0, NULL);
                g_free (replace);
        }
        g_free (buf);
        g_regex_unref (regex);
        if (master_m3u8_playlist != NULL) {
                buf = g_strdup_printf (http_200,
                               PACKAGE_NAME,
                               PACKAGE_VERSION,
                               "application/vnd.apple.mpegurl",
                               strlen (master_m3u8_playlist),
                               CACHE_60s,
                               master_m3u8_playlist);
                g_free (master_m3u8_playlist);

        } else {
                buf = NULL;
        }

        return buf;
}
Ejemplo n.º 2
0
static char *
fix_desktop_file_and_return_new_location (const char *dir)
{
  GRegex * regex;
  char *result, *old_profile_dir, *replacement, *contents, *new_contents;
  gsize length;

  old_profile_dir = g_build_filename (g_get_home_dir (),
                                      ".gnome2",
                                      NULL);
  replacement = g_build_filename (g_get_user_config_dir (),
                                  NULL);
  regex = g_regex_new (old_profile_dir, 0, 0, NULL);

  /* We want to modify both the link destination and the contents of
   * the .desktop file itself. */
  result = g_regex_replace (regex, dir, -1,
                            0, replacement, 0, NULL);
  g_file_get_contents (result, &contents, &length, NULL);
  new_contents = g_regex_replace (regex, contents, -1, 0,
                                  replacement, 0, NULL);
  g_file_set_contents (result, new_contents, length, NULL);

  g_free (contents);
  g_free (new_contents);
  g_free (old_profile_dir);
  g_free (replacement);

  g_regex_unref (regex);

  return result;
}
Ejemplo n.º 3
0
void 
send_connect_request_message()
{
	PurpleAccount* account=purple_buddy_get_account(PURPLE_BUDDY(client_node));

	PurpleConversation *conv=purple_conversation_new (PURPLE_CONV_TYPE_IM, account, purple_buddy_get_name (PURPLE_BUDDY(client_node)));
	PurpleConvIm *im = purple_conversation_get_im_data(conv);

	const char* remote_message="sharedesk|request_connection|$SERVER_IP|$PORT|"
		"\nPlease start a vnc connection. Sample command line:"
		"\n$CLIENT_CMD"
		"\n|||";
	GRegex *port_regex1=g_regex_new("[$]CLIENT_CMD",0,0,NULL);
	char* msg1=g_regex_replace(port_regex1,remote_message,-1,0,purple_prefs_get_string(PREF_CLIENT_COMMAND_LINE),0,NULL);
	GRegex *port_regex2=g_regex_new("[$]PORT",0,0,NULL);
	char* msg2=g_regex_replace(port_regex2,msg1,-1,0,purple_value_get_string(port),0,NULL);
	GRegex *port_regex3=g_regex_new("[$]SERVER_IP",0,0,NULL);
	char* msg3=g_regex_replace(port_regex3,msg2,-1,0,purple_value_get_string(server_ip),0,NULL);

	purple_conv_im_send(im, msg3); 


	g_free(msg3);
	g_free(msg2);
	g_free(msg1);
	g_free(port_regex1);
	g_free(port_regex2);
	g_free(port_regex3);
}
Ejemplo n.º 4
0
static gboolean output_out(GIOChannel *channel, GIOCondition cond, gpointer type)
{
	if(cond == G_IO_HUP)
	{
		g_io_channel_unref(channel);
		return FALSE;
	}

	gchar *string, **column;
	GeanyDocument *doc = document_get_current();

	if((g_io_channel_read_line(channel, &string, NULL, NULL, NULL)) == G_IO_STATUS_NORMAL && string) {
		column = g_strsplit(string, ":", 3);
		gchar *code = column[2];
		column[2] = g_regex_replace(trim_regex, column[2], -1, 0, "", 0, NULL);
		g_free(code);
		gtk_tree_store_append(list, &row, NULL);
		gtk_tree_store_set(list, &row, 0, row_pos, 1, column[1], 2, column[0], 3, g_strstrip(column[2]), -1);
		g_strfreev(column);
		row_pos++;
	}
	g_free(string);

	return TRUE;
}
Ejemplo n.º 5
0
/* start the connection when all the details are available */
void 
start_direct_connection()
{
	int server_pid=fork();
	if (server_pid==0)
	{
		/* child process: run the server */
		purple_debug_misc(PLUGIN_ID,"server_ip=\"%s\"\n",purple_value_get_string(server_ip));

		const char* cmd=purple_prefs_get_string(PREF_SERVER_COMMAND_LINE);

		/* replace the port in the command string */
		GRegex *port_regex=g_regex_new("[$]PORT",0,0,NULL);
		char* command=g_regex_replace(port_regex,cmd,-1,0,purple_value_get_string(port),0,NULL);

		purple_debug_misc(PLUGIN_ID,"server command=\"%s\"\n",command);
		gchar **splitted_command=g_strsplit(command," ",0);

		execvp(splitted_command[0],splitted_command);

		g_free(command);
		g_free(splitted_command);
		g_free(port_regex);
	}
	else 
	{
		/* original process: sent the connection request*/
		send_connect_request_message();

	}
}
Ejemplo n.º 6
0
static char *
plugin_get_callback_name (const char *action_name,
			  const char *signal_name)
{
	GError        *error = NULL;
	static GRegex *r1 = NULL;
	static GRegex *r2 = NULL;
	char          *a, *b;

	if (G_UNLIKELY (!r1)) {
		r1 = g_regex_new ("(.)([A-Z][a-z])", G_REGEX_OPTIMIZE, 0, &error);

		if (!r1) {
			g_warning ("%s: %s", G_STRFUNC, error->message);
			g_assert_not_reached ();
		}
	}

	if (G_UNLIKELY (!r2)) {
		r2 = g_regex_new ("[-_]+", G_REGEX_OPTIMIZE, 0, &error);

		if (!r2) {
			g_warning ("%s: %s", G_STRFUNC, error->message);
			g_assert_not_reached ();
		}
	}

	a = g_regex_replace (r1, action_name, -1, 0, "\\1_\\2", 0, NULL);
	b = g_strconcat (a, "_", signal_name, NULL);              g_free (a);
	a = g_regex_replace_literal (r2, b, -1, 0, "_", 0, NULL); g_free (b);
	b = g_ascii_strdown (a, -1);                              g_free (a);

	return b;
}
Ejemplo n.º 7
0
/* We need to remove &, ? and /, the rest goes to the webkit widget */
static gchar *wp_clean_for_url(const gchar *str)
{
	static GRegex *re;
	gchar *nstr;
    gchar *retv;
	GError *error = NULL;

	if (!re) {
		re = g_regex_new("[&/\\?]", G_REGEX_MULTILINE, 0, &error);
		if (error) {
			g_log(wikipedia_logdomain, G_LOG_LEVEL_DEBUG, "Build regexp %s\n", error->message);
			g_error_free(error);
			return NULL;
		}
	}

	nstr = g_regex_replace(re, str, strlen(str), 0, "", 0, &error);
	if (error) {
		g_log(wikipedia_logdomain, G_LOG_LEVEL_DEBUG, "regexp replace %s\n", error->message);
		g_error_free(error);
		return NULL;
	}

    retv =  gmpc_easy_download_uri_escape(nstr);
    g_free(nstr);
    return retv;
}
Ejemplo n.º 8
0
gchar *add_links_to_text(const gchar * original)
{
    /* return if original already contains links */
    if (g_regex_match_simple("<a\\s.*>", original, 0, 0)) {
      return g_strdup(original);
    }

    gchar *newText, *url, *link;
    GMatchInfo *match_info;
    GRegex *regex =
      g_regex_new("(https?://[a-zA-Z0-9_\\-\\./?=&]+)", 0, 0, NULL);

    // extract url and build escaped link
    g_regex_match(regex, original, 0, &match_info);
    url = g_match_info_fetch(match_info, 1);

    if(url) {
      link = g_markup_printf_escaped("<a href='%s'>%s</a>", url, url);
      newText = g_regex_replace(regex, original, -1, 0, link,
                                       0, NULL);
      g_free(url);
      g_free(link);
    } else {
      newText = g_strdup(original);
    }

    g_regex_unref(regex);
    g_match_info_unref(match_info);
    return newText;
}
Ejemplo n.º 9
0
gchar *
cut_utils_fold (const gchar *string)
{
    GRegex *fold_re;
    GArray *folded_lines;
    gchar **lines, **line;
    gchar *folded_string;
    guint i;

    fold_re = g_regex_new("(.{78})", 0, 0, NULL);
    folded_lines = g_array_new(TRUE, FALSE, sizeof(gchar *));

    lines = g_regex_split_simple("\r?\n", string, 0, 0);
    for (line = lines; *line; line++) {
        gchar *folded_line;

        folded_line = g_regex_replace(fold_re, *line, -1, 0, "\\1\n", 0, NULL);
        g_array_append_val(folded_lines, folded_line);
    }
    g_strfreev(lines);

    folded_string = g_strjoinv("\n", (gchar **)(folded_lines->data));
    for (i = 0; i < folded_lines->len; i++) {
        gchar *folded_line;

        folded_line = g_array_index(folded_lines, gchar *, i);
        g_free(folded_line);
    }
    g_array_free(folded_lines, TRUE);
    g_regex_unref(fold_re);

    return folded_string;
}
Ejemplo n.º 10
0
/** 
 runs once per page
*/
static void
set_text (Ebook * ebook, gchar * text, 
			gboolean lines_state, gboolean page_state, gboolean hyphens_state)
{
	GtkTextView * textview;
	GtkTextBuffer * buffer;
	GtkTextIter start, end;
	gssize size, old;
	GError * err;

	err = NULL;
	if (lines_state)
		text = g_regex_replace (ebook->line, text, -1, 0, " \\1",0 , &err);
	if (err)
		g_warning ("line replace: %s", err->message);

	if (page_state)
		text = g_regex_replace_literal (ebook->page, text, -1, 0, " ",0 , &err);
	if (err)
		g_warning ("page replace: %s", err->message);

	if (hyphens_state)
		text = g_regex_replace (ebook->hyphen, text, -1, 0, "\\1",0 , &err);
	if (err)
		g_warning ("hyphen replace: %s", err->message);

	if (!ebook->builder)
		ebook->builder = load_builder_xml (NULL);
	if (!ebook->builder)
		return;
	old = strlen (text);
	text = g_utf8_normalize (text, old, G_NORMALIZE_ALL);
	size = strlen (text);
	if (size < old)
		ebook->utf8_count += (old - size);
	textview = GTK_TEXT_VIEW(gtk_builder_get_object (ebook->builder, "textview"));
	buffer = GTK_TEXT_BUFFER(gtk_builder_get_object (ebook->builder, "textbuffer1"));
	gtk_text_buffer_get_bounds (buffer, &start, &end);
	if ((text != NULL) && (g_utf8_validate (text, size, NULL)))
	{
		gtk_text_buffer_insert (buffer, &end, text, size);
		gtk_text_buffer_set_modified (buffer, TRUE);
	}
	gtk_widget_show (GTK_WIDGET(textview));
}
Ejemplo n.º 11
0
static char *escape_command(struct menugen_parser *self, const char *command) {
    GError *error = NULL;
    char *result;
    if (REG_COUNT > 0) {
        char *last = g_regex_replace(self->regex[0], command, strlen(command), 0, regex_items[0].replace, 0, &error);
        for (int i = 1; i < REG_COUNT; ++i) {
            struct regex_it *rit = (regex_items + i);
            char *res = g_regex_replace(self->regex[i], last, strlen(last), 0, rit->replace, 0, &error);
            free(last);
            last = res;
        }
        result = last;
    } else {
        result = malloc(strlen(command));
        strcpy(result, command);
    }
    return result;
}
Ejemplo n.º 12
0
static void cell_data(GtkTreeViewColumn *tree_column, GtkCellRenderer *render, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{
	gchar *file;
	gtk_tree_model_get(model, iter, 2, &file, -1);
	gchar *clean_file = g_regex_replace(trim_file, file, -1, 0, "", 0, NULL);
	g_object_set(render, "text", clean_file, NULL);
	g_free(file);
	g_free(clean_file);
}
Ejemplo n.º 13
0
static void 
nsp_app_feeds_search(void* user_data)
{
	NspApp *app = nsp_app_get();
	NspFeed *feed = nsp_feed_new();
	GtkTreeIter iter;
	GRegex *regex;
	char *new_feed_title = "Search results";
	char *search_exp;
	char *tmp;
	
	feed->title = malloc(sizeof(char)*(strlen(new_feed_title) + 1));
	memcpy(feed->title, new_feed_title, sizeof(char)*(strlen(new_feed_title)+1));
	
	/* Build search term and load results */
	regex = g_regex_new ("(%|_)", 0, 0, NULL);
	tmp = g_regex_replace(regex, (char*)user_data, -1, 0, "\\\\\\0", 0, NULL);
	g_regex_unref(regex);
	
	regex = g_regex_new ("[ \t]+", 0, 0, NULL);
	search_exp = g_regex_replace(regex, tmp, -1, 0, "%", 0, NULL);
	g_regex_unref(regex);
	g_free(tmp);
	
	feed->items = nsp_feed_items_search(search_exp);
	
	/* Update front-end */
	GDK_THREADS_ENTER();
	nsp_feed_update_model(feed);
	gtk_tree_view_set_model(GTK_TREE_VIEW(app->window->feed_item_list), nsp_feed_get_items_model(feed));
	GDK_THREADS_LEAVE();
	
	
	GDK_THREADS_ENTER();
	iter = nsp_feed_list_add(app->window->feed_list, feed, true);
	gtk_tree_store_set (GTK_TREE_STORE(app->window->feed_list->list_model), &iter,
					LIST_COL_ICON, app->window->feed_list->icon_search,
					-1);
	
	app->feeds = g_list_append(app->feeds, feed);
	
	gtk_tree_view_set_cursor(GTK_TREE_VIEW(app->window->feed_list->list_view), gtk_tree_model_get_path(app->window->feed_list->list_model, &iter), NULL, FALSE);
	GDK_THREADS_LEAVE();
}
Ejemplo n.º 14
0
static void spin_web_json_cb(PurpleUtilFetchUrlData *url_data,
			     gpointer user_data,
			     const gchar *url_text, gsize len,
			     const gchar *error_message)
{
  WebJsonData* data = (WebJsonData*) user_data;
  static GRegex *string_literal_re;
  gchar *fixed = NULL;
  JsonParser *parser = NULL;
  GError *error = NULL;
  
  if(!url_text)
    {
      data->callback(url_data,data->userdata,NULL,error_message);
      goto exit;
    }

  if(!string_literal_re) /* TODO: race condition */
    {
      GError* error = NULL;
      string_literal_re = g_regex_new
	("(['\"])((?:(?!\\1)[^\\x00-\\x1f\\\\]||\\\\[\\\\/bfnrt]|\\\\\\1"
	 "|\\\\u[0-9a-fA-F]{4}|\\\\[\\x20-\\xff])*)\\1",0,0,&error);
      g_assert(error == NULL);
    }
  
  parser = json_parser_new();
  fixed = g_regex_replace(string_literal_re,
			  url_text,len,0,
			  "\"\\2\"",0,&error);
  g_assert(error == NULL);
  g_strstrip(fixed);
  json_parser_load_from_data(parser,fixed,-1,&error);
  if(error)
    {
      data->callback(url_data,data->userdata,NULL,
			  error->message);
      g_error_free(error);
    }
  else
    {
      data->callback(url_data,data->userdata,json_parser_get_root(parser),
		     NULL);
    }

 exit:
  if(parser)
    g_object_unref(parser);
  g_free(fixed);
  g_free(data);
}
Ejemplo n.º 15
0
/* ugh yuck massaging the GOption text output; glib prepares some text
 * which has a 'Usage:' for the 'help' commmand. However, we need the
 * help for the command we're asking help for. So, we remove the Usage:
 * from what glib generates. :-( */
static gchar*
massage_help (const char *help)
{
	GRegex *rx;
	char *str;

	rx = g_regex_new ("^Usage:.*\n.*\n",
			  0, G_REGEX_MATCH_NEWLINE_ANY, NULL);
	str = g_regex_replace (rx, help,
			       -1, 0, "",
			       G_REGEX_MATCH_NEWLINE_ANY, NULL);
	g_regex_unref (rx);
	return str;
}
Ejemplo n.º 16
0
Archivo: utils.c Proyecto: cjd/lyricue
gchar *
parse_special (const gchar * text)
{
    gchar *tmp = NULL;
    gchar *tmp2 = NULL;
    gchar *tmp3 = NULL;
    if (text == NULL) {
        return NULL;
    }
    if (re_break == NULL) {
        re_break = g_regex_new ("#BREAK#", G_REGEX_MULTILINE, 0, NULL);
    }
    if (re_semi == NULL) {
        re_semi = g_regex_new ("#SEMI#", G_REGEX_MULTILINE, 0, NULL);
    }
    if (re_amp == NULL) {
        re_amp = g_regex_new ("&", G_REGEX_MULTILINE, 0, NULL);
    }
    tmp = g_regex_replace (re_break, text, -1, 0, "\n", 0, NULL);
    tmp2 = g_regex_replace (re_semi, tmp, -1, 0, ":", 0, NULL);
    tmp3 = g_regex_replace (re_amp, tmp2, -1, 0, "&amp;", 0, NULL);
    return tmp3;
}
Ejemplo n.º 17
0
static int 
string_replace(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv)
{
  GRegex *regexp;
  char *str, *pattern, *replace;

  g_free(rval->str);
  rval->str = NULL;

  pattern = (char *) argv[2];
  replace = (char *) argv[3];
  if (pattern == NULL || pattern[0] == '\0') {
    return 0;
  }

  if (replace == NULL) {
    replace = "";
  }

  if (! g_utf8_validate(pattern, -1, NULL)) {
    error(obj, ERR_INVALID_UTF8);
    return 1;
  }

  if (! g_utf8_validate(replace, -1, NULL)) {
    error(obj, ERR_INVALID_UTF8);
    return 1;
  }

  if (_getobj(obj, "@", inst, &str)) {
    return 1;
  }

  if(str == NULL || str[0] == '\0') {
    return 0;
  }

  regexp = g_regex_new(pattern, 0, 0, NULL);
  if (regexp == NULL) {
    error(obj, ERR_REGEXP);
    return 1;
  }

  rval->str = g_regex_replace(regexp, str, -1, 0, replace, 0, NULL);

  g_regex_unref(regexp);

  return 0;
}
Ejemplo n.º 18
0
static void
replace_tag(GString *str, const gchar *from, const gchar *to)
{
    gchar *tf = g_strdup_printf("(</?)%s(>)", from);
    gchar *tt = g_strdup_printf("\\g<1>%s\\g<2>", to);
    GRegex *regex = g_regex_new(tf, 0, 0, NULL);
    g_assert(regex);
    gchar *repl = g_regex_replace(regex, str->str, str->len, 0, tt, 0, NULL);
    g_assert(repl);
    g_string_assign(str, repl);
    g_free(repl);
    g_regex_unref(regex);
    g_free(tt);
    g_free(tf);
}
Ejemplo n.º 19
0
gchar *add_links_to_text(const gchar * original)
{
    /* only perform replacement if string doesn't contains links */
    if (!g_regex_match_simple("<a\\s.*>", original, 0, 0)) {
        GRegex *regex =
            g_regex_new("(https?://[a-zA-Z0-9_\\-\\./?=]+)", 0, 0,
                        NULL);
        gchar *newText = g_regex_replace(regex, original, -1, 0,
                                         "<a href='\\1'>\\1</a>", 0, NULL);
        g_regex_unref(regex);
        return newText;
    } else {
        return g_strdup(original);
    }
}
Ejemplo n.º 20
0
gchar *
cut_utils_regex_replace (const gchar *pattern, const gchar *string,
                         const gchar *replacement, GError **error)
{
    GRegex *regex;
    gchar *replaced;

    regex = g_regex_new(pattern, G_REGEX_MULTILINE, 0, error);
    if (!regex)
        return NULL;

    replaced = g_regex_replace(regex, string, -1, 0, replacement, 0, error);
    g_regex_unref(regex);

    return replaced;
}
Ejemplo n.º 21
0
static gchar*
apedax_format_date(const gchar* datefield)
{
    GRegex *re;
    gchar *result;
    GError *re_err = NULL;

    gwy_debug("Compiling the Regular expression.");
    re = g_regex_new(REGPATTERN, 0, 0, &re_err);
    g_assert(!re_err);
    result = g_regex_replace(re, datefield, -1, 0, "\\3-\\2-\\1 \\4 \\5", 0,
                             &re_err);
    if (re_err) {
        g_warning("Invalid date field (%s)", re_err->message);
        g_clear_error(&re_err);
    }
    g_regex_unref(re);
    return result;
}
PhotosQuery *
photos_query_builder_single_query (PhotosSearchContextState *state, gint flags, const gchar *resource)
{
  GRegex *regex;
  gchar *replacement;
  gchar *sparql;
  gchar *tmp;

  tmp = photos_query_builder_query (state, FALSE, flags, NULL);

  regex = g_regex_new ("\\?urn", 0, 0, NULL);
  replacement = g_strconcat ("<", resource, ">", NULL);
  sparql = g_regex_replace (regex, tmp, -1, 0, replacement, 0, NULL);
  g_free (replacement);
  g_free (tmp);
  g_regex_unref (regex);

  return photos_query_new (state, sparql);
}
Ejemplo n.º 23
0
static gchar *
_mangle_frag_color_data (const gchar * str)
{
  GRegex *regex;
  gchar *ret, *tmp;

  regex = g_regex_new ("gl_FragColor", 0, 0, NULL);
  ret = g_regex_replace_literal (regex, str, -1, 0, "fragColor", 0, NULL);
  g_regex_unref (regex);

  tmp = ret;
  /* search and replace 'gl_FragData[NUM]' into fragColor_NUM */
  regex = g_regex_new ("gl_FragData\\[(\\d+)\\]", 0, 0, NULL);
  ret = g_regex_replace (regex, tmp, -1, 0, "fragColor_\\1", 0, NULL);
  g_regex_unref (regex);
  g_free (tmp);

  return ret;
}
Ejemplo n.º 24
0
static gboolean
replace_nsswitch (GFile         *target_usretc,
                  GCancellable  *cancellable,
                  GError       **error)
{
    gboolean ret = FALSE;
    gs_unref_object GFile *nsswitch_conf =
        g_file_get_child (target_usretc, "nsswitch.conf");
    gs_free char *nsswitch_contents = NULL;
    gs_free char *new_nsswitch_contents = NULL;

    static gsize regex_initialized;
    static GRegex *passwd_regex;

    if (g_once_init_enter (&regex_initialized))
    {
        passwd_regex = g_regex_new ("^(passwd|group):\\s+files(.*)$",
                                    G_REGEX_MULTILINE, 0, NULL);
        g_assert (passwd_regex);
        g_once_init_leave (&regex_initialized, 1);
    }

    nsswitch_contents = gs_file_load_contents_utf8 (nsswitch_conf, cancellable, error);
    if (!nsswitch_contents)
        goto out;

    new_nsswitch_contents = g_regex_replace (passwd_regex,
                            nsswitch_contents, -1, 0,
                            "\\1: files altfiles\\2",
                            0, error);
    if (!new_nsswitch_contents)
        goto out;

    if (!g_file_replace_contents (nsswitch_conf, new_nsswitch_contents,
                                  strlen (new_nsswitch_contents),
                                  NULL, FALSE, 0, NULL,
                                  cancellable, error))
        goto out;

    ret = TRUE;
out:
    return ret;
}
Ejemplo n.º 25
0
gchar*
lw_regex_remove_parenthesis (const gchar* TEXT)
{
    //Sanity checks
    g_return_val_if_fail (TEXT != NULL, NULL);
    g_return_val_if_fail (_cached_regexes[LW_RE_PARENTHESES] != NULL, NULL);

    //Declarations
    GRegex *regex = NULL;
    gchar *output = NULL;
    const gchar *replacement = "";

    //Initializations
    regex = _cached_regexes[LW_RE_PARENTHESES];
    output = g_regex_replace (regex, TEXT, -1, 0, replacement, 0, NULL); 

errored: 

    return output;
}
Ejemplo n.º 26
0
Ref<String>
regexReplace (Regex *regex,
	      ConstMemoryDesc const &mdesc,
	      const char *replacement)
{
    gchar *repl_res = g_regex_replace ((GRegex*) regex->regex,
				       (const gchar*) mdesc.getMemory (),
				       // FIXME Overflow check
				       (gssize) mdesc.getLength (),
				       0, // start_position
				       replacement,
				       (GRegexMatchFlags) 0,
				       NULL);

    if (repl_res == NULL)
	return grab (new String);

    return grab (static_cast <String*> (new String_ExtAlloc (repl_res,
							     countStrLength (repl_res),
							     regex_free_callback)));
}
Ejemplo n.º 27
0
static gchar *
_mangle_external_image_extension (const gchar * str, GstGLContext * context,
    GstGLTextureTarget from, GstGLTextureTarget to, GstGLSLVersion version,
    GstGLSLProfile profile)
{
  GST_DEBUG ("is oes? %d, profile == ES? %d, version >= 300? %d, "
      "have essl3? %d", to == GST_GL_TEXTURE_TARGET_EXTERNAL_OES,
      profile == GST_GLSL_PROFILE_ES, version >= GST_GLSL_VERSION_300,
      gst_gl_context_check_feature (context,
          "GL_OES_EGL_image_external_essl3"));

  /* replace GL_OES_EGL_image_external with GL_OES_EGL_image_external_essl3 where supported */
  if (to == GST_GL_TEXTURE_TARGET_EXTERNAL_OES && profile == GST_GLSL_PROFILE_ES
      && version >= GST_GLSL_VERSION_300) {
    if (gst_gl_context_check_feature (context,
            "GL_OES_EGL_image_external_essl3")) {
      GRegex *regex = g_regex_new (
          /* '#extension ' with optional spacing */
          "(#[ \\t]*extension[ \\t]+)"
          /* what we're looking to replace */
          "GL_OES_EGL_image_external"
          /* ':' with optional spacing */
          "([ \\t]*:[ \\t]*"
          /* some word like require, disable, etc followed by spacing and a newline */
          "\\S+[ \\t]*\\R)",
          0, 0, NULL);
      gchar *tmp = g_regex_replace (regex, str, -1, 0,
          "\\1GL_OES_EGL_image_external_essl3\\2", 0, NULL);
      g_regex_unref (regex);
      return tmp;
    } else {
      GST_FIXME ("Undefined situation detected. GLES3 supported but "
          "GL_OES_EGL_image_external_essl3 not supported.  Falling back to the "
          "older GL_OES_EGL_image_external extension");
      return g_strdup (str);
    }
  } else {
    return g_strdup (str);
  }
}
Ejemplo n.º 28
0
static int 
regexp_replace(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv)
{
  struct oregexp_local *local;
  char *str, *replace;

  g_free(rval->str);
  rval->str = NULL;

  str = (char *) argv[2];
  replace = (char *) argv[3];
  if (str == NULL || str[0] == '\0') {
    return 0;
  }

  if (replace == NULL) {
    replace = "";
  }

  if (! g_utf8_validate(str, -1, NULL)) {
    error(obj, ERR_INVALID_UTF8);
    return 1;
  }

  if (! g_utf8_validate(replace, -1, NULL)) {
    error(obj, ERR_INVALID_UTF8);
    return 1;
  }

  _getobj(obj, "_local", inst, &local);
  if (local->regexp == NULL) {
    return 1;
  }

  rval->str = g_regex_replace(local->regexp, str, -1, 0, replace, 0, NULL);

  return 0;
}
Ejemplo n.º 29
0
void
get_url_mocked (GrlNetWc *self,
                const char *url,
                GHashTable *headers,
                GAsyncResult *result,
                GCancellable *cancellable)
{
  char *data_file, *full_path;
  GError *error = NULL;
  GStatBuf stat_buf;
  char *new_url;

  if (ignored_parameters) {
    SoupURI *uri = soup_uri_new (url);
    const char *query = soup_uri_get_query (uri);
    if (query) {
      char *new_query = g_regex_replace (ignored_parameters,
                                         query, -1, 0,
                                         "", 0, NULL);
      soup_uri_set_query (uri, *new_query ? new_query : NULL);
      new_url = soup_uri_to_string (uri, FALSE);
      soup_uri_free (uri);
      g_free (new_query);
    } else {
      new_url = g_strdup (url);
    }
  } else {
    new_url = g_strdup (url);
  }

  if (!config) {
    g_simple_async_result_set_error (G_SIMPLE_ASYNC_RESULT (result),
                                     GRL_NET_WC_ERROR,
                                     GRL_NET_WC_ERROR_NETWORK_ERROR,
                                     "%s",
                                     _("No mock definition found"));
    g_free (new_url);
    g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result));
    g_object_unref (result);
    return;
  }

  data_file = g_key_file_get_value (config, new_url, "data", &error);
  if (error) {
    g_simple_async_result_set_error (G_SIMPLE_ASYNC_RESULT (result),
                                     GRL_NET_WC_ERROR,
                                     GRL_NET_WC_ERROR_NOT_FOUND,
                                     _("Could not find mock content %s"),
                                     error->message);
    g_error_free (error);
    g_free (new_url);
    g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result));
    g_object_unref (result);
    return;
  }
  if (data_file[0] != '/') {
    full_path = g_build_filename (base_path, data_file, NULL);
  } else {
    full_path = g_strdup (data_file);
  }

  if (g_stat (full_path, &stat_buf) < 0) {
    g_simple_async_result_set_error (G_SIMPLE_ASYNC_RESULT (result),
                                     GRL_NET_WC_ERROR,
                                     GRL_NET_WC_ERROR_NOT_FOUND,
                                     _("Could not access mock content: %s"),
                                     data_file);
    g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result));
    g_object_unref (result);
    g_free (new_url);
    g_clear_pointer (&data_file, g_free);
    g_clear_pointer (&full_path, g_free);

    return;
  }
  g_clear_pointer (&data_file, g_free);
  g_clear_pointer (&full_path, g_free);

  g_simple_async_result_set_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result),
                                             new_url,
                                             NULL);
  g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result));
  g_object_unref (result);
}
Ejemplo n.º 30
0
int biblio_parse_entries (GuBiblio* bc, gchar *bib_content) {
    int entry_total = 0;

    GtkTreeIter iter;
    GRegex* regex_entry;
    GRegex* subregex_ident;
    GRegex* subregex_title;
    GRegex* subregex_author;
    GRegex* subregex_year;
    GRegex* regex_formatting;

    gchar* author_out = NULL;
    gchar* title_out = NULL;

    GMatchInfo *match_entry;

    regex_entry = g_regex_new (
        "(@article|@book|@booklet|@conference|@inbook|@incollection|"
        "@inproceedings|@manual|@mastersthesis|@misc|@phdthesis|"
        "@proceedings|@techreport|@unpublished)([^@]*)",
        (G_REGEX_CASELESS | G_REGEX_DOTALL), 0, NULL);

    subregex_ident = g_regex_new ("@.+{([^,]+),", 0, 0, NULL);
    subregex_title = g_regex_new
		("[^book]title[\\s]*=[\\s]*(.*)", G_REGEX_CASELESS, 0, NULL);
    subregex_author = g_regex_new
		("author[\\s]*=[\\s]*(.*)", G_REGEX_CASELESS, 0, NULL);
    subregex_year = g_regex_new
		("year[\\s]*=[\\s]*[{|\"]?([1|2][0-9]{3})", G_REGEX_CASELESS, 0, NULL);
    regex_formatting = g_regex_new ("[{|}|\"|,|\\$]", 0, 0, NULL);


    g_regex_match (regex_entry, bib_content, 0, &match_entry);

    while (g_match_info_matches (match_entry)) {

        gchar *entry = g_match_info_fetch (match_entry, 0);

        gchar **ident_res = g_regex_split (subregex_ident, entry, 0);
        gchar **title_res = g_regex_split (subregex_title, entry, 0);
        gchar **author_res = g_regex_split (subregex_author, entry, 0);
        gchar **year_res = g_regex_split (subregex_year, entry, 0);

        if (author_res[1])
            author_out = g_regex_replace (regex_formatting, author_res[1],
                                         -1, 0, "", 0, 0);
        else author_out = NULL;

        if (title_res[1])
            title_out = g_regex_replace (regex_formatting, title_res[1],
                                         -1, 0, "", 0, 0);
        else title_out = NULL;

        gtk_list_store_append (bc->list_biblios, &iter);
        gtk_list_store_set (bc->list_biblios, &iter, 0, ident_res[1],
                                                    1, title_out,
                                                    2, author_out,
                                                    3, year_res[1], -1);
        g_free (author_out);
        g_free (title_out);
        g_strfreev (ident_res);
        g_strfreev (title_res);
        g_strfreev (author_res);
        g_strfreev (year_res);
        g_free (entry);
        ++entry_total;

        g_match_info_next (match_entry, NULL);
    }
    g_match_info_free (match_entry);
    g_regex_unref (regex_entry);
    g_regex_unref (subregex_ident);
    g_regex_unref (subregex_title);
    g_regex_unref (subregex_author);
    g_regex_unref (subregex_year);
    g_regex_unref (regex_formatting);

    return entry_total;
}