Ejemplo n.º 1
0
//////////////////////////////////////////////////////////////////////////
// ensure
/// INTERNAL ONLY
inline bool ensure(bool predicate, regex_constants::error_type code, char const *str = "")
{
    if(!predicate)
    {
        boost::throw_exception(regex_error(code, str));
    }
    return predicate;
}
Ejemplo n.º 2
0
	bool regex::search(char const *begin,char const *end,int /*flags*/) const
	{
		if(!d->re)
			throw regex_error("Empty expression");
		int res = pcre_exec(d->re,0,begin,end-begin,0,0,0,0);
		if(res < 0)
			return false;
		return true;
	}
regex_ptr compile_regex_boost_xpressive(const std::string& expr, int,
                                        const char* flags) {
  try {
    return regex_ptr(new xpressive_regex(expr, flags));
  }
  catch (const bxp::regex_error& error) {
    throw regex_error(error.what(), expr);
  }
}
Ejemplo n.º 4
0
 virtual sequence<BidiIter> quantify
 (
     quant_spec const & //spec
   , std::size_t & //hidden_mark_count
   , sequence<BidiIter> //seq
   , alternates_factory<BidiIter> const &//factory
 ) const
 {
     throw regex_error(regex_constants::error_badrepeat, "expression cannot be quantified");
 }
Ejemplo n.º 5
0
	void regex::assign(std::string const &pattern,int flags)
	{
		d.reset(new data());
		d->expression=pattern;
		d->flags = flags;
		char const *err_ptr = 0;
		int offset = 0;
		pcre *p=pcre_compile(pattern.c_str(),0,&err_ptr,&offset,0);
		if(!p) {
			std::ostringstream ss;
			ss << err_ptr <<", at offset "<<offset;
			throw regex_error(ss.str());
		}
		d->re = p;
		if(	pcre_fullinfo(d->re,NULL,PCRE_INFO_SIZE,&d->re_size) < 0
			|| pcre_fullinfo(d->re,NULL,PCRE_INFO_CAPTURECOUNT,&d->match_size) < 0)
		{
			throw regex_error("Internal error");
		}
		
		std::string anchored;
		anchored.reserve(pattern.size()+6);
		anchored+= "(?:";
		anchored+=pattern;
		anchored+=")\\z";

		p=pcre_compile(anchored.c_str(),0,&err_ptr,&offset,0);
		if(!p) {
			throw regex_error("Internal error");
		}
		d->are = p;
		if(pcre_fullinfo(d->are,NULL,PCRE_INFO_SIZE,&d->are_size) != 0)
		{
			throw regex_error("Internal error");
		}
	}
Ejemplo n.º 6
0
	bool regex::search(char const *begin,char const *end,std::vector<std::pair<int,int> > &marks,int /* flags */) const
	{
		if(!d->re)
			throw regex_error("Empty expression");
		marks.clear();
		int pat_size = mark_count() + 1;
		marks.resize(pat_size,std::pair<int,int>(-1,-1));

		std::vector<int> ovec((mark_count()+1)*3,0);
		int res = pcre_exec(d->re,0,begin,end-begin,0,0,&ovec.front(),ovec.size());
		if(res < 0)
			return false;
		for(int i=0;i<pat_size && i < res;i++) {
			marks[i].first=ovec[i*2];
			marks[i].second = ovec[i*2+1];
		}
		return true;
	}
Ejemplo n.º 7
0
void handle_escape(SimpleReBuilder * builder, char ** complexRe, int * len, int * bi, int * ci) {

    int i = *ci;
    int j = *bi;

    if (i+1 > *len)
        regex_error(i);

    i++; //go to escaped character and ignore '/'
    switch(DEREF(complexRe,i)) {

        case 't':
            insertIntoComplexRe(complexRe, --i, len, "\t");
            break;

        case 'n':
            insertIntoComplexRe(complexRe, --i, len, "\n");
            break;
        
        case 'd':
            insertIntoComplexRe(complexRe, --i, len, "[0-9]");
            break;

        case 'w':
            insertIntoComplexRe(complexRe, --i, len, "([a-z]|[A-Z]|_)");
            break;

        case 's':
            insertIntoComplexRe(complexRe, --i, len, "( |\t|\n)");
            break;

        /* ... see www.cs.tut.fi/~jkorpela/perl/regexp.html */
        
        // default is just ignoring the backslash and taking the 
        // LITERAL character after no matter what
        default:
            builder->re[j++] = DEREF(complexRe, i++);
            break;
    }

    *ci = i-1; //-1 because we incremented at the end
    *bi = j-1; //-1 because we incremented at the end
}
Ejemplo n.º 8
0
//////////////////////////////////////////////////////////////////////////
// ensure
/// INTERNAL ONLY
inline bool ensure(bool predicate, regex_constants::error_type code, char const *str = "")
{
    return predicate ? true : throw regex_error(code, str);
}
Ejemplo n.º 9
0
 virtual void repeat(quant_spec const &, sequence<BidiIter> &) const
 {
     boost::throw_exception(
         regex_error(regex_constants::error_badrepeat, "expression cannot be quantified")
     );
 }
Ejemplo n.º 10
0
 virtual bool is_quantifiable() const
 {
     BOOST_ASSERT(false);
     throw regex_error(regex_constants::error_internal, "internal error, sorry!");
 }