1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
/*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
| Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. |
+---------------------------------------------------------------------------+
| |
| This software is subject to the PDFlib license. It is NOT in the |
| public domain. Extended versions and commercial licenses are |
| available, please check http://www.pdflib.com. |
| |
*---------------------------------------------------------------------------*/
/* $Id: pc_string.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* The core string classes.
*
*/
#ifndef PC_STRING_H
#define PC_STRING_H
#include "pc_core.h"
/* there are two pdcore string classes. the structures "behind"
** these classes are opaque. conceptually, pdc_bstr objects are
** sequences of 'pdc_byte' (unsigned 8-bit entities), whereas
** pdc_ustr objects are sequences of 'pdc_ucval' ("unicode value";
** unsigned 32-bit entities).
*/
#ifndef PDC_STRINGS_DEFINED
#define PDC_STRINGS_DEFINED
typedef struct pdc_bstr_s pdc_bstr; /* byte strings */
typedef struct pdc_ustr_s pdc_ustr; /* unicode strings */
#endif
/* TODO: naming conventions for "per module" init/cleanup */
void pdc_init_strings(pdc_core *pdc);
void pdc_cleanup_strings(pdc_core *pdc);
/************************************************************************/
/* */
/* string object construction and deletion. */
/* */
/************************************************************************/
/* convert raw memory into an (empty) string object.
*/
void pdc_bs_boot(pdc_core *pdc, pdc_bstr *s);
void pdc_us_boot(pdc_core *pdc, pdc_ustr *s);
/* release all resources allocated by a string object (if any).
*/
void pdc_bs_shutdown(pdc_bstr *s);
void pdc_us_shutdown(pdc_ustr *s);
/* allocate a new (empty) pdc_bstr object.
*/
pdc_bstr *pdc_bs_new(pdc_core *pdc);
/* allocate a new pdc_ustr object and initialize its contents with the
** 'n' values from 'src'. if 'src' is null or 'n' is zero,
** an empty string object is constructed.
*/
pdc_ustr *pdc_us_new(pdc_core *pdc, const pdc_ucval *src, size_t n);
/* TODO: more constructors for various "source" types, eg.
**
pdc_ustr *pdc_us_new_utf16(pdc_core *pdc, const pdc_ushort *src, size_t n);
pdc_ustr *pdc_us_new_utf8(pdc_core *pdc, const pdc_byte *src, size_t n);
*/
/* return a copy of string 'src' ("copy constructor").
*/
pdc_bstr *pdc_bs_dup(const pdc_bstr *src);
pdc_ustr *pdc_us_dup(const pdc_ustr *src);
/* delete a string object explicitly ("destructor").
*/
void pdc_bs_delete(pdc_bstr *s);
void pdc_us_delete(pdc_ustr *s);
/************************************************************************/
/* */
/* "getters". */
/* */
/************************************************************************/
/* get the length of a string object in bytes or unicode values, resp.
*/
size_t pdc_bs_length(const pdc_bstr *s);
size_t pdc_us_length(const pdc_ustr *s);
/* string component access (range checked).
*/
pdc_byte pdc_bs_get(const pdc_bstr *s, int idx);
pdc_ucval pdc_us_get(const pdc_ustr *s, int idx);
/* TODO: try to get rid of that. */
const pdc_byte *pdc_bs_get_cptr(const pdc_bstr *s);
const pdc_byte *pdc_us_get_cptr(const pdc_ustr *s);
/************************************************************************/
/* */
/* "modifiers". */
/* */
/************************************************************************/
/* copy 'src' to 'dst' ("assignment operator").
*/
void pdc_bs_copy(pdc_bstr *dst, const pdc_bstr *src);
void pdc_us_copy(pdc_ustr *dst, const pdc_ustr *src);
/* copy part of 'src' to 'dst'.
*/
void pdc_bs_substr(pdc_bstr *dst, const pdc_bstr *src,
size_t pos, size_t len);
void pdc_us_substr(pdc_ustr *dst, const pdc_ustr *src,
size_t pos, size_t len);
/* insert 'src' into 'dst' at 'pos'.
*/
void pdc_bs_insert(pdc_bstr *dst, const pdc_bstr *src, size_t pos);
void pdc_us_insert(pdc_ustr *dst, const pdc_ustr *src, size_t pos);
/* append 'src' to 'dst'.
*/
void pdc_bs_concat(pdc_bstr *dst, const pdc_bstr *src);
void pdc_us_concat(pdc_ustr *dst, const pdc_ustr *src);
/* string component access (range checked).
*/
void pdc_bs_set(pdc_bstr *s, int idx, pdc_byte val);
void pdc_us_set(pdc_ustr *s, int idx, pdc_ucval val);
/* case conversion.
*/
void pdc_bs_tolower(pdc_bstr *s);
void pdc_bs_toupper(pdc_bstr *s);
/************************************************************************/
/* */
/* stream-like functions. */
/* */
/************************************************************************/
/* append 'n' values from 'src' to 'dst'. if 'n' is zero,
** or 'src' is null, 'dst' remains unchanged.
*/
void pdc_bs_write(pdc_bstr *dst, const pdc_byte *src, size_t n);
/* append the null terminated string 'src' to 'dst'.
*/
void pdc_bs_puts(pdc_bstr *dst, const pdc_byte *src);
/* append 'n' values from 'src' to 'dst'. if 'src' is null or 'n'
** is zero, 'dst' remains unchanged.
*/
void pdc_us_write(pdc_ustr *dst, const pdc_ucval *src, size_t n);
void pdc_us_write_utf16(pdc_ustr *dst, const pdc_ushort *src, size_t n);
/* TODO: more writer functions for various "source" types, eg.
**
void pdc_us_write_utf8(pdc_ustr *dst, const pdc_byte *src, size_t n);
*/
/* reset 's' to an empty stream object.
*/
void pdc_bs_rewrite(pdc_bstr *s);
void pdc_us_rewrite(pdc_ustr *s);
/* append a single byte (or unicode value, resp.) to a string object.
*/
void pdc_bs_putc(pdc_bstr *s, pdc_byte val);
void pdc_us_putc(pdc_ustr *s, pdc_ucval val);
/* TODO: stream-like read access. again, the read functions for pdc_ustr
** objects will be available in several flavors in order to support
** conversion to various "external" formats.
**
void pdc_bs_reset(pdc_bstr *s);
void pdc_us_reset(pdc_ustr *s);
void pdc_bs_seek(pdc_bstr *s, size_t pos);
void pdc_us_seek(pdc_ustr *s, size_t pos);
size_t pdc_bs_tell(const pdc_bstr *s);
size_t pdc_us_tell(const pdc_ustr *s);
size_t pdc_bs_read(pdc_bstr *src, pdc_byte *dst, size_t n);
size_t pdc_us_read(pdc_ustr *src, pdc_ucval *dst, size_t n);
size_t pdc_us_read_utf16(pdc_ustr *src, pdc_ushort *dst, size_t n);
size_t pdc_us_read_utf8(pdc_ustr *src, pdc_byte *dst, size_t n);
*/
/************************************************************************/
/* */
/* other utilities. */
/* */
/************************************************************************/
int pdc_bs_compare(const pdc_bstr *s1, const pdc_bstr *s2);
/************************************************************************/
/* */
/* PRIVATE SECTION */
/* */
/* the declarations below are strictly private to the implementation */
/* module, and must not be used by any client modules! */
/* */
/************************************************************************/
#define PDC_STR_INLINE_CAP 16
struct pdc_bstr_s
{
pdc_core * pdc;
pdc_byte buf0[PDC_STR_INLINE_CAP];
pdc_byte * buf;
size_t len;
size_t cap;
};
struct pdc_ustr_s
{
pdc_core * pdc;
pdc_ucval buf0[PDC_STR_INLINE_CAP];
pdc_ucval * buf;
size_t len;
size_t cap;
};
#if 0
/* string representation.
*/
typedef struct
{
pdc_byte * buf; /* contents */
size_t cap; /* capacity (unit: pdc_byte) */
size_t len; /* length (unit: pdc_byte) */
int ref; /* reference count */
} pdc_bs_rep;
typedef struct
{
pdc_ucval * buf; /* contents */
size_t cap; /* capacity (unit: pdc_ucval) */
size_t len; /* length (unit: pdc_ucval) */
int ref; /* reference count */
} pdc_us_rep;
struct pdc_bstr_s
{
pdc_core * pdc;
pdc_bs_rep *rep;
};
struct pdc_ustr_s
{
pdc_core * pdc;
pdc_us_rep *rep;
};
#endif
#endif /* PC_STRING_H */
|