Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
693 B

  1. #include "scan.h"
  2. #include <ctype.h>
  3. /* Return the number of leading chars in s that are in charset, but no
  4. * more than limit */
  5. size_t scan_charsetnskip(const char *s,const char *charset,size_t limit) {
  6. register const char *t=s;
  7. register const char *u=t+limit;
  8. register const char* i;
  9. while (t<u) {
  10. for (i=charset; *i; ++i)
  11. if (*i==*t) break;
  12. if (*i!=*t) break;
  13. ++t;
  14. }
  15. return (size_t)(t-s);
  16. }
  17. #ifdef UNITTEST
  18. #include <assert.h>
  19. int main() {
  20. assert(scan_charsetnskip("fnord","fo",4)==1);
  21. assert(scan_charsetnskip("fnord","nf",4)==2);
  22. assert(scan_charsetnskip("gaord","nf",4)==0);
  23. assert(scan_charsetnskip("fnord","fnord",4)==4);
  24. return 0;
  25. }
  26. #endif