コード例 #1
0
static gboolean
pk_backend_config_add_server (PkBackendConfig *config,
			      PkBackendConfigSection *section,
			      const gchar *address, GError **e)
{
	gchar *url;

	g_return_val_if_fail (config != NULL, FALSE);
	g_return_val_if_fail (section != NULL, FALSE);
	g_return_val_if_fail (address != NULL, FALSE);

	url = g_regex_replace_literal (config->xrepo, address, -1, 0,
				       section->name, 0, e);
	if (url == NULL) {
		return FALSE;
	}

	if (config->arch != NULL) {
		gchar *temp = url;
		url = g_regex_replace_literal (config->xarch, temp, -1, 0,
					       config->arch, 0, e);
		g_free (temp);

		if (url == NULL) {
			return FALSE;
		}
	} else if (strstr (url, "$arch") != NULL) {
		g_set_error (e, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID,
			     "url contained $arch, which is not set");
	}

	section->servers = alpm_list_add (section->servers, url);

	return TRUE;
}
コード例 #2
0
ファイル: gsettingsschema.c プロジェクト: shihyu/glib
static gchar *
normalise_whitespace (const gchar *orig)
{
  /* We normalise by the same rules as in intltool:
   *
   *   sub cleanup {
   *       s/^\s+//;
   *       s/\s+$//;
   *       s/\s+/ /g;
   *       return $_;
   *   }
   *
   *   $message = join "\n\n", map &cleanup, split/\n\s*\n+/, $message;
   *
   * Where \s is an ascii space character.
   *
   * We aim for ease of implementation over efficiency -- this code is
   * not run in normal applications.
   */
  static GRegex *cleanup[3];
  static GRegex *splitter;
  gchar **lines;
  gchar *result;
  gint i;

  if (g_once_init_enter (&splitter))
    {
      GRegex *s;

      cleanup[0] = g_regex_new ("^\\s+", 0, 0, 0);
      cleanup[1] = g_regex_new ("\\s+$", 0, 0, 0);
      cleanup[2] = g_regex_new ("\\s+", 0, 0, 0);
      s = g_regex_new ("\\n\\s*\\n+", 0, 0, 0);

      g_once_init_leave (&splitter, s);
    }

  lines = g_regex_split (splitter, orig, 0);
  for (i = 0; lines[i]; i++)
    {
      gchar *a, *b, *c;

      a = g_regex_replace_literal (cleanup[0], lines[i], -1, 0, "", 0, 0);
      b = g_regex_replace_literal (cleanup[1], a, -1, 0, "", 0, 0);
      c = g_regex_replace_literal (cleanup[2], b, -1, 0, " ", 0, 0);
      g_free (lines[i]);
      g_free (a);
      g_free (b);
      lines[i] = c;
    }

  result = g_strjoinv ("\n\n", lines);
  g_strfreev (lines);

  return result;
}
コード例 #3
0
ファイル: set_music.c プロジェクト: yshui/tprj
gchar *get_connection_bus_name(const gchar *obj){
	static GRegex *regex1 = NULL, *regex2 = NULL;
	GError *error = NULL;
	if(regex1 == NULL)
		regex1 = g_regex_new("^/", 0, 0, &error);
	if(regex2 == NULL)
		regex2 = g_regex_new("/", 0, 0, &error);
	gchar *tmp1 = g_regex_replace_literal(regex1, obj, -1, 0, "", 0, &error);
	gchar *tmp2 = g_regex_replace_literal(regex2, tmp1, -1, 0, ".", 0, &error);
	g_free(tmp1);
	return tmp2;
}
コード例 #4
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;
}
コード例 #5
0
ファイル: na-core-utils.c プロジェクト: nmbooker/caja-actions
/**
 * na_core_utils_str_remove_char:
 * @string: source string.
 * @to_remove: the character to remove.
 *
 * Returns: a newly allocated string, which is a copy of the source @string,
 * minus all the found occurrences of the given @to_remove char.
 *
 * The returned string should be g_free() by the caller.
 *
 * Since: 2.30
 */
