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