Added strrstr_skip_count() function.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-04-26 10:25:10 +03:00
parent fc8a86766b
commit 91f3d8f4fd
2 changed files with 29 additions and 0 deletions

View File

@ -524,6 +524,12 @@ int str_verscmp (const char *s1, const char *s2);
*/
void str_msg_term_size (const char *text, int *lines, int *columns);
/**
skip first <skip_count> needle's in haystack and returns pointer to
<skip_count+1> needle (or NULL if not found).
*/
char *strrstr_skip_count (const char *haystack, const char *needle, size_t skip_count);
/*** inline functions ****************************************************************************/
static inline void

View File

@ -803,3 +803,26 @@ str_msg_term_size (const char *text, int *lines, int *columns)
g_free (tmp);
}
/* --------------------------------------------------------------------------------------------- */
char *
strrstr_skip_count (const char *haystack, const char *needle, size_t skip_count)
{
char *semi;
ssize_t len;
len = strlen (haystack);
do
{
semi = g_strrstr_len (haystack, len, needle);
if (semi == NULL)
return NULL;
len = semi - haystack - 1;
}
while (skip_count-- != 0);
return semi;
}
/* --------------------------------------------------------------------------------------------- */