strings.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <assert.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5. int main() {
  6. assert(!bcmp("hello", "hehe", 2));
  7. assert(bcmp("hello", "haha", 2));
  8. char* new = malloc(3);
  9. bcopy("hi", new, 3); // include nul byte
  10. assert(!strcasecmp("hi", new));
  11. assert(strcasecmp("he", new));
  12. assert(strcasecmp("hello", "HEllO") == 0);
  13. assert(strcasecmp("hello", "HEllOo") < 0);
  14. assert(strcasecmp("5", "5") == 0);
  15. assert(strcasecmp("5", "4") > 0);
  16. assert(strcasecmp("5", "6") < 0);
  17. assert(strncasecmp("hello", "Hello World", 5) == 0);
  18. assert(strncasecmp("FLOOR0_1", "FLOOR0_1FLOOR4_1", 8) == 0);
  19. assert(strncasecmp("FL00RO_1", "FLOOR0_1FLOOR4_1", 8) < 0);
  20. // Ensure we aren't relying on the 5th (lowercase) bit on non-alpha characters
  21. assert(strcasecmp("{[", "[{") > 0);
  22. bzero(new, 1);
  23. assert(*new == 0);
  24. assert(*(new+1) == 'i');
  25. assert(*(new+2) == 0);
  26. assert(ffs(1) == 1);
  27. assert(ffs(2) == 2);
  28. assert(ffs(3) == 1);
  29. assert(ffs(10) == 2);
  30. char* str = "hihih";
  31. assert(index(str, 'i') == str + 1);
  32. assert(rindex(str, 'i') == str + 3);
  33. }