@@ -34,10 +34,6 @@ using namespace http;
3434
3535http_endpoint::~http_endpoint ()
3636{
37- if (reg_compiled)
38- {
39- regfree (&(this ->re_url_normalized ));
40- }
4137}
4238
4339http_endpoint::http_endpoint
@@ -118,9 +114,7 @@ http_endpoint::http_endpoint
118114 if (use_regex)
119115 {
120116 this ->url_normalized += " $" ;
121- regcomp (&(this ->re_url_normalized ), url_normalized.c_str (),
122- REG_EXTENDED|REG_ICASE|REG_NOSUB
123- );
117+ this ->re_url_normalized = std::regex (url_normalized, std::regex_constants::icase & std::regex_constants::nosubs & std::regex_constants::extended);
124118 this ->reg_compiled = true ;
125119 }
126120}
@@ -131,35 +125,50 @@ http_endpoint::http_endpoint(const http_endpoint& h):
131125 url_pars (h.url_pars),
132126 url_pieces (h.url_pieces),
133127 chunk_positions (h.chunk_positions),
128+ re_url_normalized (h.re_url_normalized),
129+ family_url (h.family_url),
130+ reg_compiled (h.reg_compiled)
131+ {
132+ }
133+
134+ http_endpoint::http_endpoint (http_endpoint&& h):
135+ url_complete (std::move(h.url_complete)),
136+ url_normalized (std::move(h.url_normalized)),
137+ url_pars (std::move(h.url_pars)),
138+ url_pieces (std::move(h.url_pieces)),
139+ chunk_positions (std::move(h.chunk_positions)),
140+ re_url_normalized (std::move(h.re_url_normalized)),
134141 family_url (h.family_url),
135142 reg_compiled (h.reg_compiled)
136143{
137- if (this ->reg_compiled )
138- regcomp (&(this ->re_url_normalized ), url_normalized.c_str (),
139- REG_EXTENDED|REG_ICASE|REG_NOSUB
140- );
141144}
142145
143- http_endpoint& http_endpoint::operator =(const http_endpoint& h)
146+ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
144147{
145148 this ->url_complete = h.url_complete ;
146149 this ->url_normalized = h.url_normalized ;
147150 this ->family_url = h.family_url ;
148151 this ->reg_compiled = h.reg_compiled ;
149- if (this ->reg_compiled )
150- {
151- regfree (&(this ->re_url_normalized ));
152-
153- regcomp (&(this ->re_url_normalized ), url_normalized.c_str (),
154- REG_EXTENDED|REG_ICASE|REG_NOSUB
155- );
156- }
152+ this ->re_url_normalized = h.re_url_normalized ;
157153 this ->url_pars = h.url_pars ;
158154 this ->url_pieces = h.url_pieces ;
159155 this ->chunk_positions = h.chunk_positions ;
160156 return *this ;
161157}
162158
159+ http_endpoint& http_endpoint::operator =(http_endpoint&& h)
160+ {
161+ this ->url_complete = std::move (h.url_complete );
162+ this ->url_normalized = std::move (h.url_normalized );
163+ this ->family_url = h.family_url ;
164+ this ->reg_compiled = h.reg_compiled ;
165+ this ->re_url_normalized = std::move (h.re_url_normalized );
166+ this ->url_pars = std::move (h.url_pars );
167+ this ->url_pieces = std::move (h.url_pieces );
168+ this ->chunk_positions = std::move (h.chunk_positions );
169+ return *this ;
170+ }
171+
163172bool http_endpoint::operator <(const http_endpoint& b) const
164173{
165174 COMPARATOR (this ->url_normalized , b.url_normalized , std::toupper);
@@ -170,7 +179,7 @@ bool http_endpoint::match(const http_endpoint& url) const
170179 if (!this ->reg_compiled ) throw std::invalid_argument (" Cannot run match. Regex suppressed." );
171180
172181 if (!this ->family_url || url.url_pieces .size () < this ->url_pieces .size ())
173- return regexec (&( this -> re_url_normalized ), url.url_complete . c_str (), 0 , NULL , 0 ) == 0 ;
182+ return regex_match ( url.url_complete , this -> re_url_normalized ) ;
174183
175184 string nn = " /" ;
176185 bool first = true ;
@@ -179,7 +188,7 @@ bool http_endpoint::match(const http_endpoint& url) const
179188 nn += (first ? " " : " /" ) + url.url_pieces [i];
180189 first = false ;
181190 }
182- return regexec (&( this ->re_url_normalized ), nn. c_str (), 0 , NULL , 0 ) == 0 ;
191+ return regex_match (nn, this ->re_url_normalized );
183192}
184193
185194};
0 commit comments