gchar *
na_core_utils_str_remove_char( const gchar *string, const gchar *to_remove )
{
	static const gchar *thisfn = "na_core_utils_str_remove_char";
	gchar *removed;
	GRegex *regex;
	GError *error;

	removed = g_strdup( string );

	if( g_utf8_validate( string, -1, NULL )){

		error = NULL;
		regex = g_regex_new( to_remove, 0, 0, &error );
		if( error ){
			g_warning( "%s [g_regex_new] %s", thisfn, error->message );
			g_error_free( error );

		} else {
			g_free( removed );
			removed = g_regex_replace_literal( regex, string, -1, 0, "", 0, &error );
			if( error ){
				g_warning( "%s [g_regex_replace_literal] %s", thisfn, error->message );
				g_error_free( error );
			}
		}
	}

	return( removed );
}
コード例 #6
0
ファイル: string_helper.c プロジェクト: poelzi/gtkmateview
/* Replace all occurences of match_string with replacement_string inside start_string.*/
char* string_helper_gsub (const char* start_string, const char* match_string, const char* replacement_string) {
	GError * inner_error;
	GRegex* grx;
	char* result;
	char* _tmp5;
	g_return_val_if_fail (start_string != NULL, NULL);
	g_return_val_if_fail (match_string != NULL, NULL);
	g_return_val_if_fail (replacement_string != NULL, NULL);
	inner_error = NULL;
	grx = NULL;
	result = NULL;
	{
		GRegex* _tmp1;
		char* _tmp0;
		char* _tmp2;
		char* _tmp3;
		_tmp1 = NULL;
		_tmp0 = NULL;
		grx = (_tmp1 = g_regex_new (_tmp0 = g_regex_escape_string (match_string, -1), 0, 0, &inner_error), (grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL)), _tmp1);
		if (inner_error != NULL) {
			if (inner_error->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			goto __finally4;
		}
		_tmp0 = (g_free (_tmp0), NULL);
		_tmp2 = g_regex_replace_literal (grx, start_string, strlen (start_string), 0, replacement_string, 0, &inner_error);
		if (inner_error != NULL) {
			if (inner_error->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			goto __finally4;
		}
		_tmp3 = NULL;
		result = (_tmp3 = _tmp2, result = (g_free (result), NULL), _tmp3);
	}
	goto __finally4;
	__catch4_g_regex_error:
	{
		GError * e;
		e = inner_error;
		inner_error = NULL;
		{
			char* _tmp4;
			_tmp4 = NULL;
			return (_tmp4 = g_strdup (""), (e == NULL) ? NULL : (e = (g_error_free (e), NULL)), (grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL)), result = (g_free (result), NULL), _tmp4);
		}
	}
	__finally4:
	if (inner_error != NULL) {
		(grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL));
		result = (g_free (result), NULL);
		g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
		g_clear_error (&inner_error);
		return NULL;
	}
	_tmp5 = NULL;
	return (_tmp5 = result, (grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL)), _tmp5);
}
コード例 #7
0
ファイル: string_helper.c プロジェクト: alourie/gtkmateview
/* Replace all occurences of match_string with replacement_string inside start_string.*/
char* string_helper_gsub (const char* start_string, const char* match_string, const char* replacement_string) {
	GError * _inner_error_;
	GRegex* grx;
	char* _result_;
	char* _tmp5_;
	g_return_val_if_fail (start_string != NULL, NULL);
	g_return_val_if_fail (match_string != NULL, NULL);
	g_return_val_if_fail (replacement_string != NULL, NULL);
	_inner_error_ = NULL;
	grx = NULL;
	_result_ = NULL;
	{
		GRegex* _tmp1_;
		char* _tmp0_;
		char* _tmp2_;
		char* _tmp3_;
		_tmp1_ = NULL;
		_tmp0_ = NULL;
		grx = (_tmp1_ = g_regex_new (_tmp0_ = g_regex_escape_string (match_string, -1), 0, 0, &_inner_error_), (grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL)), _tmp1_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			goto __finally4;
		}
		_tmp0_ = (g_free (_tmp0_), NULL);
		_tmp2_ = g_regex_replace_literal (grx, start_string, strlen (start_string), 0, replacement_string, 0, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			goto __finally4;
		}
		_tmp3_ = NULL;
		_result_ = (_tmp3_ = _tmp2_, _result_ = (g_free (_result_), NULL), _tmp3_);
	}
	goto __finally4;
	__catch4_g_regex_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			char* _tmp4_;
			_tmp4_ = NULL;
			return (_tmp4_ = g_strdup (""), (e == NULL) ? NULL : (e = (g_error_free (e), NULL)), (grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL)), _result_ = (g_free (_result_), NULL), _tmp4_);
		}
	}
	__finally4:
	if (_inner_error_ != NULL) {
		(grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL));
		_result_ = (g_free (_result_), NULL);
		g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, _inner_error_->message);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp5_ = NULL;
	return (_tmp5_ = _result_, (grx == NULL) ? NULL : (grx = (g_regex_unref (grx), NULL)), _tmp5_);
}
コード例 #8
0
ファイル: lyricwiki.c プロジェクト: CBke/audacious-plugins
/* str_unref() returned string */
static char *scrape_uri_from_lyricwiki_search_result(const char *buf, int64_t len)
{
	xmlDocPtr doc;
	gchar *uri = NULL;

	/*
	 * workaround buggy lyricwiki search output where it cuts the lyrics
	 * halfway through the UTF-8 symbol resulting in invalid XML.
	 */
	GRegex *reg;

	reg = g_regex_new("<(lyrics?)>.*</\\1>", (G_REGEX_MULTILINE | G_REGEX_DOTALL | G_REGEX_UNGREEDY), 0, NULL);
	gchar *newbuf = g_regex_replace_literal(reg, buf, len, 0, "", G_REGEX_MATCH_NEWLINE_ANY, NULL);
	g_regex_unref(reg);

	/*
	 * temporarily set our error-handling functor to our suppression function,
	 * but we have to set it back because other components of Audacious depend
	 * on libxml and we don't want to step on their code paths.
	 *
	 * unfortunately, libxml is anti-social and provides us with no way to get
	 * the previous error functor, so we just have to set it back to default after
	 * parsing and hope for the best.
	 */
	xmlSetGenericErrorFunc(NULL, libxml_error_handler);
	doc = xmlParseMemory(newbuf, strlen(newbuf));
	xmlSetGenericErrorFunc(NULL, NULL);

	if (doc != NULL)
	{
		xmlNodePtr root, cur;

		root = xmlDocGetRootElement(doc);

		for (cur = root->xmlChildrenNode; cur; cur = cur->next)
		{
			if (xmlStrEqual(cur->name, (xmlChar *) "url"))
			{
				xmlChar *lyric;
				gchar *basename;

				lyric = xmlNodeGetContent(cur);
				basename = g_path_get_basename((gchar *) lyric);

				uri = str_printf("http://lyrics.wikia.com/index.php?action=edit"
				 "&title=%s", basename);

				g_free(basename);
				xmlFree(lyric);
			}
		}

		xmlFreeDoc(doc);
	}

	g_free(newbuf);

	return uri;
}
コード例 #9
0
ファイル: utils.c プロジェクト: rosedu/osmo
gchar *
utl_text_replace (const gchar *text, const gchar *regex, const gchar *replacement)
{
	GRegex *reg = g_regex_new (regex, 0, 0, NULL);
	gchar *buffer = g_regex_replace_literal (reg, text, -1, 0, replacement, 0, NULL);
	g_regex_unref (reg);

	return buffer;
}
コード例 #10
0
ファイル: buildheaderfile.c プロジェクト: lukesalisbury/meg
gchar * replace_string( gchar * needle, gchar * haystack, gchar * value )
{
	GRegex * regex = g_regex_new( needle, 0, 0, NULL );
	gchar * new_string = g_regex_replace_literal( regex, haystack, -1, 0, value, 0, NULL );

	g_regex_unref( regex );

	return new_string;
}
コード例 #11
0
ファイル: parser.c プロジェクト: GnLWeB/balde
void
balde_unescape_single_quoted_strings(gchar** str)
{
    GRegex *re_escaped_str = g_regex_new("\\\\'", 0, 0, NULL);
    gchar *escaped_str = g_regex_replace_literal(re_escaped_str, *str, -1, 0,
        "'", 0, NULL);
    g_free(*str);
    *str = escaped_str;
    g_regex_unref(re_escaped_str);
}
コード例 #12
0
ファイル: gmimex.c プロジェクト: swerter/gmimex
static GString *gstr_replace_all(GString *text, const gchar* old_str, const gchar *new_str) {
  gchar *escaped_s1 = g_regex_escape_string (old_str, -1);
  GRegex *regex = g_regex_new (escaped_s1, 0, 0, NULL);
  gchar *new_string =  g_regex_replace_literal(regex, text->str, -1, 0, new_str, 0, NULL);
  g_regex_unref(regex);
  g_free(escaped_s1);
  g_string_assign(text, new_string);
  g_free(new_string);
  return text;
}
コード例 #13
0
ファイル: xid2aid.c プロジェクト: CannedFish/dde
static
void _get_exec_name_args(char** cmdline, gsize length, char** name, char** args)
{
    g_assert(length != 0);
    *args = NULL;

    gsize name_pos = 0;

    if (cmdline[0] != NULL) {
        char* space_pos = NULL;
        if ((space_pos = strchr(cmdline[0], ' ')) != NULL && g_strrstr(cmdline[0], "chrom") != NULL) {
            *space_pos = '\0';
            for (gsize i = length - 1; i > 0; --i) {
                cmdline[i + 1] = cmdline[i];
            }
            length += 1;
            cmdline[1] = space_pos + 1;
        }
        char* basename = g_path_get_basename(cmdline[0]);
        if (g_regex_match(prefix_regex, basename, 0, NULL)) {
            g_debug("prefix match");
            while (cmdline[name_pos + 1] && cmdline[++name_pos][0] == '-') {
                g_debug("name pos changed");
            }
        }
        g_free(basename);
    }

    cmdline[length] = NULL;

    int diff = length - name_pos;
    if (diff == 0) {
        *name = g_path_get_basename(cmdline[0]);
        if (length > 1) {
            *args = g_strjoinv(" ", cmdline+1);
        }
    } else if (diff >= 1){
        *name = g_path_get_basename(cmdline[name_pos]);
        if (diff >= 2)
            *args = g_strjoinv(" ", cmdline + name_pos + 1);
    }

    char* tmp = *name;
    g_assert(tmp != NULL);
    g_assert(suffix_regex != NULL);
    *name = g_regex_replace_literal (suffix_regex, tmp, -1, 0, "", 0, NULL);
    g_free(tmp);

    for (guint i=0; i<strlen(*name); i++) {
        if ((*name)[i] == ' ') {
            (*name)[i] = '\0';
            break;
        }
    }
}
コード例 #14
0
ファイル: requests.c プロジェクト: GnLWeB/balde
gchar*
balde_urldecode(const gchar* str)
{
    // corner case: + -> ' '
    GRegex *re_space = g_regex_new("\\+", 0, 0, NULL);
    gchar *new_str = g_regex_replace_literal(re_space, str, -1, 0, "%20", 0, NULL);
    g_regex_unref(re_space);
    gchar *rv = g_uri_unescape_string(new_str, NULL);
    g_free(new_str);
    return rv;
}
コード例 #15
0
gchar *special_to_actual_chars (const gchar *file) {
	GRegex *regex;
	gchar *f;
	
	if (!file)
		return NULL;
	regex = g_regex_new("%20", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL);
	f = g_strstrip(g_regex_replace_literal(regex, file, -1, 0, " ", 0, NULL));
	
	return f;
}
コード例 #16
0
ファイル: main.c プロジェクト: dram/configs
void update_client_side_ui_cb(FcitxClient *client,
			      char *auxup,
			      char *auxdown,
			      char *preedit,
			      char *candidateword,
			      char *imname,
			      int cursorpos,
			      void *user_data)
{
	GString *data;
	GSocket *connection = user_data;

	data = g_string_new("");

	if (!committed->len)
		g_string_assign(committed, "nil");

	if (candidateword[0] == '1') {
		GRegex *regex;
		gchar *candidates;

		regex = g_regex_new(" \\d+\\.", 0, 0, NULL);

		candidateword += 2;
		candidateword[strlen(candidateword) - 1] = 0;

		candidates = g_regex_replace_literal(regex,
						     candidateword,
						     -1,
						     0,
						     "\" \"",
						     0,
						     NULL);

		g_string_printf(data, "'(\"%s\" (\"%s\") %s)",
				preedit, candidates, committed->str);

		g_free(candidates);
		g_free(regex);
	} else {
		g_string_printf(data, "'(\"%s\" () %s)",
				preedit, committed->str);
	}

	if (g_socket_send(connection,
			  data->str, data->len, NULL, NULL) == -1) {
		perror("g_socket_send");
		exit(1);
	}

	g_string_truncate(committed, 0);

	g_string_free(data, TRUE);
}
コード例 #17
0
ファイル: appmenu2menuorg.c プロジェクト: yavdr/yavdr-panel
char *filter(const char *str)
{
  GError *error = NULL;
  GRegex *regex;
  char *result;

  regex = g_regex_new(" [^ ]*%[fFuUdDnNickvm]", 0, 0, &error);
  result = g_regex_replace_literal(regex, str, strlen(str), 0, "", 0, &error);
  g_regex_unref(regex);
 
  return result;
}
コード例 #18
0
ファイル: util.c プロジェクト: vifino/dwb
char *
util_string_replace(const char *haystack, const char *needle, const char *replacement) 
{
    char *ret = NULL;
    if ( haystack && needle) 
    { 
        GRegex *regex = g_regex_new(needle, 0, 0, NULL);
        ret = g_regex_replace_literal(regex, haystack, -1, 0, replacement, 0, NULL);
        g_regex_unref(regex);
    }
    return ret;
}/*}}}*/
コード例 #19
0
ファイル: gstglsl.c プロジェクト: alessandrod/gst-plugins-bad
static gchar *
_mangle_varying_attribute (const gchar * str, guint shader_type,
    GstGLSLVersion version, GstGLSLProfile profile)
{
  if (shader_type == GL_VERTEX_SHADER) {
    if (profile == GST_GLSL_PROFILE_CORE || (profile == GST_GLSL_PROFILE_ES
            && version >= GST_GLSL_VERSION_300)) {
      gchar *tmp, *tmp2;
      GRegex *regex;

      /* followed by some whitespace  */
      regex = g_regex_new ("varying(?=\\s)", 0, 0, NULL);
      tmp = g_regex_replace_literal (regex, str, -1, 0, "out", 0, NULL);
      g_regex_unref (regex);

      /* followed by some whitespace  */
      regex = g_regex_new ("attribute(?=\\s)", 0, 0, NULL);
      tmp2 = g_regex_replace_literal (regex, tmp, -1, 0, "in", 0, NULL);
      g_regex_unref (regex);

      g_free (tmp);
      return tmp2;
    }
  } else if (shader_type == GL_FRAGMENT_SHADER) {
    if (profile == GST_GLSL_PROFILE_CORE || (profile == GST_GLSL_PROFILE_ES
            && version >= GST_GLSL_VERSION_300)) {
      gchar *tmp;
      GRegex *regex;

      /* followed by some whitespace  */
      regex = g_regex_new ("varying(?=\\s)", 0, 0, NULL);
      tmp = g_regex_replace_literal (regex, str, -1, 0, "in", 0, NULL);
      g_regex_unref (regex);

      return tmp;
    }
  }
  return g_strdup (str);
}
コード例 #20
0
gchar *parse_expand_tilde(const gchar *f)
{
	gchar *ret;
	GRegex *regex;
	
	if (!f)
		return NULL;
	regex = g_regex_new("(?:^|(?<=[ \\t]))~(?:(?=[/ \\t])|$)",
						G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL);
	ret = g_regex_replace_literal(regex, f, -1, 0, g_get_home_dir(), 0, NULL);
	g_regex_unref(regex);
	
	return ret;
}
コード例 #21
0
gchar *grab_only_path (const gchar *file)
{
	GRegex *regex;
	gchar *f;

	if (!file)
		return NULL;
	regex = g_regex_new(" .*", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL);
	
	f = g_strstrip(special_to_actual_chars(g_regex_replace_literal(regex, get_file_path(file), -1, 0, "", 0, NULL)));

	g_regex_unref(regex);
	return f;
}
コード例 #22
0
ファイル: gstglsl.c プロジェクト: alessandrod/gst-plugins-bad
static gchar *
_mangle_texture_access (const gchar * str, GstGLContext * context,
    GstGLTextureTarget from, GstGLTextureTarget to, GstGLSLVersion version,
    GstGLSLProfile profile)
{
  const gchar *from_str = NULL, *to_str = NULL;
  gchar *ret, *tmp;
  gchar *regex_find;
  GRegex *regex;

  if (from == GST_GL_TEXTURE_TARGET_2D)
    from_str = "texture2D";
  if (from == GST_GL_TEXTURE_TARGET_RECTANGLE)
    from_str = "texture2DRect";
  if (from == GST_GL_TEXTURE_TARGET_EXTERNAL_OES)
    from_str = "texture2D";

  /* GL3 || gles3 but not when external-oes unless the image_external_essl3 extension is supported */
  if (profile == GST_GLSL_PROFILE_CORE || (profile == GST_GLSL_PROFILE_ES
          && version >= GST_GLSL_VERSION_300
          && (to != GST_GL_TEXTURE_TARGET_EXTERNAL_OES
              || gst_gl_context_check_feature (context,
                  "GL_OES_EGL_image_external_essl3")))) {
    to_str = "texture";
  } else {
    if (to == GST_GL_TEXTURE_TARGET_2D)
      to_str = "texture2D";
    if (to == GST_GL_TEXTURE_TARGET_RECTANGLE)
      to_str = "texture2DRect";
    if (to == GST_GL_TEXTURE_TARGET_EXTERNAL_OES)
      to_str = "texture2D";
  }

  /* followed by any amount of whitespace then a bracket */
  regex_find = g_strdup_printf ("%s(?=\\s*\\()", from_str);
  regex = g_regex_new (regex_find, 0, 0, NULL);
  tmp = g_regex_replace_literal (regex, str, -1, 0, to_str, 0, NULL);
  g_free (regex_find);
  g_regex_unref (regex);

  if (tmp) {
    ret = tmp;
  } else {
    GST_FIXME ("Couldn't mangle texture access successfully from %s to %s",
        from_str, to_str);
    ret = g_strdup (str);
  }

  return ret;
}
コード例 #23
0
ファイル: parser.c プロジェクト: reiver-dev/menugen
char *parse_expand_tilde(const char *from) {
    GRegex *regex;
    char *result;

    if (!from) {
        return NULL;
    }

    regex = g_regex_new("(?:^|(?<=[ \\t]))~(?:(?=[/ \\t])|$)", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL);
    result= g_regex_replace_literal(regex, from, -1, 0, g_get_home_dir(), 0, NULL);
    g_regex_unref(regex);

    return result;
}
コード例 #24
0
static gchar *
video_sanitise_string (const gchar *str)
{
  int    i;
  gchar *line, *line_end;
  GRegex *regex;

  line = (gchar *) str;
  for (i = 0; video_blacklisted_prefix[i]; i++) {
    if (g_str_has_prefix (str, video_blacklisted_prefix[i])) {
      int len = strlen (video_blacklisted_prefix[i]);

      line = (gchar *) str + len;
    }
  }

  /* Get the substring limited by the first blacklisted word */
  line_end = line + strlen (line);
  for (i = 0; video_blacklisted_words[i]; i++) {
    gchar *end;

    end = strcasestr (line, video_blacklisted_words[i]);
    if (end && end < line_end) {
      line_end = end;
    }
  }

  if (*line_end != '\0') {
    /* After removing substring with blacklisted word, ignore non alpha-numeric
     * char in the end of the sanitised string */
    do {
      line_end = g_utf8_find_prev_char (line, line_end);
    } while (is_nonalnum (line_end));

    /* If everything in the string is blacklisted, just ignore
     * the blackisting logic.
     */
    if (line_end == NULL) {
      return g_strdup (str);
    }

    return g_strndup (line, line_end - line);
  }

  regex = g_regex_new ("\\.-\\.", 0, 0, NULL);
  line = g_regex_replace_literal(regex, line, -1, 0, ".", 0, NULL);
  g_regex_unref(regex);

  return line;
}
コード例 #25
0
static char* string_replace (const char* self, const char* old, const char* replacement) {
	GError * _inner_error_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	_inner_error_ = NULL;
	{
		char* _tmp0_;
		GRegex* _tmp1_;
		GRegex* regex;
		char* _tmp2_;
		char* _tmp3_;
		_tmp0_ = NULL;
		_tmp1_ = NULL;
		regex = (_tmp1_ = g_regex_new (_tmp0_ = g_regex_escape_string (old, -1), 0, 0, &_inner_error_), _tmp0_ = (g_free (_tmp0_), NULL), _tmp1_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			goto __finally4;
		}
		_tmp2_ = g_regex_replace_literal (regex, self, (glong) (-1), 0, replacement, 0, &_inner_error_);
		if (_inner_error_ != NULL) {
			(regex == NULL) ? NULL : (regex = (g_regex_unref (regex), NULL));
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			goto __finally4;
		}
		_tmp3_ = NULL;
		return (_tmp3_ = _tmp2_, (regex == NULL) ? NULL : (regex = (g_regex_unref (regex), NULL)), _tmp3_);
	}
	goto __finally4;
	__catch4_g_regex_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			g_assert_not_reached ();
			(e == NULL) ? NULL : (e = (g_error_free (e), NULL));
		}
	}
	__finally4:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, _inner_error_->message);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}
