2 * Copyright 2012 Jacek Caban for CodeWeavers
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.
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.
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
21 #include "wine/debug.h"
23 const char *debugstr_jsstr(jsstr_t
*str
)
25 return debugstr_wn(str
->str
, jsstr_length(str
));
28 jsstr_t
*jsstr_alloc_buf(unsigned len
)
32 if(len
> JSSTR_MAX_LENGTH
)
35 ret
= heap_alloc(FIELD_OFFSET(jsstr_t
, str
[len
+1]));
39 ret
->length_flags
= len
<< JSSTR_LENGTH_SHIFT
;
45 jsstr_t
*jsstr_alloc_len(const WCHAR
*buf
, unsigned len
)
49 ret
= jsstr_alloc_buf(len
);
51 memcpy(ret
->str
, buf
, len
*sizeof(WCHAR
));
56 int jsstr_cmp(jsstr_t
*str1
, jsstr_t
*str2
)
58 int len1
= jsstr_length(str1
);
59 int len2
= jsstr_length(str2
);
62 ret
= memcmp(str1
->str
, str2
->str
, min(len1
, len2
)*sizeof(WCHAR
));
69 static jsstr_t
*empty_str
, *nan_str
;
71 jsstr_t
*jsstr_nan(void)
73 return jsstr_addref(nan_str
);
76 jsstr_t
*jsstr_empty(void)
78 return jsstr_addref(empty_str
);
81 BOOL
init_strings(void)
83 static const WCHAR NaNW
[] = { 'N','a','N',0 };
85 if(!(empty_str
= jsstr_alloc_buf(0)))
87 if(!(nan_str
= jsstr_alloc(NaNW
)))
92 void free_strings(void)
94 jsstr_release(empty_str
);
95 jsstr_release(nan_str
);