-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstrings.cpp
644 lines (533 loc) · 18.7 KB
/
strings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
#include "strings.h"
using namespace std::string_literals;
TEST_CASE("std::string literals")
{
auto s1{"Hello, world!"s};
auto s2{L"Hello, world!"s};
auto s3{u"Hello, world!"s};
auto s4{U"Hello, world!"s};
REQUIRE((std::is_same_v<decltype(s1), XXX>));
REQUIRE((std::is_same_v<decltype(s2), XXX>));
REQUIRE((std::is_same_v<decltype(s3), XXX>));
REQUIRE((std::is_same_v<decltype(s4), XXX>));
}
TEST_CASE("std::string variants")
{
REQUIRE((std::is_same_v<std::basic_string<char>, XXX>));
REQUIRE((std::is_same_v<std::string, std::basic_string<XXX>>));
REQUIRE((std::is_same_v<std::wstring, std::basic_string<XXX>>));
REQUIRE((std::is_same_v<std::u16string, std::basic_string<XXX>>));
REQUIRE((std::is_same_v<std::u32string, std::basic_string<XXX>>));
}
TEST_CASE("std::string related types")
{
REQUIRE((std::is_same_v<std::string::traits_type, XXX>));
REQUIRE((std::is_same_v<std::string::value_type, XXX>));
REQUIRE((std::is_same_v<std::string::reference, XXX>));
REQUIRE((std::is_same_v<std::string::const_reference, XXX>));
REQUIRE((std::is_same_v<std::string::reverse_iterator, std::reverse_iterator<XXX>>));
REQUIRE((std::is_same_v<std::string::const_reverse_iterator, std::reverse_iterator<XXX>>));
}
TEST_CASE("std::string constructors")
{
std::string const s1;
REQUIRE(xxx == s1.length());
std::string const s2{5, 'E'};
REQUIRE(xxx == s2.length());
std::string const s3{s2};
REQUIRE(xxx == s3.length());
std::string const s4{s2, 1};
REQUIRE(xxx == s4.length());
std::string const hw{"Hello, world!"};
std::string const s5{hw, 1, 4};
REQUIRE(xxx == s5);
std::string const s6{"Hello, world!"};
REQUIRE(xxx == s6.length());
std::string const s7{"Hello, world!", 5};
REQUIRE(xxx == s7);
std::string const s8{s7.begin(), s7.begin() + 1};
REQUIRE(xxx == s8);
std::string const s9{'H', 'e', 'l', 'l', 'o'};
REQUIRE(xxx == s9);
}
TEST_CASE("std::string accessors")
{
std::string const s{"Hello, world!"};
REQUIRE(xxx == s[0]);
REQUIRE('w' == s.at(xxx));
REQUIRE_THROWS_AS(s.at(1000), XXX);
REQUIRE(xxx == s.front());
REQUIRE(xxx == s.back());
REQUIRE((std::is_same_v<decltype(s.data()), XXX>));
REQUIRE((std::is_same_v<decltype(s.c_str()), XXX>));
}
TEST_CASE("string_iterators")
{
std::string const s{"Hello, world!"};
REQUIRE((std::is_same_v<decltype(s.begin()), XXX>));
REQUIRE((std::is_same_v<decltype(s.cbegin()), XXX>));
REQUIRE(xxx == *s.begin());
REQUIRE(xxx == *(s.end() - 1));
REQUIRE(xxx == *s.rbegin());
REQUIRE(xxx == *(s.rend() - 1));
}
TEST_CASE("std::string capacity")
{
std::string s{"Hello, world!"};
REQUIRE(xxx == s.length());
REQUIRE(xxx == s.empty());
REQUIRE(static_cast<std::string::size_type>(xxx) >= s.capacity());
s += s;
s = "Hello, world!";
REQUIRE(xxx == s.length());
REQUIRE(static_cast<std::string::size_type>(xxx) >= s.capacity());
s.shrink_to_fit();
REQUIRE(xxx == s.length());
REQUIRE(static_cast<std::string::size_type>(xxx) >= s.capacity());
s.reserve(1024);
REQUIRE(xxx == s.length());
REQUIRE(xxx == s.capacity());
}
TEST_CASE("std::string clear")
{
std::string s{"Hello, world!"};
s.clear();
REQUIRE(xxx == s.length());
REQUIRE(xxx == s.empty());
REQUIRE(s.capacity() >= static_cast<std::string::size_type>(xxx));
}
TEST_CASE("std::string insert")
{
std::string s2{"Bob"};
auto res1 = s2.insert(1, "illy B");
REQUIRE((std::is_same_v<decltype(res1), XXX>));
REQUIRE(xxx == s2);
auto res2 = s2.insert(0, 2, '-');
REQUIRE((std::is_same_v<decltype(res2), XXX>));
REQUIRE(xxx == s2);
auto res3 = s2.insert(2, "Hello, world!", 7);
REQUIRE((std::is_same_v<decltype(res3), XXX>));
REQUIRE(xxx == s2);
std::string s3{"Hello, world!"};
std::string s4{"big, fat "};
auto res4 = s3.insert(7, s4);
REQUIRE((std::is_same_v<decltype(res4), XXX>));
REQUIRE(xxx == s3);
std::string s5{"Hello, world!"};
auto res5 = s5.insert(7, s4, xxx, 3);
REQUIRE((std::is_same_v<decltype(res5), XXX>));
REQUIRE("Hello, fat world!"s == s5);
std::string s6{"Hello? "};
std::string::iterator it6{xxx};
auto res6 = s5.insert<std::string::iterator>(s5.begin(), s6.begin(), it6);
REQUIRE((std::is_same_v<decltype(res6), XXX>));
REQUIRE("Hello? Hello, fat world!"s == s5);
REQUIRE(xxx == *res6);
std::string s7{", world"};
auto res7 = s7.insert(0, {'H', 'e', 'l', 'l', 'o'});
REQUIRE((std::is_same_v<decltype(res7), XXX>));
REQUIRE(xxx == s7);
}
TEST_CASE("std::string erase")
{
std::string s1{"Hello, world!"};
s1.erase(5);
REQUIRE(xxx == s1);
std::string s2{"Hello, world!"};
s2.erase(5, 1);
REQUIRE(xxx == s2);
std::string s3{"Hello, world!"};
s3.erase(s3.end() - 1);
REQUIRE(xxx == s3);
std::string s4{"Hello, world!"};
std::string::iterator it4{xxx};
s4.erase(it4, s4.end() - 1);
REQUIRE("H!"s == s4);
}
TEST_CASE("std::string push_back")
{
std::string s{"<"};
char c{xxx};
s.push_back(c);
REQUIRE("<>"s == s);
}
TEST_CASE("std::string pop_back")
{
std::string s{"[]"};
s.pop_back();
REQUIRE(xxx == s);
}
TEST_CASE("std::string append")
{
std::string s1{"<["};
auto res1 = s1.append(xxx, 2);
REQUIRE((std::is_same_v<decltype(res1), XXX>));
REQUIRE("<[]>"s == s1);
std::string s2{"Foo"};
s2.append("bar"s);
REQUIRE(xxx == s2);
std::string s3{"Meta"};
s3.append("Well, what about the--"s, xxx);
REQUIRE("Meta--"s == s3);
std::string s4{"Wafer "};
s4.append("Something"s, 4, xxx);
REQUIRE("Wafer thin"s == s4);
std::string s5{"The good "};
s5.append(" wicked witch", xxx);
REQUIRE("The good witch"s == s5);
std::string s6{"Powdered "};
const char lit[] = "donut";
s6.append(std::begin(lit), xxx);
REQUIRE("Powdered donut"s == s6);
std::string s7{"+"};
std::initializer_list<char> il{ xxx, xxx, xxx };
s7.append(il);
REQUIRE("+--+"s == s7);
}
TEST_CASE("std::string operator+")
{
std::string s1{"One"};
std::string s2{s1 + static_cast<char>(xxx)};
REQUIRE("One!"s == s2);
std::string s3{static_cast<char>(xxx) + s2};
REQUIRE("!One!"s == s3);
std::string s4{"One, "};
std::string s5{xxx};
std::string s6{s4 + s5};
REQUIRE("One, Two"s == s6);
const char *lit = "Ten";
std::string s7{s4 + lit};
REQUIRE(xxx == s7);
}
TEST_CASE("std::string comparison operators")
{
const std::string alpha{"Alpha"};
REQUIRE("xxx"s < alpha);
REQUIRE("xxx"s > alpha);
REQUIRE("xxx"s <= alpha);
REQUIRE("xxx"s >= alpha);
REQUIRE("xxx"s == alpha);
REQUIRE("xxx"s != alpha);
}
TEST_CASE("std::string compare")
{
const std::string s1{"Alphabetical"};
const std::string s2{"Alphanumerical"};
auto res1 = s1.compare(s2);
REQUIRE((std::is_same_v<decltype(res1), XXX>));
REQUIRE(xxx == res1);
REQUIRE(0 == s1.compare(xxx, 5, s2));
REQUIRE(0 == s1.compare(xxx, 3, s2, 11, 3));
REQUIRE(0 == s1.compare("xxx"));
REQUIRE(0 == s1.compare(xxx, 4, "ical"));
REQUIRE(0 == s1.compare(xxx, 4, "Canonical", 5));
}
TEST_CASE("std::string replace")
{
std::string s{"Canonical"};
auto res = s.replace(xxx, xxx, "Med"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE("Medical"s == s);
std::string::iterator first1{xxx};
std::string::iterator last1{xxx};
s.replace(first1, last1, "Gargantuan"s);
REQUIRE("Gargantuan"s == s);
s.replace(xxx, xxx, " Two Face"s, xxx, xxx);
REQUIRE("Gargantua Two"s == s);
s.replace(xxx, xxx, "Orion double"s, xxx);
REQUIRE("Gargantuan double"s == s);
s.replace(xxx, xxx, "single minded", xxx);
REQUIRE("Gargantuan single"s == s);
std::string::iterator first2{xxx};
std::string::iterator last2{xxx};
s.replace(first2, last2, "double sided", xxx);
REQUIRE("Gargantuan double"s == s);
s.replace(xxx, xxx, "le carefully");
REQUIRE("Gargle carefully"s == s);
std::string::iterator first3{xxx};
std::string::iterator last3{xxx};
s.replace(first3, last3, "is funny sometimes", xxx);
REQUIRE("Gargle is funny"s == s);
s.replace(xxx, 4, xxx, '-');
REQUIRE("Gargle--funny"s == s);
std::string::iterator first4{xxx};
std::string::iterator last4{xxx};
s.replace(first4, last4, 1, '!');
REQUIRE("Gargle!"s == s);
std::string::iterator first5{xxx};
std::string::iterator last5{xxx};
s.replace(first5, last5, std::initializer_list<char>{ xxx, xxx, xxx });
REQUIRE("Woo!"s == s);
}
TEST_CASE("std::string substr")
{
std::string s{"Holly Jolly Folly"};
REQUIRE(xxx == s.substr());
REQUIRE("Folly"s == s.substr(xxx));
REQUIRE("Jolly"s == s.substr(xxx, xxx));
}
TEST_CASE("std::string copy")
{
char dest[5];
std::string s{"Holly Jolly Folly"};
auto res = s.copy(dest, xxx);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(std::string(std::begin(dest), std::end(dest)) == "Holly"s);
REQUIRE(xxx == res);
char dest2[5];
s.copy(dest2, xxx, xxx);
REQUIRE(std::string(std::begin(dest2), std::end(dest2)) == "Jolly"s);
REQUIRE_THROWS_AS(s.copy(dest2, 0, std::string::npos), XXX);
char dest3[80];
auto res2 = s.copy(dest3, std::string::npos);
REQUIRE(xxx == res2);
char dest4[5];
s.copy(dest4, std::string::npos, xxx);
REQUIRE(std::string(std::begin(dest4), std::end(dest4)) == "Folly"s);
}
TEST_CASE("std::string resize")
{
std::string s;
s.resize(xxx);
REQUIRE("\0\0\0"s == s);
s.resize(5, xxx);
REQUIRE("====="s == s);
}
TEST_CASE("std::string swap")
{
std::string s1{"Laurel"};
std::string s2{"Hardy"};
s1.swap(s2);
REQUIRE("xxx"s == s1);
REQUIRE("xxx"s == s2);
}
TEST_CASE("std::string find")
{
const std::string s{"Have a fun day at the zoo."};
auto res = s.find("a"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(xxx == res);
char ch{xxx};
REQUIRE(4 == s.find(ch));
REQUIRE(6 == s.find(ch, xxx));
REQUIRE(xxx == s.find("!"s));
REQUIRE(14 == s.find(" a"s, xxx));
REQUIRE(xxx == s.find(" a"));
REQUIRE(14 == s.find(" a", xxx));
REQUIRE(4 == s.find(" a", xxx, 1));
REQUIRE(xxx == ""s.find(ch));
REQUIRE(xxx == "foo"s.find(ch, 10));
REQUIRE(xxx == "foo"s.find("f"s, 10));
REQUIRE(xxx == "foo"s.find("f", 10));
}
TEST_CASE("std::string rfind")
{
std::string s{"Foobar Googly Eyes"};
auto res = s.rfind("oo"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(xxx == res);
REQUIRE(xxx == s.rfind("oo"s, 6));
REQUIRE(xxx == s.rfind("oo"));
REQUIRE(xxx == s.rfind("oo", 6));
REQUIRE(xxx == s.rfind("oo", 6, 1));
REQUIRE(xxx == s.rfind('y'));
REQUIRE(xxx == s.rfind('y', 14));
}
TEST_CASE("std::string find_first_of")
{
std::string s{"Foobar Googly Eyes"};
auto res = s.find_first_of("EGF"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(xxx == res);
REQUIRE(xxx == s.find_first_of("EGF"s, 1));
REQUIRE(xxx == s.find_first_of("EGF"));
REQUIRE(xxx == s.find_first_of("EGF", 1));
REQUIRE(xxx == s.find_first_of("EGF", 1, 1));
REQUIRE(xxx == s.find_first_of('o'));
REQUIRE(xxx == s.find_first_of('o', 3));
REQUIRE(xxx == s.find_first_of(""s));
REQUIRE(xxx == s.find_first_of(""));
REQUIRE(xxx == s.find_first_of("ABC"s));
REQUIRE(xxx == s.find_first_of("ABC"));
REQUIRE(xxx == s.find_first_of('A'));
REQUIRE(xxx == s.find_first_of("o"s, 100));
REQUIRE(xxx == s.find_first_of("o", 100));
REQUIRE(xxx == s.find_first_of("o", 100, 1));
REQUIRE(xxx == s.find_first_of('o', 100));
}
TEST_CASE("std::string find_first_not_of")
{
std::string s{"Foobar Googly Eyes"};
auto res = s.find_first_not_of("ABCDEFG"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(xxx == res);
REQUIRE(xxx == s.find_first_not_of("oab"s, 1));
REQUIRE(xxx == s.find_first_not_of("abF"));
REQUIRE(xxx == s.find_first_not_of("abF", 3));
REQUIRE(xxx == s.find_first_not_of("abF", 3, 1));
REQUIRE(xxx == s.find_first_not_of('F'));
REQUIRE(xxx == s.find_first_not_of('o', 1));
REQUIRE(xxx == s.find_first_not_of("Fobar GglyEes"s));
REQUIRE(xxx == s.find_first_not_of("Fobar GglyEes"));
REQUIRE(xxx == s.substr(1, 1).find_first_not_of('F'));
REQUIRE(xxx == s.find_first_not_of("o"s, 100));
REQUIRE(xxx == s.find_first_not_of("o", 100));
REQUIRE(xxx == s.find_first_not_of("o", 100, 1));
REQUIRE(xxx == s.find_first_not_of('o', 100));
}
TEST_CASE("std::string find_last_of")
{
std::string s{"Foobar Googly Eyes"};
auto res = s.find_last_of("EGF"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(xxx == res);
REQUIRE(xxx == s.find_last_of("EGF"s, 1));
REQUIRE(xxx == s.find_last_of("EGF"));
REQUIRE(xxx == s.find_last_of("EGF", 1));
REQUIRE(xxx == s.find_last_of("EGF", 1, 1));
REQUIRE(xxx == s.find_last_of('o'));
REQUIRE(xxx == s.find_last_of('o', 3));
REQUIRE(xxx == s.find_last_of(""s));
REQUIRE(xxx == s.find_last_of(""));
REQUIRE(xxx == s.find_last_of("ABC"s));
REQUIRE(xxx == s.find_last_of("ABC"));
REQUIRE(xxx == s.find_last_of('A'));
REQUIRE(xxx == s.find_last_of("o"s, 100));
REQUIRE(xxx == s.find_last_of("o", 100));
REQUIRE(xxx == s.find_last_of("o", 100, 1));
REQUIRE(xxx == s.find_last_of('o', 100));
}
TEST_CASE("std::string find_last_not_of")
{
std::string s{"Foobar Googly Eyes"};
auto res = s.find_last_not_of("ABCDEFG"s);
REQUIRE((std::is_same_v<decltype(res), XXX>));
REQUIRE(xxx == res);
REQUIRE(xxx == s.find_last_not_of("oab"s, 1));
REQUIRE(xxx == s.find_last_not_of("abF"));
REQUIRE(xxx == s.find_last_not_of("abF", 3));
REQUIRE(xxx == s.find_last_not_of("abF", 3, 1));
REQUIRE(xxx == s.find_last_not_of('F'));
REQUIRE(xxx == s.find_last_not_of('o', 1));
REQUIRE(xxx == s.find_last_not_of("Fobar GglyEes"s));
REQUIRE(xxx == s.find_last_not_of("Fobar GglyEes"));
REQUIRE(xxx == s.substr(1, 1).find_last_not_of('F'));
REQUIRE(xxx == s.find_last_not_of("o"s, 100));
REQUIRE(xxx == s.find_last_not_of("o", 100));
REQUIRE(xxx == s.find_last_not_of("o", 100, 1));
REQUIRE(xxx == s.find_last_not_of('o', 100));
}
TEST_CASE("std::string signed integer conversions")
{
auto res1 = std::stoi("111"s);
REQUIRE((std::is_same_v<decltype(res1), XXX>));
REQUIRE(xxx == res1);
auto res2 = std::stol("222"s);
REQUIRE((std::is_same_v<decltype(res2), XXX>));
REQUIRE(xxx == res2);
auto res3 = std::stoll("333"s);
REQUIRE((std::is_same_v<decltype(res3), XXX>));
REQUIRE(xxx == res3);
REQUIRE(xxx == std::stoi(L"111"s));
REQUIRE(xxx == std::stol(L"222"s));
REQUIRE(xxx == std::stoll(L"333"s));
REQUIRE(xxx == std::stoi(" \t\v\r\n\f111"s));
REQUIRE(xxx == std::stol(" \t\v\r\n\f222"s));
REQUIRE(xxx == std::stoll(" \t\v\r\n\f333"s));
REQUIRE(xxx == std::stoi("-1"));
REQUIRE(xxx == std::stoi("+1"));
std::size_t pos = 0;
REQUIRE(xxx == std::stoi("100x"s, &pos));
REQUIRE(xxx == pos);
for( int base = 2; base <= 36; ++base)
{
REQUIRE(xxx == std::stoi("10", nullptr, base));
}
REQUIRE(xxx == std::stoi("10", nullptr, 0));
REQUIRE(xxx == std::stoi("010", nullptr, 0));
REQUIRE(xxx == std::stoi("010", nullptr, 8));
REQUIRE(xxx == std::stoi("0x10", nullptr, 0));
REQUIRE(xxx == std::stoi("0X10", nullptr, 0));
REQUIRE(xxx == std::stoi("0x10", nullptr, 16));
REQUIRE(xxx == std::stoi("0xa", nullptr, 16));
REQUIRE(xxx == std::stoi("0xA", nullptr, 16));
REQUIRE_THROWS_AS(std::stoi("Yikes!"), XXX);
REQUIRE_THROWS_AS(std::stoi("0xFFFFFFFFFFFFFFFFFFFFFFFF", nullptr, 16), XXX);
}
TEST_CASE("std::string unsigned integer conversions")
{
auto res1 = std::stoul("111"s);
REQUIRE((std::is_same_v<decltype(res1), XXX>));
REQUIRE(xxx == res1);
auto res2 = std::stoull("222"s);
REQUIRE((std::is_same_v<decltype(res2), XXX>));
REQUIRE(xxx == res2);
REQUIRE(xxx == std::stoul(L"111"s));
REQUIRE(xxx == std::stoull(L"222"s));
REQUIRE(xxx == std::stoul(" \t\v\r\n\f111"s));
REQUIRE(xxx == std::stoull(" \t\v\r\n\f222"s));
REQUIRE(xxx == std::stoul("-1"));
REQUIRE(xxx == std::stoul("+1"));
std::size_t pos = 0;
REQUIRE(xxx == std::stoul("100x"s, &pos));
REQUIRE(xxx == pos);
for( int base = 2; base <= 36; ++base)
{
REQUIRE(xxx == std::stoul("10", nullptr, base));
}
REQUIRE(xxx == std::stoul("10", nullptr, 0));
REQUIRE(xxx == std::stoul("010", nullptr, 0));
REQUIRE(xxx == std::stoul("010", nullptr, 8));
REQUIRE(xxx == std::stoul("0x10", nullptr, 0));
REQUIRE(xxx == std::stoul("0X10", nullptr, 0));
REQUIRE(xxx == std::stoul("0x10", nullptr, 16));
REQUIRE_THROWS_AS(std::stoul("Yikes!"), XXX);
REQUIRE_THROWS_AS(std::stoul("0xFFFFFFFFFFFFFFFFFFFFFFFF", nullptr, 16), XXX);
}
TEST_CASE("std::string float conversions")
{
auto res1 = std::stof("111"s);
REQUIRE((std::is_same_v<decltype(res1), XXX>));
REQUIRE(xxx == res1);
auto res2 = std::stod("222"s);
REQUIRE((std::is_same_v<decltype(res2), XXX>));
REQUIRE(xxx == res2);
REQUIRE(xxx == std::stof(L"111"s));
REQUIRE(xxx == std::stod(L"222"s));
REQUIRE(xxx == std::stof(" \t\v\r\n\f111"s));
REQUIRE(xxx == std::stod(" \t\v\r\n\f222"s));
REQUIRE(xxx == std::stof("-1.5e1"));
REQUIRE(xxx == std::stof("+1.5E1"));
REQUIRE(xxx == std::stof("inf"));
REQUIRE(xxx == std::stof("-INFINITY"));
REQUIRE(xxx == std::stof("+nan"));
REQUIRE(xxx == std::stof("-nanotechnology"));
std::size_t pos = 0;
REQUIRE(xxx == std::stof("100x"s, &pos));
REQUIRE(xxx == pos);
REQUIRE_THROWS_AS(std::stof("Yikes!"), XXX);
REQUIRE_THROWS_AS(std::stof("0xFFFFFFFFFFFFFFFFFFFFFFFF", nullptr), XXX);
}
TEST_CASE("std::string to_string function")
{
REQUIRE((std::is_same_v<decltype(std::to_string(1)), XXX>));
REQUIRE((std::is_same_v<decltype(std::to_wstring(1)), XXX>));
REQUIRE("xxx"s == std::to_string(-1));
REQUIRE("xxx"s == std::to_string(2L));
REQUIRE("xxx"s == std::to_string(3LL));
REQUIRE("xxx"s == std::to_string(4U));
REQUIRE("xxx"s == std::to_string(5UL));
REQUIRE("xxx"s == std::to_string(6ULL));
REQUIRE("xxx"s == std::to_string(23.43f));
REQUIRE("xxx"s == std::to_string(23.43));
REQUIRE("xxx"s == std::to_string(23.43L));
REQUIRE("xxx"s == std::to_string(1e-40));
}
TEST_CASE("std::string allocators")
{
REQUIRE((std::is_same_v<std::string::allocator_type, XXX>));
REQUIRE((std::is_same_v<std::string::size_type, XXX>));
REQUIRE((std::is_same_v<std::string::difference_type, XXX>));
REQUIRE((std::is_same_v<std::string::pointer, XXX>));
REQUIRE((std::is_same_v<std::string::const_pointer, XXX>));
}