1 /*
2     $Id: strobj.h 2596 2021-04-18 18:52:11Z soci $
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 #ifndef STROBJ_H
20 #define STROBJ_H
21 #include "obj.h"
22 #include "stdbool.h"
23 
24 extern struct Type *const STR_OBJ;
25 
26 typedef struct Str {
27     Obj v;
28     size_t len;
29     size_t chars;
30     uint8_t *data;
31     union {
32         uint8_t val[16];
33         struct {
34             size_t max;
35             int hash;
36         } s;
37     } u;
38 } Str;
39 
40 #define Str(a) ((Str *)(1 ? (a) : (Obj *)(Str *)(a)))
41 
42 extern Obj *const null_str;
43 
44 extern void strobj_init(void);
45 extern void strobj_names(void);
46 extern void strobj_destroy(void);
47 
48 struct str_t;
49 
50 extern MALLOC Str *new_str(size_t);
51 extern MALLOC Str *new_str2(size_t);
52 extern MUST_CHECK Obj *str_from_str(const uint8_t *, linecpos_t *, linepos_t);
53 extern MUST_CHECK Obj *str_from_obj(Obj *, linepos_t);
54 extern MUST_CHECK Obj *float_from_str(const Str *, linepos_t);
55 extern size_t str_quoting(const uint8_t *, size_t, uint8_t *);
56 extern bool tostr(const struct values_s *, struct str_t *);
57 #endif
58