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