alstring.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef ALSTRING_H
  2. #define ALSTRING_H
  3. #include <string.h>
  4. #include "vector.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef char al_string_char_type;
  9. TYPEDEF_VECTOR(al_string_char_type, al_string)
  10. TYPEDEF_VECTOR(al_string, vector_al_string)
  11. inline void alstr_reset(al_string *str)
  12. { VECTOR_DEINIT(*str); }
  13. #define AL_STRING_INIT(_x) do { (_x) = (al_string)NULL; } while(0)
  14. #define AL_STRING_INIT_STATIC() ((al_string)NULL)
  15. #define AL_STRING_DEINIT(_x) alstr_reset(&(_x))
  16. inline size_t alstr_length(const_al_string str)
  17. { return VECTOR_SIZE(str); }
  18. inline ALboolean alstr_empty(const_al_string str)
  19. { return alstr_length(str) == 0; }
  20. inline const al_string_char_type *alstr_get_cstr(const_al_string str)
  21. { return str ? &VECTOR_FRONT(str) : ""; }
  22. void alstr_clear(al_string *str);
  23. int alstr_cmp(const_al_string str1, const_al_string str2);
  24. int alstr_cmp_cstr(const_al_string str1, const al_string_char_type *str2);
  25. void alstr_copy(al_string *str, const_al_string from);
  26. void alstr_copy_cstr(al_string *str, const al_string_char_type *from);
  27. void alstr_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to);
  28. void alstr_append_char(al_string *str, const al_string_char_type c);
  29. void alstr_append_cstr(al_string *str, const al_string_char_type *from);
  30. void alstr_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to);
  31. #ifdef _WIN32
  32. #include <wchar.h>
  33. /* Windows-only methods to deal with WideChar strings. */
  34. void alstr_copy_wcstr(al_string *str, const wchar_t *from);
  35. void alstr_append_wcstr(al_string *str, const wchar_t *from);
  36. void alstr_copy_wrange(al_string *str, const wchar_t *from, const wchar_t *to);
  37. void alstr_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to);
  38. #endif
  39. #ifdef __cplusplus
  40. } /* extern "C" */
  41. #endif
  42. #endif /* ALSTRING_H */