Files
Odin/core/unicode/inrange.odin
StudebakerGuy 673adf30c3 Add searing of generated tables, Fixed in_digit
This adds the functino `unicode.in_range` to search for a run in
the `Range` type used in `core/unicode/generated.odin`.

This also modifies `unicode.binary_search` so it will support searching
types other than i32 by making it support implicit parametric polymorphism.

`unicode.in_digit` has been modified to use the generated tables.
2026-03-09 19:48:11 +01:00

40 lines
990 B
Odin

package unicode
/*
Check to see if the rune `r` is in `range`
*/
in_range :: proc(r: rune, range: Range) -> bool {
if r <= 0xFFFF {
r16 := cast(u16) r
length := len(range.ranges_16)
index := binary_search(r16, range.ranges_16, length/2, 2) if length > 0 else -1
if index >= 0 && range.ranges_16[index] <= r16 && range.ranges_16[index+1] >= r16 do return true
length = len(range.single_16)
index = binary_search(r16, range.single_16, length, 1) if length > 0 else -1
if index >= 0 && range.single_16[index] == r16 {
return true
}
}
r32 := cast(i32) r
length := len(range.ranges_32)
index := binary_search(r32, range.ranges_32, length/2, 2) if length >0 else -1
if index >= 0 && range.ranges_32[index] <= r32 && range.ranges_32[index+1] >= r32 do return true
length = len(range.single_32)
index = binary_search(r32, range.single_32, length, 1) if length > 0 else -1
if index >= 0 && range.single_32[index] == r32 do return true
return false
}