#pragma once
#include "regex.h"

Regex::Regex(string regex) {
	_regular_expression = new regex_backing_type(regex.c_str());
	this->regex = new string(regex);
}
Regex::Regex(const char* regex) {
	_regular_expression = new regex_backing_type(regex);
	this->regex = new string(regex);
}
Regex::~Regex() {
	delete _regular_expression;
	delete regex;
}

bool Regex::find_from_start(const char* str, unsigned long str_len, int* end) {
	//MatchResult mr = _regular_expression->Match(str,false);
	MatchResult mr = _regular_expression->Match(str,str_len,-1,NULL,false);

	bool matched = mr.IsMatched()==1;
	if (!matched) return false;

	*end = mr.GetEnd();

	return true;
}
bool Regex::find_in(const char* str, unsigned long str_len, int* start, int* end) {
	MatchResult mr = _regular_expression->Match(str);

	bool matched = mr.IsMatched()==1;
	if (!matched) return false;

	*start = mr.GetStart();
	*end = mr.GetEnd();

	return true;
}