コード例 #26
0
ファイル: pdf.c プロジェクト: Debian/gpdftext
/** 
 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));
}
コード例 #27
0
ファイル: regex.c プロジェクト: zakkudo/gwaei
gchar*
lw_regex_remove_kanji_dictionary_spacers (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 = "";

    //Initializtions
    regex = _cached_regexes[LW_RE_KANJI_DICTIONARY_SPACERS];
    output = g_regex_replace_literal (regex, TEXT, -1, 0, replacement, 0, NULL);

    return output;
}
コード例 #28
0
ファイル: gstglsl.c プロジェクト: alessandrod/gst-plugins-bad
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;
}
コード例 #29
0
static gchar *
replace_string (gchar **string, const gchar *search, const char *replacement)
{
	GRegex *regex;
	gchar *res;

	g_return_val_if_fail (*string != NULL, NULL);
	g_return_val_if_fail (string != NULL, NULL);
	g_return_val_if_fail (search != NULL, *string);
	g_return_val_if_fail (replacement != NULL, *string);

	regex = g_regex_new (search, 0, 0, NULL);
	res = g_regex_replace_literal (regex, *string, -1, 0, replacement, 0, NULL);
	g_regex_unref (regex);
	/* The given string is freed and replaced by the resulting replacement */
	g_free (*string);
	*string = res;

	return res;
}
コード例 #30
0
ファイル: regex-dna2.c プロジェクト: cyrta/sandbox
/* Substitute each occurrence of the regular expression "regex" in "s"
 * with "subst".  The result is returned in a newly allocate string
 * that must be freed with g_free(). */
static char*
regsub(const char* regex,
       const char* s,
       const char* subst,
       GError** err)
{
    char* rv = NULL;
    GRegex* prog = NULL;

    /* How glib propagates exceptions. */
    if (err && *err) {
        goto out;
    }

    /* Compile regex. */
    prog = g_regex_new(regex,
                       G_REGEX_CASELESS |
                       G_REGEX_RAW |
                       G_REGEX_NO_AUTO_CAPTURE |
                       G_REGEX_OPTIMIZE,
                       0,
                       err);
    if (err && *err) {
        goto out;
    }

    /* Substitute. */
    rv = g_regex_replace_literal(prog, s, -1, 0, subst, 0, err);
    if (err && *err) {
        goto out;
    }

 out:

    /* Clean up. */
    if (prog) {
        g_regex_unref(prog);
    }

    return rv;
}