1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| gint gw_strcmp_strregex ( gchar *str, gchar *regex, gboolean case_sensitive)
{
regex_t *r;
gint cflags;
size_t no_sub;
regmatch_t *reg_result;
gint result = -1;
#ifdef GW_DEBUG_TOOLS_COMPONENT
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
#endif
if ( (r = (regex_t *) g_malloc ( sizeof ( regex_t))) != NULL )
{
if ( case_sensitive == FALSE )
{
cflags = REG_ICASE;
}
else
{
cflags = 0;
}
if ( regcomp ( r, regex, cflags) != 0 )
{
regfree ( r);
}
else
{
no_sub = r->re_nsub + 1;
if ( (reg_result = (regmatch_t *) g_malloc ( sizeof ( regmatch_t) * no_sub)) != NULL )
{
if ( regexec ( r, str, no_sub, reg_result, 0) == 0 )
{
g_free ( r);
result = 0;
}
g_free ( reg_result);
}
}
}
#ifdef GW_DEBUG_TOOLS_COMPONENT
if ( result == 0 )
{
g_print ( "*** GW - %s (%d) :: %s() : %s == %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, str, regex);
}
else
{
g_print ( "*** GW - %s (%d) :: %s() : %s <> %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, str, regex);
}
#endif
return result;
} |
Partager