Skip to content

Commit 86e1b4f

Browse files
authored
Merge branch 'main' into main
2 parents c6fd7ee + 2e7c7d0 commit 86e1b4f

6 files changed

Lines changed: 186 additions & 171 deletions

File tree

include/ctre/evaluation.hpp

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -294,46 +294,46 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
294294

295295
if constexpr (B != 0 && A > B) {
296296
return not_matched;
297-
}
298-
299-
const Iterator backup_current = current;
297+
} else {
298+
const Iterator backup_current = current;
300299

301-
size_t i{0};
300+
size_t i{0};
302301

303-
while (less_than<A>(i)) {
304-
auto outer_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
302+
while (less_than<A>(i)) {
303+
auto outer_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
305304

306-
if (!outer_result) return not_matched;
305+
if (!outer_result) return not_matched;
307306

308-
captures = outer_result.unmatch();
309-
current = outer_result.get_end_position();
307+
captures = outer_result.unmatch();
308+
current = outer_result.get_end_position();
310309

311-
++i;
312-
}
310+
++i;
311+
}
313312

314-
if (auto outer_result = evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>())) {
315-
return outer_result;
316-
}
313+
if (auto outer_result = evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>())) {
314+
return outer_result;
315+
}
317316

318-
while (less_than_or_infinite<B>(i)) {
319-
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
317+
while (less_than_or_infinite<B>(i)) {
318+
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
320319

321-
if (!inner_result) return not_matched;
320+
if (!inner_result) return not_matched;
322321

323-
auto outer_result = evaluate(begin, inner_result.get_end_position(), end, consumed_something(f), inner_result.unmatch(), ctll::list<Tail...>());
322+
auto outer_result = evaluate(begin, inner_result.get_end_position(), end, consumed_something(f), inner_result.unmatch(), ctll::list<Tail...>());
324323

325-
if (outer_result) {
326-
return outer_result;
327-
}
324+
if (outer_result) {
325+
return outer_result;
326+
}
328327

329-
captures = inner_result.unmatch();
330-
current = inner_result.get_end_position();
328+
captures = inner_result.unmatch();
329+
current = inner_result.get_end_position();
331330

332-
++i;
333-
}
331+
++i;
332+
}
334333

335-
// rest of regex
336-
return evaluate(begin, current, end, consumed_something(f), captures, ctll::list<Tail...>());
334+
// rest of regex
335+
return evaluate(begin, current, end, consumed_something(f), captures, ctll::list<Tail...>());
336+
}
337337
}
338338

339339
// possessive repeat
@@ -342,24 +342,24 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
342342

343343
if constexpr ((B != 0) && (A > B)) {
344344
return not_matched;
345-
}
346-
347-
const auto backup_current = current;
345+
} else {
346+
const auto backup_current = current;
348347

349-
for (size_t i{0}; less_than_or_infinite<B>(i); ++i) {
350-
// try as many of inner as possible and then try outer once
351-
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
348+
for (size_t i{0}; less_than_or_infinite<B>(i); ++i) {
349+
// try as many of inner as possible and then try outer once
350+
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
352351

353-
if (!inner_result) {
354-
if (!less_than<A>(i)) break;
355-
return not_matched;
356-
}
352+
if (!inner_result) {
353+
if (!less_than<A>(i)) break;
354+
return not_matched;
355+
}
357356

358-
captures = inner_result.unmatch();
359-
current = inner_result.get_end_position();
360-
}
357+
captures = inner_result.unmatch();
358+
current = inner_result.get_end_position();
359+
}
361360

362-
return evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>());
361+
return evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>());
362+
}
363363
}
364364

365365
// (gready) repeat
@@ -411,31 +411,32 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
411411
}
412412

