Eric Blake <ebl...@redhat.com> writes: > On 02/04/2016 03:26 PM, Richard Henderson wrote: >> On 02/05/2016 01:56 AM, Alex Bennée wrote: >>> + if (g_strrstr(filename, "%d")) { >>> + /* if we are going to format this we'd better validate first */ >>> + if (g_regex_match_simple("^[^%]+%d[^%]+$", filename, 0, 0)) { >> >> Why g_strrstr instead of strstr? There should be only one, so why look >> for the last?
Yeah, my fault for using the glib functions, I guess g_strstr_len(filename, -1, "%d") would be the glib equivalent for strstr. > For that matter, why use a heavyweight regex, when you can achieve the > same validation with the faster: > > char *tmp = strchr(filename, '%'); > if (tmp) { > if (tmp[1] != 'd' || strchr(tmp + 2, '%')) { > ...report invalid string > } For option parsing I'm not too worried about speed. At least a regex gives the explicit format we expect (for those that read regex). I guess I can do it manually if preferred. -- Alex Bennée