williamr@2
|
1 |
/* GLIB - Library of useful routines for C programming
|
williamr@2
|
2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
williamr@2
|
3 |
* Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This library is free software; you can redistribute it and/or
|
williamr@2
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
williamr@2
|
7 |
* License as published by the Free Software Foundation; either
|
williamr@2
|
8 |
* version 2 of the License, or (at your option) any later version.
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This library is distributed in the hope that it will be useful,
|
williamr@2
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
williamr@2
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
williamr@2
|
13 |
* Lesser General Public License for more details.
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
williamr@2
|
16 |
* License along with this library; if not, write to the
|
williamr@2
|
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
williamr@2
|
18 |
* Boston, MA 02111-1307, USA.
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
|
williamr@2
|
21 |
/*
|
williamr@2
|
22 |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
williamr@2
|
23 |
* file for a list of people on the GLib Team. See the ChangeLog
|
williamr@2
|
24 |
* files for a list of changes. These files are distributed with
|
williamr@2
|
25 |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
williamr@2
|
26 |
*/
|
williamr@2
|
27 |
|
williamr@2
|
28 |
#ifndef __G_STRING_H__
|
williamr@2
|
29 |
#define __G_STRING_H__
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#include <_ansi.h>
|
williamr@2
|
32 |
#include <glib/gtypes.h>
|
williamr@2
|
33 |
#include <glib/gunicode.h>
|
williamr@2
|
34 |
#include <glib/gutils.h> /* for G_CAN_INLINE */
|
williamr@2
|
35 |
|
williamr@2
|
36 |
G_BEGIN_DECLS
|
williamr@2
|
37 |
|
williamr@2
|
38 |
typedef struct _GString GString;
|
williamr@2
|
39 |
typedef struct _GStringChunk GStringChunk;
|
williamr@2
|
40 |
|
williamr@2
|
41 |
struct _GString
|
williamr@2
|
42 |
{
|
williamr@2
|
43 |
gchar *str;
|
williamr@2
|
44 |
gsize len;
|
williamr@2
|
45 |
gsize allocated_len;
|
williamr@2
|
46 |
};
|
williamr@2
|
47 |
|
williamr@2
|
48 |
/* String Chunks
|
williamr@2
|
49 |
*/
|
williamr@2
|
50 |
IMPORT_C GStringChunk* g_string_chunk_new (gsize size);
|
williamr@2
|
51 |
IMPORT_C void g_string_chunk_free (GStringChunk *chunk);
|
williamr@2
|
52 |
IMPORT_C gchar* g_string_chunk_insert (GStringChunk *chunk,
|
williamr@2
|
53 |
const gchar *string);
|
williamr@2
|
54 |
IMPORT_C gchar* g_string_chunk_insert_len (GStringChunk *chunk,
|
williamr@2
|
55 |
const gchar *string,
|
williamr@2
|
56 |
gssize len);
|
williamr@2
|
57 |
IMPORT_C gchar* g_string_chunk_insert_const (GStringChunk *chunk,
|
williamr@2
|
58 |
const gchar *string);
|
williamr@2
|
59 |
|
williamr@2
|
60 |
|
williamr@2
|
61 |
/* Strings
|
williamr@2
|
62 |
*/
|
williamr@2
|
63 |
IMPORT_C GString* g_string_new (const gchar *init);
|
williamr@2
|
64 |
IMPORT_C GString* g_string_new_len (const gchar *init,
|
williamr@2
|
65 |
gssize len);
|
williamr@2
|
66 |
IMPORT_C GString* g_string_sized_new (gsize dfl_size);
|
williamr@2
|
67 |
IMPORT_C gchar* g_string_free (GString *string,
|
williamr@2
|
68 |
gboolean free_segment);
|
williamr@2
|
69 |
IMPORT_C gboolean g_string_equal (const GString *v,
|
williamr@2
|
70 |
const GString *v2);
|
williamr@2
|
71 |
IMPORT_C guint g_string_hash (const GString *str);
|
williamr@2
|
72 |
IMPORT_C GString* g_string_assign (GString *string,
|
williamr@2
|
73 |
const gchar *rval);
|
williamr@2
|
74 |
IMPORT_C GString* g_string_truncate (GString *string,
|
williamr@2
|
75 |
gsize len);
|
williamr@2
|
76 |
IMPORT_C GString* g_string_set_size (GString *string,
|
williamr@2
|
77 |
gsize len);
|
williamr@2
|
78 |
IMPORT_C GString* g_string_insert_len (GString *string,
|
williamr@2
|
79 |
gssize pos,
|
williamr@2
|
80 |
const gchar *val,
|
williamr@2
|
81 |
gssize len);
|
williamr@2
|
82 |
IMPORT_C GString* g_string_append (GString *string,
|
williamr@2
|
83 |
const gchar *val);
|
williamr@2
|
84 |
IMPORT_C GString* g_string_append_len (GString *string,
|
williamr@2
|
85 |
const gchar *val,
|
williamr@2
|
86 |
gssize len);
|
williamr@2
|
87 |
IMPORT_C GString* g_string_append_c (GString *string,
|
williamr@2
|
88 |
gchar c);
|
williamr@2
|
89 |
IMPORT_C GString* g_string_append_unichar (GString *string,
|
williamr@2
|
90 |
gunichar wc);
|
williamr@2
|
91 |
IMPORT_C GString* g_string_prepend (GString *string,
|
williamr@2
|
92 |
const gchar *val);
|
williamr@2
|
93 |
IMPORT_C GString* g_string_prepend_c (GString *string,
|
williamr@2
|
94 |
gchar c);
|
williamr@2
|
95 |
IMPORT_C GString* g_string_prepend_unichar (GString *string,
|
williamr@2
|
96 |
gunichar wc);
|
williamr@2
|
97 |
IMPORT_C GString* g_string_prepend_len (GString *string,
|
williamr@2
|
98 |
const gchar *val,
|
williamr@2
|
99 |
gssize len);
|
williamr@2
|
100 |
IMPORT_C GString* g_string_insert (GString *string,
|
williamr@2
|
101 |
gssize pos,
|
williamr@2
|
102 |
const gchar *val);
|
williamr@2
|
103 |
IMPORT_C GString* g_string_insert_c (GString *string,
|
williamr@2
|
104 |
gssize pos,
|
williamr@2
|
105 |
gchar c);
|
williamr@2
|
106 |
IMPORT_C GString* g_string_insert_unichar (GString *string,
|
williamr@2
|
107 |
gssize pos,
|
williamr@2
|
108 |
gunichar wc);
|
williamr@2
|
109 |
IMPORT_C GString* g_string_erase (GString *string,
|
williamr@2
|
110 |
gssize pos,
|
williamr@2
|
111 |
gssize len);
|
williamr@2
|
112 |
IMPORT_C GString* g_string_ascii_down (GString *string);
|
williamr@2
|
113 |
IMPORT_C GString* g_string_ascii_up (GString *string);
|
williamr@2
|
114 |
IMPORT_C void g_string_printf (GString *string,
|
williamr@2
|
115 |
const gchar *format,
|
williamr@2
|
116 |
...) G_GNUC_PRINTF (2, 3);
|
williamr@2
|
117 |
IMPORT_C void g_string_append_printf (GString *string,
|
williamr@2
|
118 |
const gchar *format,
|
williamr@2
|
119 |
...) G_GNUC_PRINTF (2, 3);
|
williamr@2
|
120 |
|
williamr@2
|
121 |
/* -- optimize g_strig_append_c --- */
|
williamr@2
|
122 |
#ifdef G_CAN_INLINE
|
williamr@2
|
123 |
static inline GString*
|
williamr@2
|
124 |
g_string_append_c_inline (GString *gstring,
|
williamr@2
|
125 |
gchar c)
|
williamr@2
|
126 |
{
|
williamr@2
|
127 |
if (gstring->len + 1 < gstring->allocated_len)
|
williamr@2
|
128 |
{
|
williamr@2
|
129 |
gstring->str[gstring->len++] = c;
|
williamr@2
|
130 |
gstring->str[gstring->len] = 0;
|
williamr@2
|
131 |
}
|
williamr@2
|
132 |
else
|
williamr@2
|
133 |
g_string_insert_c (gstring, -1, c);
|
williamr@2
|
134 |
return gstring;
|
williamr@2
|
135 |
}
|
williamr@2
|
136 |
#define g_string_append_c(gstr,c) g_string_append_c_inline (gstr, c)
|
williamr@2
|
137 |
#endif /* G_CAN_INLINE */
|
williamr@2
|
138 |
|
williamr@2
|
139 |
|
williamr@2
|
140 |
#ifndef G_DISABLE_DEPRECATED
|
williamr@2
|
141 |
|
williamr@2
|
142 |
/* The following two functions are deprecated and will be removed in
|
williamr@2
|
143 |
* the next major release. They use the locale-specific tolower and
|
williamr@2
|
144 |
* toupper, which is almost never the right thing.
|
williamr@2
|
145 |
*/
|
williamr@2
|
146 |
|
williamr@2
|
147 |
IMPORT_C GString* g_string_down (GString *string);
|
williamr@2
|
148 |
IMPORT_C GString* g_string_up (GString *string);
|
williamr@2
|
149 |
|
williamr@2
|
150 |
/* These aliases are included for compatibility. */
|
williamr@2
|
151 |
#define g_string_sprintf g_string_printf
|
williamr@2
|
152 |
#define g_string_sprintfa g_string_append_printf
|
williamr@2
|
153 |
|
williamr@2
|
154 |
#endif /* G_DISABLE_DEPRECATED */
|
williamr@2
|
155 |
|
williamr@2
|
156 |
G_END_DECLS
|
williamr@2
|
157 |
|
williamr@2
|
158 |
#endif /* __G_STRING_H__ */
|
williamr@2
|
159 |
|