413413
#ifndef CTRE_DISABLE_GREEDY_OPT
414-
if constexpr (!collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
414+
else if constexpr (!collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
415415
return evaluate(begin, current, end, f, captures, ctll::list<possessive_repeat<A,B,Content...>, Tail...>());
416416
}
417417
#endif
418-
419-
// A..B
420-
size_t i{0};
421-
while (less_than<A>(i)) {
422-
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
418+
else {
419+
// A..B
420+
size_t i{0};
421+
while (less_than<A>(i)) {
422+
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
423423

424-
if (!inner_result) return not_matched;
424+
if (!inner_result) return not_matched;
425425

426-
captures = inner_result.unmatch();
427-
current = inner_result.get_end_position();
426+
captures = inner_result.unmatch();
427+
current = inner_result.get_end_position();
428428

429-
++i;
430-
}
429+
++i;
430+
}
431431

432432
#ifdef CTRE_MSVC_GREEDY_WORKAROUND
433-
R result;
434-
evaluate_recursive(result, i, begin, current, end, f, captures, stack);
435-
return result;
433+
R result;
434+
evaluate_recursive(result, i, begin, current, end, f, captures, stack);
435+
return result;
436436
#else
437-
return evaluate_recursive(i, begin, current, end, f, captures, stack);
437+
return evaluate_recursive(i, begin, current, end, f, captures, stack);
438438
#endif
439+
}
439440

440441
}
441442

include/ctre/return_type.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ template <size_t Id, typename Name = void> struct captured_content {
9494
#if __cpp_char8_t >= 201811
9595
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
9696
return static_cast<size_t>(std::distance(_begin.ptr, _end.ptr));
97+
} else {
98+
return static_cast<size_t>(std::distance(begin(), end()));
9799
}
98100
#endif
99101
return static_cast<size_t>(std::distance(begin(), end()));
@@ -121,6 +123,8 @@ template <size_t Id, typename Name = void> struct captured_content {
121123
#if __cpp_char8_t >= 201811
122124
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
123125
return std::basic_string<char_type>(data_unsafe(), static_cast<size_t>(unit_size()));
126+
} else {
127+
return std::basic_string<char_type>(begin(), end());
124128
}
125129
#endif
126130
return std::basic_string<char_type>(begin(), end());

include/unicode-db/unicode-db.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ struct flat_array {
293293
if(it == std::end(data))
294294
return false;
295295
}
296+
return false;
296297
} else {
297298
return detail::binary_search(std::begin(data), std::end(data), u);
298299
}
299-
return false;
300300
}
301301
};
302302

single-header/ctre-unicode.hpp

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,6 +3001,8 @@ template <size_t Id, typename Name = void> struct captured_content {
30013001
#if __cpp_char8_t >= 201811
30023002
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
30033003
return static_cast<size_t>(std::distance(_begin.ptr, _end.ptr));
3004+
} else {
3005+
return static_cast<size_t>(std::distance(begin(), end()));
30043006
}
30053007
#endif
30063008
return static_cast<size_t>(std::distance(begin(), end()));
@@ -3028,6 +3030,8 @@ template <size_t Id, typename Name = void> struct captured_content {
30283030
#if __cpp_char8_t >= 201811
30293031
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
30303032
return std::basic_string<char_type>(data_unsafe(), static_cast<size_t>(unit_size()));
3033+
} else {
3034+
return std::basic_string<char_type>(begin(), end());
30313035
}
30323036
#endif
30333037
return std::basic_string<char_type>(begin(), end());
@@ -4240,46 +4244,46 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
42404244

42414245
if constexpr (B != 0 && A > B) {
42424246
return not_matched;
4243-
}
4244-
4245-
const Iterator backup_current = current;
4247+
} else {
4248+
const Iterator backup_current = current;
42464249

4247-
size_t i{0};
4250+
size_t i{0};
42484251

4249-
while (less_than<A>(i)) {
4250-
auto outer_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
4252+
while (less_than<A>(i)) {
4253+
auto outer_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
42514254

4252-
if (!outer_result) return not_matched;
4255+
if (!outer_result) return not_matched;
42534256

4254-
captures = outer_result.unmatch();
4255-
current = outer_result.get_end_position();
4257+
captures = outer_result.unmatch();
4258+
current = outer_result.get_end_position();
42564259

4257-
++i;
4258-
}
4260+
++i;
4261+
}
42594262

4260-
if (auto outer_result = evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>())) {
4261-
return outer_result;
4262-
}
4263+
if (auto outer_result = evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>())) {
4264+
return outer_result;
4265+
}
42634266

