atl80: Added AtlComModuleRegisterServer implementation (based on AtlModuleRegisterSer...
[wine] / dlls / jscript / jsstr.h
1 /*
2  * Copyright 2012 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 struct _jsstr_t {
20     unsigned length_flags;
21     unsigned ref;
22     WCHAR str[1];
23 };
24
25 #define JSSTR_LENGTH_SHIFT 4
26 #define JSSTR_MAX_LENGTH (1 << (32-JSSTR_LENGTH_SHIFT))
27 #define JSSTR_FLAGS_MASK ((1 << JSSTR_LENGTH_SHIFT)-1)
28
29 #define JSSTR_FLAG_NULLBSTR 1
30
31 static inline unsigned jsstr_length(jsstr_t *str)
32 {
33     return str->length_flags >> JSSTR_LENGTH_SHIFT;
34 }
35
36 jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN;
37 jsstr_t *jsstr_alloc_buf(unsigned) DECLSPEC_HIDDEN;
38
39 static inline jsstr_t *jsstr_alloc(const WCHAR *str)
40 {
41     return jsstr_alloc_len(str, strlenW(str));
42 }
43
44 static inline void jsstr_release(jsstr_t *str)
45 {
46     if(!--str->ref)
47         heap_free(str);
48 }
49
50 static inline jsstr_t *jsstr_addref(jsstr_t *str)
51 {
52     str->ref++;
53     return str;
54 }
55
56 static inline BOOL jsstr_eq(jsstr_t *str1, jsstr_t *str2)
57 {
58     unsigned len = jsstr_length(str1);
59     return len == jsstr_length(str2) && !memcmp(str1->str, str2->str, len*sizeof(WCHAR));
60 }
61
62 int jsstr_cmp(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN;
63 jsstr_t *jsstr_concat(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN;
64
65 jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN;
66 jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN;
67
68 BOOL init_strings(void) DECLSPEC_HIDDEN;
69 void free_strings(void) DECLSPEC_HIDDEN;
70
71 const char *debugstr_jsstr(jsstr_t*) DECLSPEC_HIDDEN;