Skip to content

Instantly share code, notes, and snippets.

@codingdave
Created February 8, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codingdave/27b12fd2be9421f539d130ec6c9d9173 to your computer and use it in GitHub Desktop.
Save codingdave/27b12fd2be9421f539d130ec6c9d9173 to your computer and use it in GitHub Desktop.
gchar *_string_get_next_variable(gchar *string, gchar *variable, const size_t max_variable_size)
{
gchar *end = NULL;
gchar *start = g_strstr_len(string, max_variable_size, "$(");
if(start)
{
end = g_strstr_len(start, max_variable_size, ")");
if(end)
{
const int length = end - start + 2;
g_strlcpy(variable, start, length);
// the string in variable is null terminated
end++;
}
}
// fprintf(stderr, "_string_get_next_variable: splitted %s in variable %s and remainder %s\n", string, variable,
// end);
return end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment