xref: /netbsd-src/external/gpl3/gdb/dist/include/dyn-string.h (revision e663ba6e3a60083e70de702e9d54bf486a57b6a7)
198b9484cSchristos /* An abstract string datatype.
2*e663ba6eSchristos    Copyright (C) 1998-2024 Free Software Foundation, Inc.
398b9484cSchristos    Contributed by Mark Mitchell (mark@markmitchell.com).
498b9484cSchristos 
598b9484cSchristos This file is part of GCC.
698b9484cSchristos 
798b9484cSchristos GCC is free software; you can redistribute it and/or modify
898b9484cSchristos it under the terms of the GNU General Public License as published by
998b9484cSchristos the Free Software Foundation; either version 2, or (at your option)
1098b9484cSchristos any later version.
1198b9484cSchristos 
1298b9484cSchristos GCC is distributed in the hope that it will be useful,
1398b9484cSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1498b9484cSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1598b9484cSchristos GNU General Public License for more details.
1698b9484cSchristos 
1798b9484cSchristos You should have received a copy of the GNU General Public License
1898b9484cSchristos along with GCC; see the file COPYING.  If not, write to
1998b9484cSchristos the Free Software Foundation, 51 Franklin Street - Fifth Floor,
2098b9484cSchristos Boston, MA 02110-1301, USA.  */
2198b9484cSchristos 
2298b9484cSchristos #ifndef DYN_STRING_H
2398b9484cSchristos #define DYN_STRING_H
2498b9484cSchristos 
2598b9484cSchristos #ifdef __cplusplus
2698b9484cSchristos extern "C" {
2798b9484cSchristos #endif
2898b9484cSchristos 
2998b9484cSchristos typedef struct dyn_string
3098b9484cSchristos {
3198b9484cSchristos   int allocated;	/* The amount of space allocated for the string.  */
3298b9484cSchristos   int length;		/* The actual length of the string.  */
3398b9484cSchristos   char *s;		/* The string itself, NUL-terminated.  */
3498b9484cSchristos }* dyn_string_t;
3598b9484cSchristos 
3698b9484cSchristos /* The length STR, in bytes, not including the terminating NUL.  */
3798b9484cSchristos #define dyn_string_length(STR)                                          \
3898b9484cSchristos   ((STR)->length)
3998b9484cSchristos 
4098b9484cSchristos /* The NTBS in which the contents of STR are stored.  */
4198b9484cSchristos #define dyn_string_buf(STR)                                             \
4298b9484cSchristos   ((STR)->s)
4398b9484cSchristos 
4498b9484cSchristos /* Compare DS1 to DS2 with strcmp.  */
4598b9484cSchristos #define dyn_string_compare(DS1, DS2)                                    \
4698b9484cSchristos   (strcmp ((DS1)->s, (DS2)->s))
4798b9484cSchristos 
4898b9484cSchristos 
4998b9484cSchristos extern int dyn_string_init (struct dyn_string *, int);
5098b9484cSchristos extern dyn_string_t dyn_string_new (int);
5198b9484cSchristos extern void dyn_string_delete (dyn_string_t);
5298b9484cSchristos extern char *dyn_string_release (dyn_string_t);
5398b9484cSchristos extern dyn_string_t dyn_string_resize (dyn_string_t, int);
5498b9484cSchristos extern void dyn_string_clear (dyn_string_t);
5598b9484cSchristos extern int dyn_string_copy (dyn_string_t, dyn_string_t);
5698b9484cSchristos extern int dyn_string_copy_cstr (dyn_string_t, const char *);
5798b9484cSchristos extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
5898b9484cSchristos extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
5998b9484cSchristos extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
6098b9484cSchristos extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
6198b9484cSchristos extern int dyn_string_insert_char (dyn_string_t, int, int);
6298b9484cSchristos extern int dyn_string_append (dyn_string_t, dyn_string_t);
6398b9484cSchristos extern int dyn_string_append_cstr (dyn_string_t, const char *);
6498b9484cSchristos extern int dyn_string_append_char (dyn_string_t, int);
6598b9484cSchristos extern int dyn_string_substring (dyn_string_t,  dyn_string_t, int, int);
6698b9484cSchristos extern int dyn_string_eq (dyn_string_t, dyn_string_t);
6798b9484cSchristos 
6898b9484cSchristos #ifdef __cplusplus
6998b9484cSchristos }
7098b9484cSchristos #endif
7198b9484cSchristos 
7298b9484cSchristos #endif /* !defined (DYN_STRING_H) */
73