evaluator roundup
[mala.git] / engine / strings.h
blob3662e99210d56942a719da6734c12aee406d77ff
1 /*
2 strings.h - MaLa string handling
4 Copyright (C) 2004, 2005, 2006, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #ifndef MALA_STRINGS_H
21 #define MALA_STRINGS_H
23 #include <string.h>
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include "mala_types.h"
27 #include "acogc.h"
28 #include "stringbucket.h"
29 #include "llist.h"
32 struct mala_string_struct
34 const char * str;
35 size_t len;
36 union
38 MalaAction action;
39 void * user;
40 int integer;
41 MalaString string;
43 short str_alloc_type:4;
44 short user_alloc_type:4;
47 /* gc support */
48 acogc_mark_result
49 mala_string_acogc_mark (void*);
51 void
52 mala_string_acogc_initize (void*);
54 void
55 mala_string_acogc_finalize (void*);
57 /* constructors */
58 MalaString
59 mala_string_new_cstr (const char* cstr, MalaStringBucket bucket);
61 MalaString
62 mala_string_new_literal_cstr (const char* cstr, MalaStringBucket bucket);
64 MalaString
65 mala_string_new_attach_cstr (const char* cstr, MalaStringBucket bucket);
67 MalaString
68 mala_string_new_cstr_n (const char* cstr, const size_t n, MalaStringBucket bucket);
70 MalaString
71 mala_string_new_2cstr (const char* cstr1, const char* cstr2, MalaStringBucket bucket);
73 MalaString
74 mala_string_new_print (MalaStringBucket bucket, const char* fmt,...);
76 MalaString
77 mala_string_new_n (MalaString src, const size_t n, MalaStringBucket bucket);
79 MalaString
80 mala_string_new_prefix (const char* prefix, MalaString str, MalaStringBucket bucket);
82 int
83 mala_string_scan (const_MalaString str,const char* fmt,...);
86 static inline const char*
87 mala_string_cstr (const_MalaString s);
89 static inline size_t
90 mala_string_length (const_MalaString s);
92 static inline int
93 mala_string_compare (const_MalaString a, const_MalaString b);
95 static inline int
96 mala_string_compare_nocase (const_MalaString a, const_MalaString b);
100 static inline const char*
101 mala_string_cstr (const_MalaString s)
103 return s ? s->str : NULL;
107 static inline size_t
108 mala_string_length (const_MalaString s)
110 return s->len;
114 static inline int
115 mala_string_compare (const_MalaString a, const_MalaString b)
117 return a == b ? 0 : strcmp (mala_string_cstr (a), mala_string_cstr (b));
121 static inline int
122 mala_string_compare_nocase (const_MalaString a, const_MalaString b)
124 return a == b ? 0 : strcasecmp (mala_string_cstr (a), mala_string_cstr (b));
128 #endif /* MALA_STRINGS */
131 // Local Variables:
132 // mode: C
133 // c-file-style: "gnu"
134 // End:
135 // arch-tag: b43b7350-ecb6-4aa8-94d3-930da822e3ea
136 // end_of_file