Skip to content
Snippets Groups Projects
Commit 9ab1c0eb authored by Simon McVittie's avatar Simon McVittie
Browse files

utils: Factor out _srt_string_ends_with_len()


If the length is already known, this avoids recalculating it (and if
the suffix contains embedded NULs, this makes it possible to check for).

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 9ec469a4
No related branches found
No related tags found
1 merge request!781Test coverage and refactoring in preparation for steamrt/tasks#595
......@@ -604,6 +604,23 @@ gboolean _srt_string_read_fd_until_eof (GString *buf,
int fd,
GError **error);
/*
* _srt_string_ends_with_len:
* @str: A #GString
* @suffix: A suffix
* @len: Length of suffix
*
* Returns: %TRUE if @str ends with @suffix
*/
static inline gboolean
_srt_string_ends_with_len (const GString *str,
const char *suffix,
gsize len)
{
return (str->len >= len
&& memcmp (str->str + str->len - len, suffix, len) == 0);
}
/*
* _srt_string_ends_with:
* @str: A #GString
......@@ -615,10 +632,7 @@ static inline gboolean
_srt_string_ends_with (const GString *str,
const char *suffix)
{
size_t len = strlen (suffix);
return (str->len >= len
&& strcmp (str->str + str->len - len, suffix) == 0);
return _srt_string_ends_with_len (str, suffix, strlen (suffix));
}
gboolean _srt_is_identifier (const char *name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment