kernel32: Some spelling tweaks and fixes for the error messages.
[wine] / dlls / msvcp90 / string.c
CommitLineData
b895c104
PC
1/*
2 * Copyright 2010 Piotr 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
6c57f13a
PC
19#include "config.h"
20
b895c104
PC
21#include <stdarg.h>
22
23#include "msvcp90.h"
24#include "stdio.h"
25
26#include "windef.h"
27#include "winbase.h"
28#include "wine/debug.h"
29WINE_DEFAULT_DEBUG_CHANNEL(msvcp90);
30
31/* char_traits<char> */
32/* ?assign@?$char_traits@D@std@@SAXAADABD@Z */
2ef0077d 33/* ?assign@?$char_traits@D@std@@SAXAEADAEBD@Z */
b895c104
PC
34void CDECL MSVCP_char_traits_char_assign(char *ch, const char *assign)
35{
36 *ch = *assign;
37}
38
39/* ?eq@?$char_traits@D@std@@SA_NABD0@Z */
2ef0077d 40/* ?eq@?$char_traits@D@std@@SA_NAEBD0@Z */
b895c104
PC
41MSVCP_BOOL CDECL MSVCP_char_traits_char_eq(const char *ch1, const char *ch2)
42{
43 return *ch1 == *ch2;
44}
45
46/* ?lt@?$char_traits@D@std@@SA_NABD0@Z */
2ef0077d 47/* ?lt@?$char_traits@D@std@@SA_NAEBD0@Z */
b895c104
PC
48MSVCP_BOOL CDECL MSVCP_char_traits_lt(const char *ch1, const char *ch2)
49{
50 return *ch1 < *ch2;
51}
52
2ef0077d
PC
53/* ?compare@?$char_traits@D@std@@SAHPBD0I@Z */
54/* ?compare@?$char_traits@D@std@@SAHPEBD0_K@Z */
b895c104 55int CDECL MSVCP_char_traits_char_compare(
2ef0077d 56 const char *s1, const char *s2, size_t count)
b895c104
PC
57{
58 int ret = memcmp(s1, s2, count);
59 return (ret>0 ? 1 : (ret<0 ? -1 : 0));
60}
61
62/* ?length@?$char_traits@D@std@@SAIPBD@Z */
2ef0077d
PC
63/* ?length@?$char_traits@D@std@@SA_KPEBD@Z */
64size_t CDECL MSVCP_char_traits_char_length(const char *str)
b895c104
PC
65{
66 return strlen(str);
67}
68
69/* ?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z */
2ef0077d 70/* ?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z */
b895c104 71char* CDECL MSVCP_char_traits_char__Copy_s(char *dest,
2ef0077d 72 size_t size, const char *src, size_t count)
b895c104
PC
73{
74 if(!dest || !src || size<count) {
75 if(dest && size)
76 dest[0] = '\0';
77 _invalid_parameter(NULL, NULL, NULL, 0, 0);
78 return dest;
79 }
80
81 return memcpy(dest, src, count);
82}
83
84/* ?copy@?$char_traits@D@std@@SAPADPADPBDI@Z */
2ef0077d 85/* ?copy@?$char_traits@D@std@@SAPEADPEADPEBD_K@Z */
b895c104 86char* CDECL MSVCP_char_traits_char_copy(
2ef0077d 87 char *dest, const char *src, size_t count)
b895c104
PC
88{
89 return MSVCP_char_traits_char__Copy_s(dest, count, src, count);
90}
91
92/* ?find@?$char_traits@D@std@@SAPBDPBDIABD@Z */
2ef0077d 93/* ?find@?$char_traits@D@std@@SAPEBDPEBD_KAEBD@Z */
b895c104 94const char * CDECL MSVCP_char_traits_char_find(
2ef0077d 95 const char *str, size_t range, const char *c)
b895c104
PC
96{
97 return memchr(str, *c, range);
98}
99
100/* ?_Move_s@?$char_traits@D@std@@SAPADPADIPBDI@Z */
2ef0077d 101/* ?_Move_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z */
b895c104 102char* CDECL MSVCP_char_traits_char__Move_s(char *dest,
2ef0077d 103 size_t size, const char *src, size_t count)
b895c104
PC
104{
105 if(!dest || !src || size<count) {
106 if(dest && size)
107 dest[0] = '\0';
108 _invalid_parameter(NULL, NULL, NULL, 0, 0);
109 return dest;
110 }
111
112 return memmove(dest, src, count);
113}
114
115/* ?move@?$char_traits@D@std@@SAPADPADPBDI@Z */
2ef0077d 116/* ?move@?$char_traits@D@std@@SAPEADPEADPEBD_K@Z */
b895c104 117char* CDECL MSVCP_char_traits_char_move(
2ef0077d 118 char *dest, const char *src, size_t count)
b895c104
PC
119{
120 return MSVCP_char_traits_char__Move_s(dest, count, src, count);
121}
122
123/* ?assign@?$char_traits@D@std@@SAPADPADID@Z */
2ef0077d
PC
124/* ?assign@?$char_traits@D@std@@SAPEADPEAD_KD@Z */
125char* CDECL MSVCP_char_traits_char_assignn(char *str, size_t num, char c)
b895c104
PC
126{
127 return memset(str, c, num);
128}
129
130/* ?to_char_type@?$char_traits@D@std@@SADABH@Z */
2ef0077d 131/* ?to_char_type@?$char_traits@D@std@@SADAEBH@Z */
b895c104
PC
132char CDECL MSVCP_char_traits_char_to_char_type(const int *i)
133{
134 return (char)*i;
135}
136
137/* ?to_int_type@?$char_traits@D@std@@SAHABD@Z */
2ef0077d 138/* ?to_int_type@?$char_traits@D@std@@SAHAEBD@Z */
b895c104
PC
139int CDECL MSVCP_char_traits_char_to_int_type(const char *ch)
140{
141 return (int)*ch;
142}
143
144/* ?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z */
2ef0077d 145/* ?eq_int_type@?$char_traits@D@std@@SA_NAEBH0@Z */
b895c104
PC
146MSVCP_BOOL CDECL MSVCP_char_traits_char_eq_int_type(const int *i1, const int *i2)
147{
148 return *i1 == *i2;
149}
150
151/* ?eof@?$char_traits@D@std@@SAHXZ */
152int CDECL MSVCP_char_traits_char_eof(void)
153{
154 return EOF;
155}
156
157/* ?not_eof@?$char_traits@D@std@@SAHABH@Z */
2ef0077d 158/* ?not_eof@?$char_traits@D@std@@SAHAEBH@Z */
b895c104
PC
159int CDECL MSVCP_char_traits_char_not_eof(int *in)
160{
161 return (*in==EOF ? !EOF : *in);
162}
8313d52c
PC
163
164
165/* char_traits<wchar_t> */
166/* ?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z */
fad0f817 167/* ?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z */
8313d52c
PC
168void CDECL MSVCP_char_traits_wchar_assign(wchar_t *ch,
169 const wchar_t *assign)
170{
171 *ch = *assign;
172}
173
174/* ?eq@?$char_traits@_W@std@@SA_NAB_W0@Z */
fad0f817 175/* ?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z */
8313d52c
PC
176MSVCP_BOOL CDECL MSVCP_char_traits_wchar_eq(wchar_t *ch1, wchar_t *ch2)
177{
178 return *ch1 == *ch2;
179}
180
181/* ?lt@?$char_traits@_W@std@@SA_NAB_W0@Z */
fad0f817 182/* ?lt@?$char_traits@_W@std@@SA_NAEB_W0@Z */
8313d52c
PC
183MSVCP_BOOL CDECL MSVCP_char_traits_wchar_lt(const wchar_t *ch1,
184 const wchar_t *ch2)
185{
186 return *ch1 < *ch2;
187}
188
189/* ?compare@?$char_traits@_W@std@@SAHPB_W0I@Z */
fad0f817 190/* ?compare@?$char_traits@_W@std@@SAHPEB_W0_K@Z */
8313d52c 191int CDECL MSVCP_char_traits_wchar_compare(const wchar_t *s1,
fad0f817 192 const wchar_t *s2, size_t count)
8313d52c
PC
193{
194 int ret = memcmp(s1, s2, sizeof(wchar_t[count]));
195 return (ret>0 ? 1 : (ret<0 ? -1 : 0));
196}
197
198/* ?length@?$char_traits@_W@std@@SAIPB_W@Z */
fad0f817
PC
199/* ?length@?$char_traits@_W@std@@SA_KPEB_W@Z */
200size_t CDECL MSVCP_char_traits_wchar_length(const wchar_t *str)
8313d52c
PC
201{
202 return wcslen((WCHAR*)str);
203}
204
205/* ?_Copy_s@?$char_traits@_W@std@@SAPA_WPA_WIPB_WI@Z */
fad0f817 206/* ?_Copy_s@?$char_traits@_W@std@@SAPEA_WPEA_W_KPEB_W1@Z */
8313d52c 207wchar_t* CDECL MSVCP_char_traits_wchar__Copy_s(wchar_t *dest,
fad0f817 208 size_t size, const wchar_t *src, size_t count)
8313d52c
PC
209{
210 if(!dest || !src || size<count) {
211 if(dest && size)
212 dest[0] = '\0';
213 _invalid_parameter(NULL, NULL, NULL, 0, 0);
214 return dest;
215 }
216
217 return memcpy(dest, src, sizeof(wchar_t[count]));
218}
219
220/* ?copy@?$char_traits@_W@std@@SAPA_WPA_WPB_WI@Z */
fad0f817 221/* ?copy@?$char_traits@_W@std@@SAPEA_WPEA_WPEB_W_K@Z */
8313d52c 222wchar_t* CDECL MSVCP_char_traits_wchar_copy(wchar_t *dest,
fad0f817 223 const wchar_t *src, size_t count)
8313d52c
PC
224{
225 return MSVCP_char_traits_wchar__Copy_s(dest, count, src, count);
226}
227
228/* ?find@?$char_traits@_W@std@@SAPB_WPB_WIAB_W@Z */
fad0f817 229/* ?find@?$char_traits@_W@std@@SAPEB_WPEB_W_KAEB_W@Z */
8313d52c 230const wchar_t* CDECL MSVCP_char_traits_wchar_find(
fad0f817 231 const wchar_t *str, size_t range, const wchar_t *c)
8313d52c 232{
fad0f817 233 size_t i=0;
8313d52c
PC
234
235 for(i=0; i<range; i++)
236 if(str[i] == *c)
237 return str+i;
238
239 return NULL;
240}
241
242/* ?_Move_s@?$char_traits@_W@std@@SAPA_WPA_WIPB_WI@Z */
fad0f817 243/* ?_Move_s@?$char_traits@_W@std@@SAPEA_WPEA_W_KPEB_W1@Z */
8313d52c 244wchar_t* CDECL MSVCP_char_traits_wchar__Move_s(wchar_t *dest,
fad0f817 245 size_t size, const wchar_t *src, size_t count)
8313d52c
PC
246{
247 if(!dest || !src || size<count) {
248 if(dest && size)
249 dest[0] = '\0';
250 _invalid_parameter(NULL, NULL, NULL, 0, 0);
251 return dest;
252 }
253
254 return memmove(dest, src, sizeof(WCHAR[count]));
255}
256
257/* ?move@?$char_traits@_W@std@@SAPA_WPA_WPB_WI@Z */
fad0f817 258/* ?move@?$char_traits@_W@std@@SAPEA_WPEA_WPEB_W_K@Z */
8313d52c 259wchar_t* CDECL MSVCP_char_traits_wchar_move(wchar_t *dest,
fad0f817 260 const wchar_t *src, size_t count)
8313d52c
PC
261{
262 return MSVCP_char_traits_wchar__Move_s(dest, count, src, count);
263}
264
265/* ?assign@?$char_traits@_W@std@@SAPA_WPA_WI_W@Z */
fad0f817 266/* ?assign@?$char_traits@_W@std@@SAPEA_WPEA_W_K_W@Z */
8313d52c 267wchar_t* CDECL MSVCP_char_traits_wchar_assignn(wchar_t *str,
fad0f817 268 size_t num, wchar_t c)
8313d52c 269{
fad0f817 270 size_t i;
8313d52c
PC
271
272 for(i=0; i<num; i++)
273 str[i] = c;
274
275 return str;
276}
277
278/* ?to_char_type@?$char_traits@_W@std@@SA_WABG@Z */
fad0f817 279/* ?to_char_type@?$char_traits@_W@std@@SA_WAEBG@Z */
8313d52c
PC
280wchar_t CDECL MSVCP_char_traits_wchar_to_char_type(const unsigned short *i)
281{
282 return *i;
283}
284
285/* ?to_int_type@?$char_traits@_W@std@@SAGAB_W@Z */
fad0f817 286/* ?to_int_type@?$char_traits@_W@std@@SAGAEB_W@Z */
8313d52c
PC
287unsigned short CDECL MSVCP_char_traits_wchar_to_int_type(const wchar_t *ch)
288{
289 return *ch;
290}
291
292/* ?eq_int_type@?$char_traits@_W@std@@SA_NABG0@Z */
fad0f817 293/* ?eq_int_type@?$char_traits@_W@std@@SA_NAEBG0@Z */
8313d52c
PC
294MSVCP_BOOL CDECL MSVCP_char_traits_wchar_eq_int_tpe(const unsigned short *i1,
295 const unsigned short *i2)
296{
297 return *i1 == *i2;
298}
299
300/* ?eof@?$char_traits@_W@std@@SAGXZ */
301unsigned short CDECL MSVCP_char_traits_wchar_eof(void)
302{
303 return WEOF;
304}
305
306/* ?not_eof@?$char_traits@_W@std@@SAGABG@Z */
fad0f817 307/* ?not_eof@?$char_traits@_W@std@@SAGAEBG@Z */
8313d52c
PC
308unsigned short CDECL MSVCP_char_traits_wchar_not_eof(const unsigned short *in)
309{
310 return (*in==WEOF ? !WEOF : *in);
311}
0a4e9015
PC
312
313
314/* char_traits<unsigned short> */
315/* ?assign@?$char_traits@G@std@@SAXAAGABG@Z */
96c622df 316/* ?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z */
0a4e9015
PC
317void CDECL MSVCP_char_traits_short_assign(unsigned short *ch,
318 const unsigned short *assign)
319{
320 *ch = *assign;
321}
322
323/* ?eq@?$char_traits@G@std@@SA_NABG0@Z */
96c622df 324/* ?eq@?$char_traits@G@std@@SA_NAEBG0@Z */
0a4e9015
PC
325MSVCP_BOOL CDECL MSVCP_char_traits_short_eq(const unsigned short *ch1,
326 const unsigned short *ch2)
327{
328 return *ch1 == *ch2;
329}
330
331/* ?lt@?$char_traits@G@std@@SA_NABG0@Z */
96c622df 332/* ?lt@?$char_traits@G@std@@SA_NAEBG0@Z */
0a4e9015
PC
333MSVCP_BOOL CDECL MSVCP_char_traits_short_lt(const unsigned short *ch1,
334 const unsigned short *ch2)
335{
336 return *ch1 < *ch2;
337}
338
339/* ?compare@?$char_traits@G@std@@SAHPBG0I@Z */
96c622df 340/* ?compare@?$char_traits@G@std@@SAHPEBG0_K@Z */
0a4e9015 341int CDECL MSVCP_char_traits_short_compare(const unsigned short *s1,
96c622df 342 const unsigned short *s2, size_t count)
0a4e9015 343{
96c622df 344 size_t i;
0a4e9015
PC
345
346 for(i=0; i<count; i++)
347 if(s1[i] != s2[i])
348 return (s1[i] < s2[i] ? -1 : 1);
349
350 return 0;
351}
352
353/* ?length@?$char_traits@G@std@@SAIPBG@Z */
96c622df
PC
354/* ?length@?$char_traits@G@std@@SA_KPEBG@Z */
355size_t CDECL MSVCP_char_traits_short_length(const unsigned short *str)
0a4e9015 356{
96c622df 357 size_t len;
0a4e9015
PC
358
359 for(len=0; str[len]; len++);
360
361 return len;
362}
363
364/* ?_Copy_s@?$char_traits@G@std@@SAPAGPAGIPBGI@Z */
96c622df 365/* ?_Copy_s@?$char_traits@G@std@@SAPEAGPEAG_KPEBG1@Z */
0a4e9015 366unsigned short * CDECL MSVCP_char_traits_short__Copy_s(unsigned short *dest,
96c622df 367 size_t size, const unsigned short *src, size_t count)
0a4e9015
PC
368{
369 if(size<count) {
370 _invalid_parameter(NULL, NULL, NULL, 0, 0);
371 return dest;
372 }
373
374 return memcpy(dest, src, sizeof(unsigned short[count]));
375}
376
377/* ?copy@?$char_traits@G@std@@SAPAGPAGPBGI@Z */
96c622df 378/* ?copy@?$char_traits@G@std@@SAPEAGPEAGPEBG_K@Z */
0a4e9015 379unsigned short* CDECL MSVCP_char_traits_short_copy(unsigned short *dest,
96c622df 380 const unsigned short *src, size_t count)
0a4e9015
PC
381{
382 return MSVCP_char_traits_short__Copy_s(dest, count, src, count);
383}
384
385/* ?find@?$char_traits@G@std@@SAPBGPBGIABG@Z */
96c622df 386/* ?find@?$char_traits@G@std@@SAPEBGPEBG_KAEBG@Z */
0a4e9015 387const unsigned short* CDECL MSVCP_char_traits_short_find(
96c622df 388 const unsigned short *str, size_t range, const unsigned short *c)
0a4e9015 389{
96c622df 390 size_t i;
0a4e9015
PC
391
392 for(i=0; i<range; i++)
393 if(str[i] == *c)
394 return str+i;
395
396 return NULL;
397}
398
399/* ?_Move_s@?$char_traits@G@std@@SAPAGPAGIPBGI@Z */
96c622df 400/* ?_Move_s@?$char_traits@G@std@@SAPEAGPEAG_KPEBG1@Z */
0a4e9015 401unsigned short* CDECL MSVCP_char_traits_short__Move_s(unsigned short *dest,
96c622df 402 size_t size, const unsigned short *src, size_t count)
0a4e9015
PC
403{
404 if(size<count) {
405 _invalid_parameter(NULL, NULL, NULL, 0, 0);
406 return dest;
407 }
408
409 return memmove(dest, src, sizeof(unsigned short[count]));
410}
411
412/* ?move@?$char_traits@G@std@@SAPAGPAGPBGI@Z */
96c622df 413/* ?move@?$char_traits@G@std@@SAPEAGPEAGPEBG_K@Z */
0a4e9015 414unsigned short* CDECL MSVCP_char_traits_short_move(unsigned short *dest,
96c622df 415 const unsigned short *src, size_t count)
0a4e9015
PC
416{
417 return MSVCP_char_traits_short__Move_s(dest, count, src, count);
418}
419
420/* ?assign@?$char_traits@G@std@@SAPAGPAGIG@Z */
96c622df 421/* ?assign@?$char_traits@G@std@@SAPEAGPEAG_KG@Z */
0a4e9015 422unsigned short* CDECL MSVCP_char_traits_short_assignn(unsigned short *str,
96c622df 423 size_t num, unsigned short c)
0a4e9015 424{
96c622df 425 size_t i;
0a4e9015
PC
426
427 for(i=0; i<num; i++)
428 str[i] = c;
429
430 return str;
431}
432
433/* ?to_char_type@?$char_traits@G@std@@SAGABG@Z */
96c622df 434/* ?to_char_type@?$char_traits@G@std@@SAGAEBG@Z */
0a4e9015
PC
435unsigned short CDECL MSVCP_char_traits_short_to_char_type(const unsigned short *i)
436{
437 return *i;
438}
439
440/* ?to_int_type@?$char_traits@G@std@@SAGABG@Z */
96c622df 441/* ?to_int_type@?$char_traits@G@std@@SAGAEBG@Z */
0a4e9015
PC
442unsigned short CDECL MSVCP_char_traits_short_to_int_type(const unsigned short *ch)
443{
444 return *ch;
445}
446
447/* ?eq_int_type@?$char_traits@G@std@@SA_NABG0@Z */
96c622df 448/* ?eq_int_type@?$char_traits@G@std@@SA_NAEBG0@Z */
0a4e9015
PC
449MSVCP_BOOL CDECL MSVCP_char_traits_short_eq_int_type(unsigned short *i1,
450 unsigned short *i2)
451{
452 return *i1 == *i2;
453}
454
455/* ?eof@?$char_traits@G@std@@SAGXZ */
456unsigned short CDECL MSVCP_char_traits_short_eof(void)
457{
458 return -1;
459}
460
461/* ?not_eof@?$char_traits@G@std@@SAGABG@Z */
96c622df 462/* ?not_eof@?$char_traits@G@std@@SAGAEBG@Z */
0a4e9015
PC
463unsigned short CDECL MSVCP_char_traits_short_not_eof(const unsigned short *in)
464{
465 return (*in==(unsigned short)-1 ? 0 : *in);
466}
6c57f13a
PC
467
468
1ba4fff9
PC
469/* _String_base */
470/* ?_Xlen@_String_base@std@@SAXXZ */
471void CDECL MSVCP__String_base_Xlen(void)
472{
473 static const char msg[] = "string too long";
474
475 TRACE("\n");
476 throw_exception(EXCEPTION_LENGTH_ERROR, msg);
477}
478
d7938822
PC
479/* ?_Xran@_String_base@std@@SAXXZ */
480void CDECL MSVCP__String_base_Xran(void)
481{
482 static const char msg[] = "invalid string position";
483
484 TRACE("\n");
485 throw_exception(EXCEPTION_OUT_OF_RANGE, msg);
486}
487
256a08ae
PC
488/* ?_Xinvarg@_String_base@std@@SAXXZ */
489void CDECL MSVCP__String_base_Xinvarg(void)
490{
491 static const char msg[] = "invalid string argument";
492
493 TRACE("\n");
494 throw_exception(EXCEPTION_INVALID_ARGUMENT, msg);
495}
496
1ba4fff9 497
6c57f13a 498/* basic_string<char, char_traits<char>, allocator<char>> */
50c99f00 499/* ?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB */
04f4b8a3 500/* ?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2_KB */
50c99f00
PC
501const size_t MSVCP_basic_string_char_npos = -1;
502
6c57f13a
PC
503/* Internal: basic_string_char_ptr - return pointer to stored string */
504static char* basic_string_char_ptr(basic_string_char *this)
505{
506 if(this->res == BUF_SIZE_CHAR-1)
507 return this->data.buf;
508 return this->data.ptr;
509}
510
6040c8f8
PC
511/* Internal: basic_string_char_const_ptr - returns const pointer to stored string */
512static const char* basic_string_char_const_ptr(const basic_string_char *this)
513{
514 if(this->res == BUF_SIZE_CHAR-1)
515 return this->data.buf;
516 return this->data.ptr;
517}
518
6c57f13a
PC
519/* Internal: basic_string_char_eos - sets string length, puts '\0' on the end */
520static void basic_string_char_eos(basic_string_char *this, size_t len)
521{
522 static const char nullbyte = '\0';
523
524 this->size = len;
525 MSVCP_char_traits_char_assign(basic_string_char_ptr(this)+len, &nullbyte);
526}
527
6040c8f8
PC
528/* Internal: basic_string_char_inside - checks if given pointer points inside stored string */
529static MSVCP_BOOL basic_string_char_inside(
530 basic_string_char *this, const char *ptr)
531{
532 char *cstr = basic_string_char_ptr(this);
533
534 return (ptr<cstr || ptr>=cstr+this->size) ? FALSE : TRUE;
535}
536
6c57f13a
PC
537/* Internal: basic_string_char_tidy - initialize basic_string buffer, deallocates data */
538/* Caution: new_size have to be smaller than BUF_SIZE_CHAR */
539static void basic_string_char_tidy(basic_string_char *this,
04f4b8a3 540 MSVCP_BOOL built, size_t new_size)
6c57f13a
PC
541{
542 if(built && BUF_SIZE_CHAR<=this->res) {
543 char *ptr = this->data.ptr;
544
545 if(new_size > 0)
546 MSVCP_char_traits_char__Copy_s(this->data.buf, BUF_SIZE_CHAR, ptr, new_size);
547 MSVCP_allocator_char_deallocate(this->allocator, ptr, this->res+1);
548 }
549
550 this->res = BUF_SIZE_CHAR-1;
551 basic_string_char_eos(this, new_size);
552}
553
6040c8f8
PC
554/* Internal: basic_string_char_grow - changes size of internal buffer */
555static MSVCP_BOOL basic_string_char_grow(
556 basic_string_char *this, size_t new_size, MSVCP_BOOL trim)
557{
558 if(this->res < new_size) {
559 size_t new_res = new_size;
560 char *ptr;
561
562 new_res |= 0xf;
563
564 if(new_res/3 < this->res/2)
565 new_res = this->res + this->res/2;
566
567 ptr = MSVCP_allocator_char_allocate(this->allocator, new_res);
568 if(!ptr)
569 ptr = MSVCP_allocator_char_allocate(this->allocator, new_size+1);
570 else
571 new_size = new_res;
572 if(!ptr) {
573 ERR("Out of memory\n");
574 basic_string_char_tidy(this, TRUE, 0);
575 return FALSE;
576 }
577
578 MSVCP_char_traits_char__Copy_s(ptr, new_size,
579 basic_string_char_ptr(this), this->size);
580 basic_string_char_tidy(this, TRUE, 0);
581 this->data.ptr = ptr;
582 this->res = new_size;
583 basic_string_char_eos(this, this->size);
584 } else if(trim && new_size < BUF_SIZE_CHAR)
585 basic_string_char_tidy(this, TRUE,
586 new_size<this->size ? new_size : this->size);
587 else if(new_size == 0)
588 basic_string_char_eos(this, 0);
589
590 return (new_size>0);
591}
592
935e0f53
PC
593/* ?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z */
594/* ?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0@Z */
595DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_erase, 12)
14072676 596basic_string_char* __thiscall MSVCP_basic_string_char_erase(
935e0f53
PC
597 basic_string_char *this, size_t pos, size_t len)
598{
cc4972e3 599 TRACE("%p %lu %lu\n", this, (unsigned long)pos, (unsigned long)len);
935e0f53
PC
600
601 if(pos > this->size) {
d7938822 602 MSVCP__String_base_Xran();
935e0f53
PC
603 return NULL;
604 }
605
606 if(len > this->size-pos)
607 len = this->size-pos;
608
609 if(len) {
610 MSVCP_char_traits_char__Move_s(basic_string_char_ptr(this)+pos,
611 this->res-pos, basic_string_char_ptr(this)+pos+len,
612 this->size-pos-len);
613 basic_string_char_eos(this, this->size-len);
614 }
615
616 return this;
617}
618
6040c8f8
PC
619/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z */
620/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@_K1@Z */
621DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_assign_substr, 16)
14072676 622basic_string_char* __thiscall MSVCP_basic_string_char_assign_substr(
6040c8f8
PC
623 basic_string_char *this, const basic_string_char *assign,
624 size_t pos, size_t len)
625{
cc4972e3 626 TRACE("%p %p %lu %lu\n", this, assign, (unsigned long)pos, (unsigned long)len);
6040c8f8
PC
627
628 if(assign->size < pos) {
d7938822 629 MSVCP__String_base_Xran();
6040c8f8
PC
630 return NULL;
631 }
632
633 if(len > assign->size-pos)
634 len = assign->size-pos;
635
636 if(this == assign) {
637 MSVCP_basic_string_char_erase(this, pos+len, MSVCP_basic_string_char_npos);
638 MSVCP_basic_string_char_erase(this, 0, pos);
639 } else if(basic_string_char_grow(this, len, FALSE)) {
640 MSVCP_char_traits_char__Copy_s(basic_string_char_ptr(this),
641 this->res, basic_string_char_const_ptr(assign)+pos, len);
642 basic_string_char_eos(this, len);
643 }
644
645 return this;
646}
647
648/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@@Z */
649/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@@Z */
d0928761
PC
650/* ??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z */
651/* ??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV01@AEBV01@@Z */
6040c8f8 652DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_assign, 8)
14072676 653basic_string_char* __thiscall MSVCP_basic_string_char_assign(
6040c8f8
PC
654 basic_string_char *this, const basic_string_char *assign)
655{
656 return MSVCP_basic_string_char_assign_substr(this, assign,
657 0, MSVCP_basic_string_char_npos);
658}
659
660/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z */
661/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@PEBD_K@Z */
662DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_assign_cstr_len, 12)
14072676 663basic_string_char* __thiscall MSVCP_basic_string_char_assign_cstr_len(
6040c8f8
PC
664 basic_string_char *this, const char *str, size_t len)
665{
cc4972e3 666 TRACE("%p %s %lu\n", this, debugstr_a(str), (unsigned long)len);
6040c8f8
PC
667
668 if(basic_string_char_inside(this, str))
669 return MSVCP_basic_string_char_assign_substr(this, this,
670 str-basic_string_char_ptr(this), len);
671 else if(basic_string_char_grow(this, len, FALSE)) {
672 MSVCP_char_traits_char__Copy_s(basic_string_char_ptr(this),
673 this->res, str, len);
674 basic_string_char_eos(this, len);
675 }
676
677 return this;
678}
679
680/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBD@Z */
681/* ?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@PEBD@Z */
6fa52cd3
VP
682/* ??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z */
683/* ??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV01@PEBD@Z */
6040c8f8 684DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_assign_cstr, 8)
14072676 685basic_string_char* __thiscall MSVCP_basic_string_char_assign_cstr(
6040c8f8
PC
686 basic_string_char *this, const char *str)
687{
688 return MSVCP_basic_string_char_assign_cstr_len(this, str,
689 MSVCP_char_traits_char_length(str));
690}
691
22e221c4
PC
692/* ?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ */
693/* ?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ */
168dabf0
PC
694/* ?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ */
695/* ?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ */
22e221c4 696DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_c_str, 4)
14072676 697const char* __thiscall MSVCP_basic_string_char_c_str(basic_string_char *this)
22e221c4
PC
698{
699 TRACE("%p\n", this);
700 return basic_string_char_const_ptr(this);
701}
702
f8424366
EW
703/* ?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ */
704/* ?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ */
705DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_capacity, 4)
706size_t __thiscall MSVCP_basic_string_char_capacity(basic_string_char *this)
707{
708 TRACE("%p\n", this);
709 return this->res;
710}
711
6c57f13a
PC
712/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ */
713/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ */
714DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_ctor, 4)
14072676 715basic_string_char* __thiscall MSVCP_basic_string_char_ctor(basic_string_char *this)
6c57f13a
PC
716{
717 TRACE("%p\n", this);
718
719 basic_string_char_tidy(this, FALSE, 0);
720 return this;
721}
703ab02b 722
d7b4b032
PC
723/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z */
724/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV01@@Z */
725DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_copy_ctor, 8)
14072676 726basic_string_char* __thiscall MSVCP_basic_string_char_copy_ctor(
d7b4b032
PC
727 basic_string_char *this, const basic_string_char *copy)
728{
729 TRACE("%p %p\n", this, copy);
730
731 basic_string_char_tidy(this, FALSE, 0);
732 MSVCP_basic_string_char_assign(this, copy);
733 return this;
734}
735
6675d69a
PC
736/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z */
737/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z */
738DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_ctor_cstr, 8)
14072676 739basic_string_char* __thiscall MSVCP_basic_string_char_ctor_cstr(
6675d69a
PC
740 basic_string_char *this, const char *str)
741{
742 TRACE("%p %s\n", this, debugstr_a(str));
743
744 basic_string_char_tidy(this, FALSE, 0);
745 MSVCP_basic_string_char_assign_cstr(this, str);
746 return this;
747}
748
acf0cea8
PC
749/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@II@Z */
750/* ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV01@_K1@Z */
751DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_ctor_substr, 16)
752basic_string_char* __thiscall MSVCP_basic_string_char_ctor_substr(
753 basic_string_char *this, const basic_string_char *assign,
754 size_t pos, size_t len)
755{
756 TRACE("%p %p %lu %lu\n", this, assign, (unsigned long)pos, (unsigned long)len);
757
758 basic_string_char_tidy(this, FALSE, 0);
759 MSVCP_basic_string_char_assign_substr(this, assign, pos, len);
760 return this;
761}
762
703ab02b
PC
763/* ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ */
764/* ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ */
765DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_dtor, 4)
14072676 766void __thiscall MSVCP_basic_string_char_dtor(basic_string_char *this)
703ab02b
PC
767{
768 TRACE("%p\n", this);
769 basic_string_char_tidy(this, TRUE, 0);
770}
04f4b8a3 771
ec8cdcc2
PC
772/* ?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ */
773/* ?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ */
774/* ?length@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ */
775/* ?length@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ */
776DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_length, 4)
777size_t __thiscall MSVCP_basic_string_char_length(basic_string_char *this)
778{
779 TRACE("%p\n", this);
780 return this->size;
781}
782
44039975
PC
783/* ?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z */
784/* ?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@_K1@Z */
785DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_append_substr, 16)
786basic_string_char* __thiscall MSVCP_basic_string_char_append_substr(basic_string_char *this,
787 basic_string_char *append, size_t offset, size_t count)
788{
789 if(append->size < offset)
790 MSVCP__String_base_Xran();
791
792 if(count > append->size-offset)
793 count = append->size-offset;
794
795 if(basic_string_char_grow(this, this->size+count, FALSE)) {
796 MSVCP_char_traits_char__Copy_s(basic_string_char_ptr(this)+this->size,
797 this->res-this->size, basic_string_char_ptr(append)+offset, count);
798 basic_string_char_eos(this, this->size+count);
799 }
800
801 return this;
802}
803
804/* ?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@@Z */
805/* ?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@@Z */
806DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_append, 8)
807basic_string_char* __thiscall MSVCP_basic_string_char_append(
808 basic_string_char *this, basic_string_char *append)
809{
810 return MSVCP_basic_string_char_append_substr(this, append,
811 0, MSVCP_basic_string_char_npos);
812}
813
b09125ad
PC
814/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIPBDI@Z */
815/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0PEBD0@Z */
816DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_compare_substr_cstr_len, 20)
817int __thiscall MSVCP_basic_string_char_compare_substr_cstr_len(
818 basic_string_char *this, size_t pos, size_t num,
819 const char *str, size_t count)
820{
821 int ans;
822
823 TRACE("%p %lu %lu %s %lu\n", this, (unsigned long)pos,
824 (unsigned long)num, str, (unsigned long)count);
825
826 if(this->size < pos)
827 MSVCP__String_base_Xran();
828
829 if(pos+num > this->size)
830 num = this->size-pos;
831
832 ans = MSVCP_char_traits_char_compare(basic_string_char_ptr(this)+pos,
833 str, num>count ? count : num);
834 if(ans)
835 return ans;
836
837 if(num > count)
838 ans = 1;
839 else if(num < count)
840 ans = -1;
841 return ans;
842}
843
844/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIPBD@Z */
845/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0PEBD@Z */
846DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_compare_substr_cstr, 16)
847int __thiscall MSVCP_basic_string_char_compare_substr_cstr(basic_string_char *this,
848 size_t pos, size_t num, const char *str)
849{
850 return MSVCP_basic_string_char_compare_substr_cstr_len(this, pos, num,
851 str, MSVCP_char_traits_char_length(str));
852}
853
854/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHPBD@Z */
855/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAHPEBD@Z */
856DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_compare_cstr, 8)
857int __thiscall MSVCP_basic_string_char_compare_cstr(
858 basic_string_char *this, const char *str)
859{
860 return MSVCP_basic_string_char_compare_substr_cstr_len(this, 0, this->size,
861 str, MSVCP_char_traits_char_length(str));
862}
863
864/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIABV12@II@Z */
865/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0AEBV12@00@Z */
866DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_compare_substr_substr, 24)
867int __thiscall MSVCP_basic_string_char_compare_substr_substr(
868 basic_string_char *this, size_t pos, size_t num,
869 basic_string_char *compare, size_t off, size_t count)
870{
871 TRACE("%p %lu %lu %p %lu %lu\n", this, (unsigned long)pos, (unsigned long)num,
872 compare, (unsigned long)off, (unsigned long)count);
873
874 if(compare->size < off)
875 MSVCP__String_base_Xran();
876
877 if(off+count > compare->size)
878 count = compare->size-off;
879
880 return MSVCP_basic_string_char_compare_substr_cstr_len(this, pos, num,
881 basic_string_char_ptr(compare)+off, count);
882}
883
884/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIABV12@@Z */
885/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0AEBV12@@Z */
886DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_compare_substr, 16)
887int __thiscall MSVCP_basic_string_char_compare_substr(
888 basic_string_char *this, size_t pos, size_t num,
889 basic_string_char *compare)
890{
891 return MSVCP_basic_string_char_compare_substr_cstr_len(this, pos, num,
892 basic_string_char_ptr(compare), compare->size);
893}
894
895/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHABV12@@Z */
896/* ?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAHAEBV12@@Z */
897DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_compare, 8)
898int __thiscall MSVCP_basic_string_char_compare(
899 basic_string_char *this, basic_string_char *compare)
900{
901 return MSVCP_basic_string_char_compare_substr_cstr_len(this, 0, this->size,
902 basic_string_char_ptr(compare), compare->size);
903}
04f4b8a3
PC
904
905/* basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> */
906/* ?npos@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@2IB */
907/* ?npos@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@2_KB */
908const size_t MSVCP_basic_string_wchar_npos = -1;
909
910/* Internal: basic_string_wchar_ptr - return pointer to stored string */
911static wchar_t* basic_string_wchar_ptr(basic_string_wchar *this)
912{
913 if(this->res == BUF_SIZE_WCHAR-1)
914 return this->data.buf;
915 return this->data.ptr;
916}
917
918/* Internal: basic_string_wchar_const_ptr - returns const pointer to stored string */
919static const wchar_t* basic_string_wchar_const_ptr(const basic_string_wchar *this)
920{
921 if(this->res == BUF_SIZE_WCHAR-1)
922 return this->data.buf;
923 return this->data.ptr;
924}
925
926/* Internal: basic_string_wchar_eos - sets string length, puts '\0' on the end */
927static void basic_string_wchar_eos(basic_string_wchar *this, size_t len)
928{
929 static const wchar_t nullbyte_w = '\0';
930
931 this->size = len;
932 MSVCP_char_traits_wchar_assign(basic_string_wchar_ptr(this)+len, &nullbyte_w);
933}
934
935/* Internal: basic_string_char_inside - checks if given pointer points inside stored string */
936static MSVCP_BOOL basic_string_wchar_inside(
937 basic_string_wchar *this, const wchar_t *ptr)
938{
939 wchar_t *cstr = basic_string_wchar_ptr(this);
940
941 return (ptr<cstr || ptr>=cstr+this->size) ? FALSE : TRUE;
942}
943
944/* Internal: basic_string_char_tidy - initialize basic_string buffer, deallocates data */
945/* Caution: new_size have to be smaller than BUF_SIZE_WCHAR */
946static void basic_string_wchar_tidy(basic_string_wchar *this,
947 MSVCP_BOOL built, size_t new_size)
948{
949 if(built && BUF_SIZE_WCHAR<=this->res) {
950 wchar_t *ptr = this->data.ptr;
951
952 if(new_size > 0)
953 MSVCP_char_traits_wchar__Copy_s(this->data.buf, BUF_SIZE_WCHAR, ptr, new_size);
954 MSVCP_allocator_wchar_deallocate(this->allocator, ptr, this->res+1);
955 }
956
957 this->res = BUF_SIZE_WCHAR-1;
958 basic_string_wchar_eos(this, new_size);
959}
960
961/* Internal: basic_string_wchar_grow - changes size of internal buffer */
962static MSVCP_BOOL basic_string_wchar_grow(
963 basic_string_wchar *this, size_t new_size, MSVCP_BOOL trim)
964{
965 if(this->res < new_size) {
966 size_t new_res = new_size;
967 wchar_t *ptr;
968
969 new_res |= 0xf;
970
971 if(new_res/3 < this->res/2)
972 new_res = this->res + this->res/2;
973
974 ptr = MSVCP_allocator_wchar_allocate(this->allocator, new_res);
975 if(!ptr)
976 ptr = MSVCP_allocator_wchar_allocate(this->allocator, new_size+1);
977 else
978 new_size = new_res;
979 if(!ptr) {
980 ERR("Out of memory\n");
981 basic_string_wchar_tidy(this, TRUE, 0);
982 return FALSE;
983 }
984
985 MSVCP_char_traits_wchar__Copy_s(ptr, new_size,
986 basic_string_wchar_ptr(this), this->size);
987 basic_string_wchar_tidy(this, TRUE, 0);
988 this->data.ptr = ptr;
989 this->res = new_size;
990 basic_string_wchar_eos(this, this->size);
991 } else if(trim && new_size < BUF_SIZE_WCHAR)
992 basic_string_wchar_tidy(this, TRUE,
993 new_size<this->size ? new_size : this->size);
994 else if(new_size == 0)
995 basic_string_wchar_eos(this, 0);
996
997 return (new_size>0);
998}
999
1000/* ?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@II@Z */
1001/* ?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@_K0@Z */
1002DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_erase, 12)
1003basic_string_wchar* __thiscall MSVCP_basic_string_wchar_erase(
1004 basic_string_wchar *this, size_t pos, size_t len)
1005{
cc4972e3 1006 TRACE("%p %lu %lu\n", this, (unsigned long)pos, (unsigned long)len);
04f4b8a3
PC
1007
1008 if(pos > this->size) {
1009 MSVCP__String_base_Xran();
1010 return NULL;
1011 }
1012
1013 if(len > this->size-pos)
1014 len = this->size-pos;
1015
1016 if(len) {
1017 MSVCP_char_traits_wchar__Move_s(basic_string_wchar_ptr(this)+pos,
1018 this->res-pos, basic_string_wchar_ptr(this)+pos+len,
1019 this->size-pos-len);
1020 basic_string_wchar_eos(this, this->size-len);
1021 }
1022
1023 return this;
1024}
1025
1026/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@ABV12@II@Z */
1027/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@AEBV12@_K1@Z */
1028DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_assign_substr, 16)
1029basic_string_wchar* __thiscall MSVCP_basic_string_wchar_assign_substr(
1030 basic_string_wchar *this, const basic_string_wchar *assign,
1031 size_t pos, size_t len)
1032{
cc4972e3 1033 TRACE("%p %p %lu %lu\n", this, assign, (unsigned long)pos, (unsigned long)len);
04f4b8a3
PC
1034
1035 if(assign->size < pos) {
1036 MSVCP__String_base_Xran();
1037 return NULL;
1038 }
1039
1040 if(len > assign->size-pos)
1041 len = assign->size-pos;
1042
1043 if(this == assign) {
1044 MSVCP_basic_string_wchar_erase(this, pos+len, MSVCP_basic_string_wchar_npos);
1045 MSVCP_basic_string_wchar_erase(this, 0, pos);
1046 } else if(basic_string_wchar_grow(this, len, FALSE)) {
1047 MSVCP_char_traits_wchar__Copy_s(basic_string_wchar_ptr(this),
1048 this->res, basic_string_wchar_const_ptr(assign)+pos, len);
1049 basic_string_wchar_eos(this, len);
1050 }
1051
1052 return this;
1053}
1054
1055/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@ABV12@@Z */
1056/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@AEBV12@@Z */
d0928761
PC
1057/* ??4?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV01@ABV01@@Z */
1058/* ??4?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV01@AEBV01@@Z */
04f4b8a3
PC
1059DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_assign, 8)
1060basic_string_wchar* __thiscall MSVCP_basic_string_wchar_assign(
1061 basic_string_wchar *this, const basic_string_wchar *assign)
1062{
1063 return MSVCP_basic_string_wchar_assign_substr(this, assign,
1064 0, MSVCP_basic_string_wchar_npos);
1065}
1066
1067/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@PB_WI@Z */
1068/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@PEB_W_K@Z */
1069DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_assign_cstr_len, 12)
1070basic_string_wchar* __thiscall MSVCP_basic_string_wchar_assign_cstr_len(
1071 basic_string_wchar *this, const wchar_t *str, size_t len)
1072{
cc4972e3 1073 TRACE("%p %s %lu\n", this, debugstr_w(str), (unsigned long)len);
04f4b8a3
PC
1074
1075 if(basic_string_wchar_inside(this, str))
1076 return MSVCP_basic_string_wchar_assign_substr(this, this,
1077 str-basic_string_wchar_ptr(this), len);
1078 else if(basic_string_wchar_grow(this, len, FALSE)) {
1079 MSVCP_char_traits_wchar__Copy_s(basic_string_wchar_ptr(this),
1080 this->res, str, len);
1081 basic_string_wchar_eos(this, len);
1082 }
1083
1084 return this;
1085}
1086
1087/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@PB_W@Z */
1088/* ?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@PEB_W@Z */
1089DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_assign_cstr, 8)
1090basic_string_wchar* __thiscall MSVCP_basic_string_wchar_assign_cstr(
1091 basic_string_wchar *this, const wchar_t *str)
1092{
1093 return MSVCP_basic_string_wchar_assign_cstr_len(this, str,
1094 MSVCP_char_traits_wchar_length(str));
1095}
1096
1097/* ?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ */
1098/* ?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ */
168dabf0
PC
1099/* ?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ */
1100/* ?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ */
04f4b8a3
PC
1101DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_c_str, 4)
1102const wchar_t* __thiscall MSVCP_basic_string_wchar_c_str(basic_string_wchar *this)
1103{
1104 TRACE("%p\n", this);
1105 return basic_string_wchar_const_ptr(this);
1106}
1107
f8424366
EW
1108/* ?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ */
1109/* ?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ */
1110DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_capacity, 4)
1111size_t __thiscall MSVCP_basic_string_wchar_capacity(basic_string_wchar *this)
1112{
1113 TRACE("%p\n", this);
1114 return this->res;
1115}
1116
04f4b8a3
PC
1117/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ */
1118/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ */
1119DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_ctor, 4)
1120basic_string_wchar* __thiscall MSVCP_basic_string_wchar_ctor(basic_string_wchar *this)
1121{
1122 TRACE("%p\n", this);
1123
1124 basic_string_wchar_tidy(this, FALSE, 0);
1125 return this;
1126}
1127
1128/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV01@@Z */
1129/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@AEBV01@@Z */
1130DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_copy_ctor, 8)
1131basic_string_wchar* __thiscall MSVCP_basic_string_wchar_copy_ctor(
1132 basic_string_wchar *this, const basic_string_wchar *copy)
1133{
1134 TRACE("%p %p\n", this, copy);
1135
1136 basic_string_wchar_tidy(this, FALSE, 0);
1137 MSVCP_basic_string_wchar_assign(this, copy);
1138 return this;
1139}
1140
1141/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z */
1142/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z */
1143DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_ctor_cstr, 8)
1144basic_string_wchar* __thiscall MSVCP_basic_string_wchar_ctor_cstr(
1145 basic_string_wchar *this, const wchar_t *str)
1146{
1147 TRACE("%p %s\n", this, debugstr_w(str));
1148
1149 basic_string_wchar_tidy(this, FALSE, 0);
1150 MSVCP_basic_string_wchar_assign_cstr(this, str);
1151 return this;
1152}
1153
acf0cea8
PC
1154/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV01@II@Z */
1155/* ??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@AEBV01@_K1@Z */
1156DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_ctor_substr, 16)
1157basic_string_wchar* __thiscall MSVCP_basic_string_wchar_ctor_substr(
1158 basic_string_wchar *this, const basic_string_wchar *assign,
1159 size_t pos, size_t len)
1160{
1161 TRACE("%p %p %lu %lu\n", this, assign, (unsigned long)pos, (unsigned long)len);
1162
1163 basic_string_wchar_tidy(this, FALSE, 0);
1164 MSVCP_basic_string_wchar_assign_substr(this, assign, pos, len);
1165 return this;
1166}
1167
04f4b8a3
PC
1168/* ??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ */
1169/* ??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ */
1170DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_dtor, 4)
1171void __thiscall MSVCP_basic_string_wchar_dtor(basic_string_wchar *this)
1172{
1173 TRACE("%p\n", this);
1174 basic_string_wchar_tidy(this, TRUE, 0);
1175}
ec8cdcc2
PC
1176
1177/* ?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ */
1178/* ?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ */
1179/* ?length@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ */
1180/* ?length@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ */
1181DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_length, 4)
1182size_t __thiscall MSVCP_basic_string_wchar_length(basic_string_wchar *this)
1183{
1184 TRACE("%p\n", this);
1185 return this->size;
1186}
676d0d41
VM
1187
1188/* ?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z */
1189/* ?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXAEAV12@@Z */
1190DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_char_swap, 8)
1191void __thiscall MSVCP_basic_string_char_swap(basic_string_char *this, basic_string_char *str)
1192{
1193 if(this != str) {
1194 char tmp[sizeof(this->data)];
1195 const size_t size = this->size;
1196 const size_t res = this->res;
1197
1198 memcpy(tmp, this->data.buf, sizeof(this->data));
1199 memcpy(this->data.buf, str->data.buf, sizeof(this->data));
1200 memcpy(str->data.buf, tmp, sizeof(this->data));
1201
1202 this->size = str->size;
1203 this->res = str->res;
1204
1205 str->size = size;
1206 str->res = res;
1207 }
1208}
96e4e219
VM
1209
1210/* ?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXAAV12@@Z */
1211/* ?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXAEAV12@@Z */
1212DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_swap, 8)
1213void __thiscall MSVCP_basic_string_wchar_swap(basic_string_wchar *this, basic_string_wchar *str)
1214{
1215 if(this != str) {
1216 char tmp[sizeof(this->data)];
1217 const size_t size = this->size;
1218 const size_t res = this->res;
1219
1220 memcpy(tmp, this->data.buf, sizeof(this->data));
1221 memcpy(this->data.buf, str->data.buf, sizeof(this->data));
1222 memcpy(str->data.buf, tmp, sizeof(this->data));
1223
1224 this->size = str->size;
1225 this->res = str->res;
1226
1227 str->size = size;
1228 str->res = res;
1229 }
1230}
b99c5824
PC
1231
1232/* ?append@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@ABV12@II@Z */
1233/* ?append@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@AEBV12@_K1@Z */
1234DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_append_substr, 16)
1235basic_string_wchar* __thiscall MSVCP_basic_string_wchar_append_substr(basic_string_wchar *this,
1236 basic_string_wchar *append, size_t offset, size_t count)
1237{
1238 if(append->size < offset)
1239 MSVCP__String_base_Xran();
1240
1241 if(count > append->size-offset)
1242 count = append->size-offset;
1243
1244 if(basic_string_wchar_grow(this, this->size+count, FALSE)) {
1245 MSVCP_char_traits_wchar__Copy_s(basic_string_wchar_ptr(this)+this->size,
1246 this->res-this->size, basic_string_wchar_ptr(append)+offset, count);
1247 basic_string_wchar_eos(this, this->size+count);
1248 }
1249
1250 return this;
1251}
1252
1253/* ?append@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@ABV12@@Z */
1254/* ?append@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@AEBV12@@Z */
1255DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_append, 8)
1256 basic_string_wchar* __thiscall MSVCP_basic_string_wchar_append(
1257 basic_string_wchar *this, basic_string_wchar *append)
1258{
1259 return MSVCP_basic_string_wchar_append_substr(this, append,
1260 0, MSVCP_basic_string_wchar_npos);
1261}
919a7ced
PC
1262
1263/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEHIIPB_WI@Z */
1264/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAH_K0PEB_W0@Z */
1265DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_compare_substr_cstr_len, 20)
1266int __thiscall MSVCP_basic_string_wchar_compare_substr_cstr_len(
1267 basic_string_wchar *this, size_t pos, size_t num,
1268 const wchar_t *str, size_t count)
1269{
1270 int ans;
1271
1272 TRACE("%p %lu %lu %s %lu\n", this, (unsigned long)pos,
1273 (unsigned long)num, debugstr_w(str), (unsigned long)count);
1274
1275 if(this->size < pos)
1276 MSVCP__String_base_Xran();
1277
1278 if(pos+num > this->size)
1279 num = this->size-pos;
1280
1281 ans = MSVCP_char_traits_wchar_compare(basic_string_wchar_ptr(this)+pos,
1282 str, num>count ? count : num);
1283 if(ans)
1284 return ans;
1285
1286 if(num > count)
1287 ans = 1;
1288 else if(num < count)
1289 ans = -1;
1290 return ans;
1291}
1292
1293/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEHIIPB_W@Z */
1294/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAH_K0PEB_W@Z */
1295DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_compare_substr_cstr, 16)
1296int __thiscall MSVCP_basic_string_wchar_compare_substr_cstr(basic_string_wchar *this,
1297 size_t pos, size_t num, const wchar_t *str)
1298{
1299 return MSVCP_basic_string_wchar_compare_substr_cstr_len(this, pos, num,
1300 str, MSVCP_char_traits_wchar_length(str));
1301}
1302
1303/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEHPB_W@Z */
1304/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAHPEB_W@Z */
1305DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_compare_cstr, 8)
1306int __thiscall MSVCP_basic_string_wchar_compare_cstr(
1307 basic_string_wchar *this, const wchar_t *str)
1308{
1309 return MSVCP_basic_string_wchar_compare_substr_cstr_len(this, 0, this->size,
1310 str, MSVCP_char_traits_wchar_length(str));
1311}
1312
1313/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEHIIABV12@II@Z */
1314/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAH_K0AEBV12@00@Z */
1315DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_compare_substr_substr, 24)
1316int __thiscall MSVCP_basic_string_wchar_compare_substr_substr(
1317 basic_string_wchar *this, size_t pos, size_t num,
1318 basic_string_wchar *compare, size_t off, size_t count)
1319{
1320 TRACE("%p %lu %lu %p %lu %lu\n", this, (unsigned long)pos, (unsigned long)num,
1321 compare, (unsigned long)off, (unsigned long)count);
1322
1323 if(compare->size < off)
1324 MSVCP__String_base_Xran();
1325
1326 if(off+count > compare->size)
1327 count = compare->size-off;
1328
1329 return MSVCP_basic_string_wchar_compare_substr_cstr_len(this, pos, num,
1330 basic_string_wchar_ptr(compare)+off, count);
1331}
1332
1333/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEHIIABV12@@Z */
1334/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAH_K0AEBV12@@Z */
1335DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_compare_substr, 16)
1336int __thiscall MSVCP_basic_string_wchar_compare_substr(
1337 basic_string_wchar *this, size_t pos, size_t num,
1338 basic_string_wchar *compare)
1339{
1340 return MSVCP_basic_string_wchar_compare_substr_cstr_len(this, pos, num,
1341 basic_string_wchar_ptr(compare), compare->size);
1342}
1343
1344/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEHABV12@@Z */
1345/* ?compare@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAHAEBV12@@Z */
1346DEFINE_THISCALL_WRAPPER(MSVCP_basic_string_wchar_compare, 8)
1347int __thiscall MSVCP_basic_string_wchar_compare(
1348 basic_string_wchar *this, basic_string_wchar *compare)
1349{
1350 return MSVCP_basic_string_wchar_compare_substr_cstr_len(this, 0, this->size,
1351 basic_string_wchar_ptr(compare), compare->size);
1352}