Beispiel #1
0
int main()
{
   regex_tA re;
   int result;
   result = regcompA(&re, expression, REG_AWK);
   if(result > (int)REG_NOERROR)
   {
      char buf[256];
      regerrorA(result, &re, buf, sizeof(buf));
      printf(buf);
      return result;
   }
   assert(re.re_nsub == 0);
   matches[0].rm_so = 0;
   matches[0].rm_eo = strlen(text);
   result = regexecA(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
   if(result > (int)REG_NOERROR)
   {
      char buf[256];
      regerrorA(result, &re, buf, sizeof(buf));
      printf(buf);
      regfreeA(&re);
      return result;
   }
   assert((matches[0].rm_so == matches[0].rm_eo) && (matches[0].rm_eo == 1));
   regfreeA(&re);
   printf("no errors found\n");
   return 0;
}
Beispiel #2
0
AUTOBOOST_REGEX_DECL int AUTOBOOST_REGEX_CCALL regcompA(regex_tA* expression, const char* ptr, int f)
{
   if(expression->re_magic != magic_value)
   {
      expression->guts = 0;
#ifndef AUTOBOOST_NO_EXCEPTIONS
      try{
#endif
      expression->guts = new c_regex_type();
#ifndef AUTOBOOST_NO_EXCEPTIONS
      } catch(...)
      {
         return REG_ESPACE;
      }
#else
      if(0 == expression->guts)
         return REG_E_MEMORY;
#endif
   }
   // set default flags:
   autoboost::uint_fast32_t flags = (f & REG_PERLEX) ? 0 : ((f & REG_EXTENDED) ? regex::extended : regex::basic);
   expression->eflags = (f & REG_NEWLINE) ? match_not_dot_newline : match_default;
   // and translate those that are actually set:

   if(f & REG_NOCOLLATE)
   {
      flags |= regex::nocollate;
#ifndef AUTOBOOST_REGEX_V3
      flags &= ~regex::collate;
#endif
   }

   if(f & REG_NOSUB)
   {
      //expression->eflags |= match_any;
      flags |= regex::nosubs;
   }

   if(f & REG_NOSPEC)
      flags |= regex::literal;
   if(f & REG_ICASE)
      flags |= regex::icase;
   if(f & REG_ESCAPE_IN_LISTS)
      flags &= ~regex::no_escape_in_lists;
   if(f & REG_NEWLINE_ALT)
      flags |= regex::newline_alt;

   const char* p2;
   if(f & REG_PEND)
      p2 = expression->re_endp;
   else p2 = ptr + std::strlen(ptr);

   int result;

#ifndef AUTOBOOST_NO_EXCEPTIONS
   try{
#endif
      expression->re_magic = magic_value;
      static_cast<c_regex_type*>(expression->guts)->set_expression(ptr, p2, flags);
      expression->re_nsub = static_cast<c_regex_type*>(expression->guts)->mark_count();
      result = static_cast<c_regex_type*>(expression->guts)->error_code();
#ifndef AUTOBOOST_NO_EXCEPTIONS
   }
   catch(const autoboost::regex_error& be)
   {
      result = be.code();
   }
   catch(...)
   {
      result = REG_E_UNKNOWN;
   }
#endif
   if(result)
      regfreeA(expression);
   return result;

}