stringutils.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef STRINGUTILS_H_GUARD_
  2. #define STRINGUTILS_H_GUARD_
  3. /* * About * *
  4. * c+h library for wrapping strings.
  5. * Suited for:
  6. * function arguments, no additional var for buffer or length;
  7. * replacing sprintf() and strcat();
  8. * read-once-use-often, no need for strlen();
  9. *
  10. * Heap allocated, call for SU_free() when you have finished with it.
  11. * Beware, there is no reallocation inside SU_set() and SU_cat(),
  12. * take care of fitting your string yourself, otherwise it will be cut off.
  13. * */
  14. /* Macros */
  15. #include <stddef.h>
  16. #define STRINGUTILS_IMPLEMENTATION
  17. #define SU_MAX_PATH_LENGTH 4096
  18. /* Typedef */
  19. typedef struct string
  20. {
  21. char * s;
  22. size_t length;
  23. size_t bytes;
  24. } string;
  25. /* Protos */
  26. string * SU_new ( size_t size );
  27. string * SU_copy ( string * src );
  28. void SU_construct ( string * dst, size_t src );
  29. void SU_set ( string * dst, const char * fmt, ... );
  30. void SU_cat ( string * dst, const char * fmt, ... );
  31. void SU_free ( string * str );
  32. void SU_fit_with_trunk ( string * dst, string * src, const char * cutoff );
  33. string * SU_simple ( char * input );
  34. #endif