Definition in file duifilter.c.
#include <stdlib.h>
#include <string.h>
#include "duifilter.h"
#include "perr.h"
Go to the source code of this file.
Defines | |
| #define | ADD_FILT(name, func) |
Functions | |
| static void | filters_init (void) |
| DuiFilter * | dui_filter_new (const gchar *name, const gchar *revname) |
| static const gchar * | is_null (const gchar *val) |
| static const gchar * | is_whitespace_or_null (const gchar *val) |
| const gchar * | whitespace_filter (const gchar *val) |
| static const gchar * | to_int_filter (const gchar *val) |
| gint | dui_util_bool_to_int (const gchar *val) |
| void | dui_filter_add_lookup (DuiFilter *filt, const gchar *key, const gchar *val) |
| const gchar * | dui_filter_apply (DuiFilter *filt, const gchar *str) |
| DuiFilter * | dui_filter_find_by_name (const gchar *filtername) |
Variables | |
| static GHashTable * | filter_table = NULL |
| #define ADD_FILT | ( | name, | |||
| func | ) |
Value:
{ \
DuiFilter *filt = dui_filter_new(name, NULL); \
filt->filter = func; \
}
Definition at line 177 of file duifilter.c.
| void dui_filter_add_lookup | ( | DuiFilter * | , | |
| const gchar * | key, | |||
| const gchar * | value | |||
| ) |
add to the lookup table
Definition at line 154 of file duifilter.c.
00155 { 00156 gchar *keyc, *valc; 00157 if (!filt) return; 00158 00159 if (!filt->lookup_table) 00160 { 00161 filt->lookup_table = g_hash_table_new (g_str_hash, g_str_equal); 00162 } 00163 00164 keyc = g_strdup (key); 00165 valc = g_strdup (val); 00166 g_hash_table_insert (filt->lookup_table, keyc, valc); 00167 00168 /* if we have a reversed filter, then add key-val reveresed */ 00169 if (filt->rev_filter) 00170 { 00171 dui_filter_add_lookup (filt->rev_filter, val, key); 00172 } 00173 }
| const gchar* dui_filter_apply | ( | DuiFilter * | , | |
| const gchar * | ||||
| ) |
apply the indicated filter to the string, returning the result string
Definition at line 197 of file duifilter.c.
00198 { 00199 if (!filt) return str; 00200 00201 if (filt->filter) 00202 { 00203 return (filt->filter) (str); 00204 } 00205 00206 if (!str) return NULL; 00207 if (filt->lookup_table) 00208 { 00209 return g_hash_table_lookup (filt->lookup_table, str); 00210 } 00211 PWARN ("filter \"%s\" can't be found", filt->name); 00212 return str; 00213 }
| gint dui_util_bool_to_int | ( | const gchar * | val | ) |
Return integer 1 if the string starts with 't' or 'T" or contians the word 'true' or 'TRUE';if string is a number, return that number.
Definition at line 135 of file duifilter.c.
00136 { 00137 const gchar * p = whitespace_filter (val); 00138 if (!p) return 0; 00139 if ('t' == p[0]) return 1; 00140 if ('T' == p[0]) return 1; 00141 if ('y' == p[0]) return 1; 00142 if ('Y' == p[0]) return 1; 00143 if (strstr (p, "true")) return 1; 00144 if (strstr (p, "TRUE")) return 1; 00145 if (strstr (p, "yes")) return 1; 00146 if (strstr (p, "YES")) return 1; 00147 return atoi (val); 00148 }
| static const gchar* to_int_filter | ( | const gchar * | val | ) | [static] |
Definition at line 118 of file duifilter.c.
00119 { 00120 gint ival; 00121 static gchar intbuff[30]; 00124 if (!val) return "0"; 00125 ival = atoi (val); 00126 snprintf (intbuff, 30, "%d", ival); 00127 return intbuff; 00128 }
| const gchar* whitespace_filter | ( | const gchar * | val | ) |
return NULL if the field is whitespace (blank, tab, formfeed etc.)
Definition at line 104 of file duifilter.c.
00105 { 00106 size_t len; 00107 if (!val) return NULL; 00108 00109 len = strspn (val, "\a\b\t\n\v\f\r "); 00110 if (0 == val[len]) return NULL; 00111 return val+len; 00112 }
1.5.5