findchar.c 691 B

1234567891011121314151617181920212223242526272829
  1. // SPDX-License-Identifier: GPL-2.0 or GPL-3.0
  2. // Copyright © 2019 Ariadne Devos
  3. #include <sHT/index.h>
  4. #include <sHT/lex/findchar.h>
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. size_t
  8. sHT_findchar(size_t e, const uint8_t from[e], size_t b, const sHT_charclass s)
  9. {
  10. size_t i = b;
  11. if (sHT_ge(i, e))
  12. return i;
  13. /*@ loop invariant rINS: b <= i < e;
  14. loop invariant rIS: b <= e;
  15. loop invariant before_INS: \forall ℤ j; b <= j < i ==> !in_charclass(s, from[j]);
  16. loop assigns i;
  17. loop variant e - i; */
  18. do { i = sHT_index_nospec(i, e);
  19. if (sHT_charclass_test(s, from[i]))
  20. break;
  21. /*@ assert !in_charclass(s, from[i]); */
  22. i++;
  23. } while (sHT_lt(i, e));
  24. return i;
  25. }