示例#1
0
	RE2Regex(const std::string& rx) : Regex(rx), regexcl(rx, RE2::Quiet)
	{
		if (!regexcl.ok())
		{
			throw RegexException(rx, regexcl.error());
		}
	}
示例#2
0
文件: RegexPCRE.cpp 项目: mdaus/nitro
Regex& Regex::compile(const std::string& pattern)
{
    mPattern = pattern;

    destroy();

    // TODO: So, I would like an RAII object for this.  But, this object would
    //       need to call pcre2_compile() in its constructor rather than take
    //       ownership of a pointer (so that it has access to the error code
    //       information on failure) and its copy constructor / assignment
    //       operator would need to hold onto mPattern.  At that point the
    //       class is close to being this Regex class itself.
    static const int FLAGS = PCRE2_DOTALL;
    int errorCode;
    PCRE2_SIZE errorOffset;
    mPCRE = pcre2_compile(reinterpret_cast<PCRE2_SPTR>(mPattern.c_str()),
                          mPattern.length(),
                          FLAGS,
                          &errorCode,
                          &errorOffset,
                          NULL); // Use default compile context

    if (mPCRE == NULL)
    {
        std::ostringstream ostr;
        ostr << "PCRE compilation failed at offset " << errorOffset
             << ": " << getErrorMessage(errorCode);
        throw RegexException(Ctxt(ostr.str()));
    }

    return *this;
}
示例#3
0
	PCRERegex(const Anope::string &expr) : Regex(expr)
	{
		const char *error;
		int erroffset;
		this->regex = pcre_compile(expr.c_str(), PCRE_CASELESS, &error, &erroffset, NULL);
		if (!this->regex)
			throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + error); 
	}
示例#4
0
	StdRegex(const std::string& rx, std::regex::flag_type fltype) : Regex(rx)
	{
		try{
			regexcl.assign(rx, fltype | std::regex::optimize);
		}
		catch(std::regex_error rxerr)
		{
			throw RegexException(rx, rxerr.what());
		}
	}
示例#5
0
	PCRERegex(const std::string& rx) : Regex(rx)
	{
		const char* error;
		int erroffset;
		regex = pcre_compile(rx.c_str(), 0, &error, &erroffset, NULL);
		if (!regex)
		{
			ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
			throw RegexException(rx, error, erroffset);
		}
	}
示例#6
0
	POSIXRegex(const Anope::string &expr) : Regex(expr)
	{
		int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB);
		if (err)
		{
			char buf[BUFSIZE];
			regerror(err, &this->regbuf, buf, sizeof(buf));
			regfree(&this->regbuf);
			throw RegexException("Error in regex " + expr + ": " + buf);
		}
	}
示例#7
0
		void Regex::compile(){
			regex_t *r;
			int ret;
			if(handle == 0){
				r = new regex_t;
				handle = (void *)r;
			}
			else{
				r = (regex_t *)handle;
			}
			if(_pattern == 0)
				throw NullPointer();
			ret = regcomp(r, _pattern->toCharPtr(), cflags);
			if(ret != 0){
				throw RegexException(ret);
			}
			compiled = true;
		}
示例#8
0
	POSIXRegex(const std::string& rx, bool extended) : Regex(rx)
	{
		int flags = (extended ? REG_EXTENDED : 0) | REG_NOSUB;
		int errcode;
		errcode = regcomp(&regbuf, rx.c_str(), flags);
		if (errcode)
		{
			// Get the error string into a std::string. YUCK this involves at least 2 string copies.
			std::string error;
			char* errbuf;
			size_t sz = regerror(errcode, &regbuf, NULL, 0);
			errbuf = new char[sz + 1];
			memset(errbuf, 0, sz + 1);
			regerror(errcode, &regbuf, errbuf, sz + 1);
			error = errbuf;
			delete[] errbuf;
			regfree(&regbuf);
			throw RegexException(rx, error);
		}
	}