dyn-string.h 2.6 KB

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