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