mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-06 06:38:20 +00:00
[core:text/regex] Fix #6323 and add test case
Thanks to @GPotoshin for the fix.
This commit is contained in:
@@ -203,18 +203,22 @@ add_thread :: proc(vm: ^Machine, saved: ^[2 * common.MAX_CAPTURE_GROUPS]int, pc:
|
||||
}
|
||||
case .Assert_Word_Boundary:
|
||||
sp := vm.string_pointer+vm.current_rune_size
|
||||
if sp == 0 || sp == len(vm.memory) {
|
||||
|
||||
left_is_wc := false
|
||||
if sp > 0 {
|
||||
left_is_wc = is_word_class(vm.current_rune)
|
||||
}
|
||||
|
||||
right_is_wc := false
|
||||
if sp < len(vm.memory) {
|
||||
right_is_wc = is_word_class(vm.next_rune)
|
||||
}
|
||||
|
||||
if left_is_wc != right_is_wc {
|
||||
pc += size_of(Opcode)
|
||||
continue
|
||||
} else {
|
||||
last_rune_is_wc := is_word_class(vm.current_rune)
|
||||
this_rune_is_wc := is_word_class(vm.next_rune)
|
||||
|
||||
if last_rune_is_wc && !this_rune_is_wc || !last_rune_is_wc && this_rune_is_wc {
|
||||
pc += size_of(Opcode)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
case .Assert_Non_Word_Boundary:
|
||||
sp := vm.string_pointer+vm.current_rune_size
|
||||
if sp != 0 && sp != len(vm.memory) {
|
||||
|
||||
@@ -1270,6 +1270,16 @@ iterator_vectors := []Iterator_Test{
|
||||
{pos = {{0, 2}}, groups = {"a\n"}},
|
||||
},
|
||||
},
|
||||
// https://github.com/odin-lang/Odin/issues/6323
|
||||
// Test `\b` in iterator
|
||||
{
|
||||
"can, can't, 'can't'", `\b[a-z0-9']+\b`, {},
|
||||
{
|
||||
{pos = {{0, 3}}, groups = {"can"}},
|
||||
{pos = {{5, 10}}, groups = {"can't"}},
|
||||
{pos = {{13, 18}}, groups = {"can't"}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
|
||||
Reference in New Issue
Block a user