cstr.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _CSTR_H_
  2. #define _CSTR_H_
  3. /* A general-purpose string "class" for C */
  4. #if !defined(P)
  5. #ifdef __STDC__
  6. #define P(x) x
  7. #else
  8. #define P(x) ()
  9. #endif
  10. #endif
  11. /* For building dynamic link libraries under windows, windows NT
  12. * using MSVC1.5 or MSVC2.0
  13. */
  14. #ifndef _DLLDECL
  15. #define _DLLDECL
  16. #ifdef MSVC15 /* MSVC1.5 support for 16 bit apps */
  17. #define _MSVC15EXPORT _export
  18. #define _MSVC20EXPORT
  19. #define _DLLAPI _export _pascal
  20. #define _CDECL
  21. #define _TYPE(a) a _MSVC15EXPORT
  22. #define DLLEXPORT 1
  23. #elif defined(MSVC20) || (defined(_USRDLL) && defined(SRP_EXPORTS))
  24. #define _MSVC15EXPORT
  25. #define _MSVC20EXPORT _declspec(dllexport)
  26. #define _DLLAPI
  27. #define _CDECL
  28. #define _TYPE(a) _MSVC20EXPORT a
  29. #define DLLEXPORT 1
  30. #else /* Default, non-dll. Use this for Unix or DOS */
  31. #define _MSVC15DEXPORT
  32. #define _MSVC20EXPORT
  33. #define _DLLAPI
  34. #if defined(WINDOWS) || defined(_WIN32)
  35. #define _CDECL _cdecl
  36. #else
  37. #define _CDECL
  38. #endif
  39. #define _TYPE(a) a _CDECL
  40. #endif
  41. #endif /* _DLLDECL */
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif /* __cplusplus */
  45. typedef struct cstr_st {
  46. char * data; /* Okay to access data and length fields directly */
  47. int length;
  48. int cap;
  49. int ref; /* Simple reference counter */
  50. } cstr;
  51. _TYPE( cstr * ) cstr_new P((void));
  52. _TYPE( cstr * ) cstr_dup P((const cstr * str));
  53. _TYPE( cstr * ) cstr_create P((const char * s));
  54. _TYPE( cstr * ) cstr_createn P((const char * s, int len));
  55. _TYPE( void ) cstr_free P((cstr * str));
  56. _TYPE( void ) cstr_clear_free P((cstr * str));
  57. _TYPE( void ) cstr_use P((cstr * str));
  58. _TYPE( void ) cstr_empty P((cstr * str));
  59. _TYPE( int ) cstr_copy P((cstr * dst, const cstr * src));
  60. _TYPE( int ) cstr_set P((cstr * str, const char * s));
  61. _TYPE( int ) cstr_setn P((cstr * str, const char * s, int len));
  62. _TYPE( int ) cstr_set_length P((cstr * str, int len));
  63. _TYPE( int ) cstr_append P((cstr * str, const char * s));
  64. _TYPE( int ) cstr_appendn P((cstr * str, const char * s, int len));
  65. _TYPE( int ) cstr_append_str P((cstr * dst, const cstr * src));
  66. #ifdef __cplusplus
  67. }
  68. #endif /* __cplusplus */
  69. #endif /* _CSTR_H_ */