dyn-string.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* An abstract string datatype.
  2. Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2009
  3. Free Software Foundation, Inc.
  4. Contributed by Mark Mitchell (mark@markmitchell.com).
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. GCC is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING. If not, write to
  16. the Free Software Foundation, 51 Franklin Street - Fifth Floor,
  17. Boston, MA 02110-1301, USA. */
  18. #ifndef DYN_STRING_H
  19. #define DYN_STRING_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef struct dyn_string
  24. {
  25. int allocated; /* The amount of space allocated for the string. */
  26. int length; /* The actual length of the string. */
  27. char *s; /* The string itself, NUL-terminated. */
  28. }* dyn_string_t;
  29. /* The length STR, in bytes, not including the terminating NUL. */
  30. #define dyn_string_length(STR) \
  31. ((STR)->length)
  32. /* The NTBS in which the contents of STR are stored. */
  33. #define dyn_string_buf(STR) \
  34. ((STR)->s)
  35. /* Compare DS1 to DS2 with strcmp. */
  36. #define dyn_string_compare(DS1, DS2) \
  37. (strcmp ((DS1)->s, (DS2)->s))
  38. extern int dyn_string_init (struct dyn_string *, int);
  39. extern dyn_string_t dyn_string_new (int);
  40. extern void dyn_string_delete (dyn_string_t);
  41. extern char *dyn_string_release (dyn_string_t);
  42. extern dyn_string_t dyn_string_resize (dyn_string_t, int);
  43. extern void dyn_string_clear (dyn_string_t);
  44. extern int dyn_string_copy (dyn_string_t, dyn_string_t);
  45. extern int dyn_string_copy_cstr (dyn_string_t, const char *);
  46. extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
  47. extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
  48. extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
  49. extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
  50. extern int dyn_string_insert_char (dyn_string_t, int, int);
  51. extern int dyn_string_append (dyn_string_t, dyn_string_t);
  52. extern int dyn_string_append_cstr (dyn_string_t, const char *);
  53. extern int dyn_string_append_char (dyn_string_t, int);
  54. extern int dyn_string_substring (dyn_string_t, dyn_string_t, int, int);
  55. extern int dyn_string_eq (dyn_string_t, dyn_string_t);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* !defined (DYN_STRING_H) */