/* * $Source$ * $Revision$ * $Date$ * * Copyright (C) 1996 by CyberSolutions GmbH. * All rights reserved. */ #include #include #include "text.h" /* Simple front end to regular expressions. This is a simple front end to make the usage of regular expressions easier. The routine tests whether the pattern provided in 'pattern' matches the text in 'buffer' or not. Comparisons are done case-insensitive, using the extended regular expression language. RETURNS: If the pattern matches, TRUE is returned. Otherwise the routine will return FALSE. NOTE: The error handling is somewhat relaxed... well, don't use the routine if you need error handling. AUTHOR: Peter Simons */ bool text_easy_pattern_match(const char * buffer, /* text buffer */ const char * pattern /* regular expression */ ) { regex_t preg; int rc; /* Sanity checks. */ assert(buffer != NULL); assert(pattern != NULL); if (!buffer || !pattern) return FALSE; /* Compile the regular expression. */ rc = regcomp(&preg, pattern, REG_EXTENDED | REG_ICASE | REG_NOSUB | REG_NEWLINE); if (rc != 0) return FALSE; /* Match it. */ rc = regexec(&preg, buffer, 0, NULL, 0); regfree(&preg); if (rc == 0) return TRUE; else return FALSE; }