xref: /netbsd-src/external/gpl3/gcc/dist/include/dyn-string.h (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14fee23f9Smrg /* An abstract string datatype.
2*b1e83836Smrg    Copyright (C) 1998-2022 Free Software Foundation, Inc.
34fee23f9Smrg    Contributed by Mark Mitchell (mark@markmitchell.com).
44fee23f9Smrg 
54fee23f9Smrg This file is part of GCC.
64fee23f9Smrg 
74fee23f9Smrg GCC is free software; you can redistribute it and/or modify
84fee23f9Smrg it under the terms of the GNU General Public License as published by
94fee23f9Smrg the Free Software Foundation; either version 2, or (at your option)
104fee23f9Smrg any later version.
114fee23f9Smrg 
124fee23f9Smrg GCC is distributed in the hope that it will be useful,
134fee23f9Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
144fee23f9Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154fee23f9Smrg GNU General Public License for more details.
164fee23f9Smrg 
174fee23f9Smrg You should have received a copy of the GNU General Public License
184fee23f9Smrg along with GCC; see the file COPYING.  If not, write to
194fee23f9Smrg the Free Software Foundation, 51 Franklin Street - Fifth Floor,
204fee23f9Smrg Boston, MA 02110-1301, USA.  */
214fee23f9Smrg 
224fee23f9Smrg #ifndef DYN_STRING_H
234fee23f9Smrg #define DYN_STRING_H
244fee23f9Smrg 
254fee23f9Smrg #ifdef __cplusplus
264fee23f9Smrg extern "C" {
274fee23f9Smrg #endif
284fee23f9Smrg 
294fee23f9Smrg typedef struct dyn_string
304fee23f9Smrg {
314fee23f9Smrg   int allocated;	/* The amount of space allocated for the string.  */
324fee23f9Smrg   int length;		/* The actual length of the string.  */
334fee23f9Smrg   char *s;		/* The string itself, NUL-terminated.  */
344fee23f9Smrg }* dyn_string_t;
354fee23f9Smrg 
364fee23f9Smrg /* The length STR, in bytes, not including the terminating NUL.  */
374fee23f9Smrg #define dyn_string_length(STR)                                          \
384fee23f9Smrg   ((STR)->length)
394fee23f9Smrg 
404fee23f9Smrg /* The NTBS in which the contents of STR are stored.  */
414fee23f9Smrg #define dyn_string_buf(STR)                                             \
424fee23f9Smrg   ((STR)->s)
434fee23f9Smrg 
444fee23f9Smrg /* Compare DS1 to DS2 with strcmp.  */
454fee23f9Smrg #define dyn_string_compare(DS1, DS2)                                    \
464fee23f9Smrg   (strcmp ((DS1)->s, (DS2)->s))
474fee23f9Smrg 
484fee23f9Smrg 
494fee23f9Smrg extern int dyn_string_init (struct dyn_string *, int);
504fee23f9Smrg extern dyn_string_t dyn_string_new (int);
514fee23f9Smrg extern void dyn_string_delete (dyn_string_t);
524fee23f9Smrg extern char *dyn_string_release (dyn_string_t);
534fee23f9Smrg extern dyn_string_t dyn_string_resize (dyn_string_t, int);
544fee23f9Smrg extern void dyn_string_clear (dyn_string_t);
554fee23f9Smrg extern int dyn_string_copy (dyn_string_t, dyn_string_t);
564fee23f9Smrg extern int dyn_string_copy_cstr (dyn_string_t, const char *);
574fee23f9Smrg extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
584fee23f9Smrg extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
594fee23f9Smrg extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
604fee23f9Smrg extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
614fee23f9Smrg extern int dyn_string_insert_char (dyn_string_t, int, int);
624fee23f9Smrg extern int dyn_string_append (dyn_string_t, dyn_string_t);
634fee23f9Smrg extern int dyn_string_append_cstr (dyn_string_t, const char *);
644fee23f9Smrg extern int dyn_string_append_char (dyn_string_t, int);
654fee23f9Smrg extern int dyn_string_substring (dyn_string_t,  dyn_string_t, int, int);
664fee23f9Smrg extern int dyn_string_eq (dyn_string_t, dyn_string_t);
674fee23f9Smrg 
684fee23f9Smrg #ifdef __cplusplus
694fee23f9Smrg }
704fee23f9Smrg #endif
714fee23f9Smrg 
724fee23f9Smrg #endif /* !defined (DYN_STRING_H) */
73