Skip to content

Commit ae4ac6b

Browse files
committed
Temporary multiline-mode carriage return fix
This at least makes it match the behavior of std::regex.
1 parent c095ae7 commit ae4ac6b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

include/ctre/evaluation.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
9797

9898
if (multiline_mode(f)) {
9999
// TODO add support for different line ending and unicode (in a future unicode mode)
100-
if (*current == '\n') return not_matched;
100+
if (const auto c = *current; c == '\n' || c == '\r') return not_matched;
101101
}
102102
return evaluate(begin, ++current, last, consumed_something(f), captures, ctll::list<Tail...>());
103103
}
@@ -170,7 +170,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
170170
if (multiline_mode(f)) {
171171
if (last == current) {
172172
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
173-
} else if (*current == '\n' && std::next(current) == last) {
173+
} else if (const auto c = *current; (c == '\n' || c == '\r') && std::next(current) == last) {
174174
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
175175
} else {
176176
return not_matched;
@@ -188,7 +188,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
188188
if (multiline_mode(f)) {
189189
if (begin == current) {
190190
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
191-
} else if (*std::prev(current) == '\n') {
191+
} else if (const auto c = *std::prev(current); c == '\n' || c == '\r') {
192192
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
193193
} else {
194194
return not_matched;
@@ -206,7 +206,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
206206
if (multiline_mode(f)) {
207207
if (last == current) {
208208
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
209-
} else if (*current == '\n') {
209+
} else if (const auto c = *current; c == '\n' || c == '\r') {
210210
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
211211
} else {
212212
return not_matched;

single-header/ctre-unicode.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4407,7 +4407,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
44074407

44084408
if (multiline_mode(f)) {
44094409
// TODO add support for different line ending and unicode (in a future unicode mode)
4410-
if (*current == '\n') return not_matched;
4410+
if (const auto c = *current; c == '\n' || c == '\r') return not_matched;
44114411
}
44124412
return evaluate(begin, ++current, last, consumed_something(f), captures, ctll::list<Tail...>());
44134413
}
@@ -4480,7 +4480,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
44804480
if (multiline_mode(f)) {
44814481
if (last == current) {
44824482
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
4483-
} else if (*current == '\n' && std::next(current) == last) {
4483+
} else if (const auto c = *current; (c == '\n' || c == '\r') && std::next(current) == last) {
44844484
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
44854485
} else {
44864486
return not_matched;
@@ -4498,7 +4498,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
44984498
if (multiline_mode(f)) {
44994499
if (begin == current) {
45004500
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
4501-
} else if (*std::prev(current) == '\n') {
4501+
} else if (const auto c = *std::prev(current); c == '\n' || c == '\r') {
45024502
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
45034503
} else {
45044504
return not_matched;
@@ -4516,7 +4516,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
45164516
if (multiline_mode(f)) {
45174517
if (last == current) {
45184518
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
4519-
} else if (*current == '\n') {
4519+
} else if (const auto c = *current; c == '\n' || c == '\r') {
45204520
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
45214521
} else {
45224522
return not_matched;

single-header/ctre.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4404,7 +4404,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
44044404

44054405
if (multiline_mode(f)) {
44064406
// TODO add support for different line ending and unicode (in a future unicode mode)
4407-
if (*current == '\n') return not_matched;
4407+
if (const auto c = *current; c == '\n' || c == '\r') return not_matched;
44084408
}
44094409
return evaluate(begin, ++current, last, consumed_something(f), captures, ctll::list<Tail...>());
44104410
}
@@ -4477,7 +4477,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
44774477
if (multiline_mode(f)) {
44784478
if (last == current) {
44794479
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
4480-
} else if (*current == '\n' && std::next(current) == last) {
4480+
} else if (const auto c = *current; (c == '\n' || c == '\r') && std::next(current) == last) {
44814481
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
44824482
} else {
44834483
return not_matched;
@@ -4495,7 +4495,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
44954495
if (multiline_mode(f)) {
44964496
if (begin == current) {
44974497
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
4498-
} else if (*std::prev(current) == '\n') {
4498+
} else if (const auto c = *std::prev(current); c == '\n' || c == '\r') {
44994499
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
45004500
} else {
45014501
return not_matched;
@@ -4513,7 +4513,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre
45134513
if (multiline_mode(f)) {
45144514
if (last == current) {
45154515
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
4516-
} else if (*current == '\n') {
4516+
} else if (const auto c = *current; c == '\n' || c == '\r') {
45174517
return evaluate(begin, current, last, f, captures, ctll::list<Tail...>());
45184518
} else {
45194519
return not_matched;

0 commit comments

Comments
 (0)