ReactOS  0.4.13-dev-100-gc8611ae
jsstr.h
Go to the documentation of this file.
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 /*
20  * jsstr_t is a common header for all string representations. The exact layout of the string
21  * representation may be:
22  *
23  * - inline string - string bytes directly follow string headers.
24  * - heap string - a structure containing a pointer to buffer on the heap.
25  * - roper string - a product of concatenation of two strings. Instead of copying whole
26  * buffers, we may store just references to concatenated strings.
27  *
28  * String layout may change over life time of the string. Currently possible transformation
29  * is when a rope string becomes a heap stream. That happens when we need a real, linear
30  * zero-terminated buffer (a flat buffer). At this point the type of the string is changed
31  * and the new buffer is stored in the string, so that subsequent operations requiring
32  * a flat string won't need to flatten it again.
33  *
34  * In the future more layouts and transformations may be added.
35  */
36 
37 #pragma once
38 
39 struct _jsstr_t {
40  unsigned length_flags;
41  unsigned ref;
42 };
43 
44 #define JSSTR_LENGTH_SHIFT 4
45 #define JSSTR_MAX_LENGTH ((1 << (32-JSSTR_LENGTH_SHIFT))-1)
46 #define JSSTR_FLAGS_MASK ((1 << JSSTR_LENGTH_SHIFT)-1)
47 
48 #define JSSTR_FLAG_LBIT 1
49 #define JSSTR_FLAG_FLAT 2
50 #define JSSTR_FLAG_TAG_MASK 3
51 
52 typedef enum {
56 } jsstr_tag_t;
57 
58 static inline unsigned jsstr_length(jsstr_t *str)
59 {
60  return str->length_flags >> JSSTR_LENGTH_SHIFT;
61 }
62 
64 {
65  return str->length_flags & JSSTR_FLAG_TAG_MASK;
66 }
67 
69 {
70  return jsstr_tag(str) == JSSTR_INLINE;
71 }
72 
73 static inline BOOL jsstr_is_heap(jsstr_t *str)
74 {
75  return jsstr_tag(str) == JSSTR_HEAP;
76 }
77 
78 static inline BOOL jsstr_is_rope(jsstr_t *str)
79 {
80  return jsstr_tag(str) == JSSTR_ROPE;
81 }
82 
83 typedef struct {
85  WCHAR buf[1];
87 
88 typedef struct {
91 } jsstr_heap_t;
92 
93 typedef struct {
97  unsigned depth;
98 } jsstr_rope_t;
99 
100 jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN;
102 
103 static inline jsstr_t *jsstr_alloc(const WCHAR *str)
104 {
105  return jsstr_alloc_len(str, strlenW(str));
106 }
107 
109 
110 static inline void jsstr_release(jsstr_t *str)
111 {
112  if(!--str->ref)
113  jsstr_free(str);
114 }
115 
116 static inline jsstr_t *jsstr_addref(jsstr_t *str)
117 {
118  str->ref++;
119  return str;
120 }
121 
123 {
125 }
126 
128 {
130 }
131 
133 {
135 }
136 
138 
139 static inline const WCHAR *jsstr_flatten(jsstr_t *str)
140 {
144 }
145 
146 void jsstr_extract(jsstr_t*,unsigned,unsigned,WCHAR*) DECLSPEC_HIDDEN;
147 
148 static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
149 {
150  unsigned len = jsstr_length(str);
151  if(jsstr_is_inline(str)) {
152  memcpy(buf, jsstr_as_inline(str)->buf, len*sizeof(WCHAR));
153  }else if(jsstr_is_heap(str)) {
154  memcpy(buf, jsstr_as_heap(str)->buf, len*sizeof(WCHAR));
155  }else {
157  jsstr_flush(rope->left, buf);
158  jsstr_flush(rope->right, buf+jsstr_length(rope->left));
159  }
160  return len;
161 }
162 
163 static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
164 {
165  jsstr_t *ret;
166  WCHAR *ptr;
167 
168  ret = jsstr_alloc_buf(len, &ptr);
169  if(ret)
171  return ret;
172 }
173 
175 
177 {
179 }
180 
182 
186 
189 
191 void free_strings(void) DECLSPEC_HIDDEN;
192 
Definition: _rope.h:91
jsstr_t * jsstr_undefined(void) DECLSPEC_HIDDEN
Definition: jsstr.c:293
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
static const WCHAR * jsstr_flatten(jsstr_t *str)
Definition: jsstr.h:139
jsstr_tag_t
Definition: jsstr.h:52
jsstr_t * jsstr_nan(void) DECLSPEC_HIDDEN
Definition: jsstr.c:283
static jsstr_t * jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
Definition: jsstr.h:163
jsstr_t * jsstr_empty(void) DECLSPEC_HIDDEN
Definition: jsstr.c:288
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
Definition: jsstr.h:39
jsstr_t * jsstr_concat(jsstr_t *, jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:211
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static jsstr_t * jsstr_addref(jsstr_t *str)
Definition: jsstr.h:116
jsstr_t * jsstr_alloc_buf(unsigned, WCHAR **) DECLSPEC_HIDDEN
Definition: jsstr.c:69
void jsstr_free(jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:44
static jsstr_rope_t * jsstr_as_rope(jsstr_t *str)
Definition: jsstr.h:132
jsstr_t * jsstr_alloc_len(const WCHAR *, unsigned) DECLSPEC_HIDDEN
Definition: jsstr.c:86
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:148
const WCHAR * jsstr_rope_flatten(jsstr_rope_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:262
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110
BOOL is_null_bstr(jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:303
WCHAR * buf
Definition: jsstr.h:90
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
jsstr_t * left
Definition: jsstr.h:95
const WCHAR * str
void jsstr_extract(jsstr_t *, unsigned, unsigned, WCHAR *) DECLSPEC_HIDDEN
Definition: jsstr.c:113
unsigned length_flags
Definition: jsstr.h:40
jsstr_t str
Definition: jsstr.h:94
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
WCHAR buf[1]
Definition: jsstr.h:85
__wchar_t WCHAR
Definition: xmlstorage.h:180
jsstr_t * jsstr_null_bstr(void) DECLSPEC_HIDDEN
Definition: jsstr.c:298
jsstr_t * right
Definition: jsstr.h:96
GLint left
Definition: glext.h:7726
unsigned depth
Definition: jsstr.h:97
GLdouble GLdouble right
Definition: glext.h:10859
int ret
jsstr_t str
Definition: jsstr.h:89
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
unsigned ref
Definition: jsstr.h:41
static jsstr_tag_t jsstr_tag(jsstr_t *str)
Definition: jsstr.h:63
#define JSSTR_FLAG_FLAT
Definition: jsstr.h:49
static BOOL jsstr_is_heap(jsstr_t *str)
Definition: jsstr.h:73
static BOOL jsstr_is_rope(jsstr_t *str)
Definition: jsstr.h:78
#define JSSTR_FLAG_TAG_MASK
Definition: jsstr.h:50
BOOL init_strings(void) DECLSPEC_HIDDEN
Definition: jsstr.c:308
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
static BOOL jsstr_is_inline(jsstr_t *str)
Definition: jsstr.h:68
void free_strings(void) DECLSPEC_HIDDEN
Definition: jsstr.c:325
int jsstr_cmp(jsstr_t *, jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:189
static jsstr_heap_t * jsstr_as_heap(jsstr_t *str)
Definition: jsstr.h:127
const char * debugstr_jsstr(jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:37
static BOOL jsstr_eq(jsstr_t *left, jsstr_t *right)
Definition: jsstr.h:176
static jsstr_inline_t * jsstr_as_inline(jsstr_t *str)
Definition: jsstr.h:122
jsstr_t str
Definition: jsstr.h:84
#define JSSTR_FLAG_LBIT
Definition: jsstr.h:48
#define JSSTR_LENGTH_SHIFT
Definition: jsstr.h:44
off
Definition: i386-dis.c:3909