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.
 
 
 
 

59 lines
1.8 KiB

  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef STR_H
  3. #define STR_H
  4. #include <stddef.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #ifndef __pure__
  9. #define __pure__
  10. #endif
  11. /* str_copy copies leading bytes from in to out until \0.
  12. * return number of copied bytes. */
  13. size_t str_copy(char *out,const char *in);
  14. /* str_diff returns negative, 0, or positive, depending on whether the
  15. * string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
  16. * equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
  17. * If the strings are different, str_diff does not read bytes past the
  18. * first difference. */
  19. int str_diff(const char *a,const char *b) __pure__;
  20. /* str_diffn returns negative, 0, or positive, depending on whether the
  21. * string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
  22. * equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
  23. * If the strings are different, str_diffn does not read bytes past the
  24. * first difference. The strings will be considered equal if the first
  25. * limit characters match. */
  26. int str_diffn(const char *a,const char *b,size_t limit) __pure__;
  27. #ifdef __dietlibc__
  28. #include <string.h>
  29. #define str_len(foo) strlen(foo)
  30. #else
  31. /* str_len returns the index of \0 in s */
  32. size_t str_len(const char *s) __pure__;
  33. #endif
  34. /* str_chr returns the index of the first occurance of needle or \0 in haystack */
  35. size_t str_chr(const char *haystack,char needle) __pure__;
  36. /* str_rchr returns the index of the last occurance of needle or \0 in haystack */
  37. size_t str_rchr(const char *haystack,char needle) __pure__;
  38. /* str_start returns 1 if the b is a prefix of a, 0 otherwise */
  39. int str_start(const char *a,const char *b) __pure__;
  40. /* convenience shortcut to test for string equality */
  41. #define str_equal(s,t) (!str_diff((s),(t)))
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. #endif