radare2/libr/util/re.c
pancake 78dbab76d6 * Added basic working example in swig-python for r_util
* Add _write and _puts methods for r_socket api
  - fgets -> gets
  - fix r_socket_printf
* More random fixes
* typedef all structures in r_util
2009-12-22 13:27:43 +01:00

30 lines
648 B
C

/* radare - LGPL - Copyright 2007-2009 pancake<nopcode.org> */
#include <r_util.h>
#if HAVE_REGEXP
#include <regex.h>
/* XXX: This code uses POSIX 2001 . can be nonportable */
#define NUM_MATCHES 16
#endif
/* returns 1 if 'str' matches 'reg' regexp */
R_API int r_str_re_match(const char *str, const char *reg)
{
#if HAVE_REGEXP
regex_t preg;
regmatch_t pmatch[NUM_MATCHES];
if (regcomp(&preg, reg, REG_EXTENDED))
return -1;
return (regexec (&preg, str, NUM_MATCHES, pmatch, 0))?1:0;
#else
return -1;
#endif
}
R_API int r_str_re_replace(const char *str, const char *reg, const char *sub)
{
/* TODO: not yet implemented */
return -1;
}