4264-
while (less_than_or_infinite<B>(i)) {
4265-
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
4267+
while (less_than_or_infinite<B>(i)) {
4268+
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
42664269

4267-
if (!inner_result) return not_matched;
4270+
if (!inner_result) return not_matched;
42684271

4269-
auto outer_result = evaluate(begin, inner_result.get_end_position(), end, consumed_something(f), inner_result.unmatch(), ctll::list<Tail...>());
4272+
auto outer_result = evaluate(begin, inner_result.get_end_position(), end, consumed_something(f), inner_result.unmatch(), ctll::list<Tail...>());
42704273

4271-
if (outer_result) {
4272-
return outer_result;
4273-
}
4274+
if (outer_result) {
4275+
return outer_result;
4276+
}
42744277

4275-
captures = inner_result.unmatch();
4276-
current = inner_result.get_end_position();
4278+
captures = inner_result.unmatch();
4279+
current = inner_result.get_end_position();
42774280

4278-
++i;
4279-
}
4281+
++i;
4282+
}
42804283

4281-
// rest of regex
4282-
return evaluate(begin, current, end, consumed_something(f), captures, ctll::list<Tail...>());
4284+
// rest of regex
4285+
return evaluate(begin, current, end, consumed_something(f), captures, ctll::list<Tail...>());
4286+
}
42834287
}
42844288

42854289
// possessive repeat
@@ -4288,24 +4292,24 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
42884292

42894293
if constexpr ((B != 0) && (A > B)) {
42904294
return not_matched;
4291-
}
4292-
4293-
const auto backup_current = current;
4295+
} else {
4296+
const auto backup_current = current;
42944297

4295-
for (size_t i{0}; less_than_or_infinite<B>(i); ++i) {
4296-
// try as many of inner as possible and then try outer once
4297-
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
4298+
for (size_t i{0}; less_than_or_infinite<B>(i); ++i) {
4299+
// try as many of inner as possible and then try outer once
4300+
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
42984301

4299-
if (!inner_result) {
4300-
if (!less_than<A>(i)) break;
4301-
return not_matched;
4302-
}
4302+
if (!inner_result) {
4303+
if (!less_than<A>(i)) break;
4304+
return not_matched;
4305+
}
43034306

4304-
captures = inner_result.unmatch();
4305-
current = inner_result.get_end_position();
4306-
}
4307+
captures = inner_result.unmatch();
4308+
current = inner_result.get_end_position();
4309+
}
43074310

4308-
return evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>());
4311+
return evaluate(begin, current, end, consumed_something(f, backup_current != current), captures, ctll::list<Tail...>());
4312+
}
43094313
}
43104314

43114315
// (gready) repeat
@@ -4355,31 +4359,32 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
43554359
}
43564360

43574361
#ifndef CTRE_DISABLE_GREEDY_OPT
4358-
if constexpr (!collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
4362+
else if constexpr (!collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
43594363
return evaluate(begin, current, end, f, captures, ctll::list<possessive_repeat<A,B,Content...>, Tail...>());
43604364
}
43614365
#endif
4362-
4363-
// A..B
4364-
size_t i{0};
4365-
while (less_than<A>(i)) {
4366-
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
4366+
else {
4367+
// A..B
4368+
size_t i{0};
4369+
while (less_than<A>(i)) {
4370+
auto inner_result = evaluate(begin, current, end, not_empty_match(f), captures, ctll::list<Content..., end_cycle_mark>());
43674371

4368-
if (!inner_result) return not_matched;
4372+
if (!inner_result) return not_matched;
43694373

4370-
captures = inner_result.unmatch();
4371-
current = inner_result.get_end_position();
4374+
captures = inner_result.unmatch();
4375+
current = inner_result.get_end_position();
43724376

4373-
++i;
4374-
}
4377+
++i;
4378+
}
43754379

43764380
#ifdef CTRE_MSVC_GREEDY_WORKAROUND
4377-
R result;
4378-
evaluate_recursive(result, i, begin, current, end, f, captures, stack);
4379-
return result;
4381+
R result;
4382+
evaluate_recursive(result, i, begin, current, end, f, captures, stack);
4383+
return result;
43804384
#else
4381-
return evaluate_recursive(i, begin, current, end, f, captures, stack);
4385+
return evaluate_recursive(i, begin, current, end, f, captures, stack);
43824386
#endif
4387+
}
43834388

43844389
}
43854390

@@ -5597,10 +5602,10 @@ struct flat_array {
55975602
if(it == std::end(data))
55985603
return false;
55995604
}
5605+
return false;
56005606
} else {
56015607
return detail::binary_search(std::begin(data), std::end(data), u);
56025608
}
5603-
return false;
56045609
}
56055610
};
56065611

0 commit comments

Comments
 (0)