blob: f6da41122bc62721c11127dbac6b9d916b843765 [file] [log] [blame]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001/* String object interface */
2
3/*
4123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
5
6Type stringobject represents a character string. An extra zero byte is
7reserved at the end to ensure it is zero-terminated, but a size is
8present so strings with null bytes in them can be represented. This
9is an immutable object type.
10
11There are functions to create new string objects, to test
12an object for string-ness, and to get the
13string value. The latter function returns a null pointer
14if the object is not of the proper type.
15There is a variant that takes an explicit size as well as a
16variant that assumes a zero-terminated string. Note that none of the
17functions should be applied to nil objects.
18*/
19
20/* NB The type is revealed here only because it is used in dictobject.c */
21
22typedef struct {
23 OB_VARHEAD
24 char ob_sval[1];
25} stringobject;
26
27extern typeobject Stringtype;
28
29#define is_stringobject(op) ((op)->ob_type == &Stringtype)
30
31extern object *newsizedstringobject PROTO((char *, int));
32extern object *newstringobject PROTO((char *));
33extern unsigned int getstringsize PROTO((object *));
34extern char *getstringvalue PROTO((object *));
35extern void joinstring PROTO((object **, object *));
36extern int resizestring PROTO((object **, int));
37
38/* Macro, trading safety for speed */
39#define GETSTRINGVALUE(op) ((op)->ob_sval)