ascii_set.odin 557 B

123456789101112131415161718192021222324
  1. //+private
  2. package strings
  3. import "core:unicode/utf8"
  4. Ascii_Set :: distinct [8]u32
  5. // create an ascii set of all unique characters in the string
  6. ascii_set_make :: proc(chars: string) -> (as: Ascii_Set, ok: bool) #no_bounds_check {
  7. for i in 0..<len(chars) {
  8. c := chars[i]
  9. if c >= utf8.RUNE_SELF {
  10. return
  11. }
  12. as[c>>5] |= 1 << uint(c&31)
  13. }
  14. ok = true
  15. return
  16. }
  17. // returns true when the `c` byte is contained in the `as` ascii set
  18. ascii_set_contains :: proc(as: Ascii_Set, c: byte) -> bool #no_bounds_check {
  19. return as[c>>5] & (1<<(c&31)) != 0
  20. }