Skip to content

Commit 93b3ad8

Browse files
remove nested if else breaks for readability
1 parent 0772ac8 commit 93b3ad8

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

crates/djls-templates/src/lexer.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,20 @@ impl Lexer {
128128
while !self.is_at_end() {
129129
let remaining = self.remaining_source();
130130

131-
if let Some(pos) = memchr3(b'{', b'\n', b'\r', remaining.as_bytes()) {
132-
let found_char = remaining.as_bytes()[pos];
133-
134-
if found_char == b'{' {
135-
let substr = &remaining[pos..];
136-
if TagDelimiter::from_input(substr).is_some() {
137-
self.current += pos;
138-
break;
139-
}
140-
self.current += pos + 1;
141-
} else {
142-
self.current += pos;
143-
break;
144-
}
145-
} else {
131+
let Some(pos) = memchr3(b'{', b'\n', b'\r', remaining.as_bytes()) else {
146132
self.current = self.source.len();
147133
break;
134+
};
135+
136+
let is_newline = matches!(remaining.as_bytes()[pos], b'\n' | b'\r');
137+
let is_django_delimiter = TagDelimiter::from_input(&remaining[pos..]).is_some();
138+
139+
if is_newline || is_django_delimiter {
140+
self.current += pos;
141+
break;
148142
}
143+
144+
self.current += pos + 1;
149145
}
150146

151147
let text = self.consumed_source_from(text_start);

0 commit comments

Comments
 (0)