-
Notifications
You must be signed in to change notification settings - Fork 3
/
UseCases.html
602 lines (568 loc) · 17 KB
/
UseCases.html
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
<!doctype html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<head>
<title>std-text-wg use cases</title>
<style type="text/css">
#hide_text:checked ~ * fieldset.text { display:none; visibility:hidden }
#hide_text_view:checked ~ * fieldset.text_view { display:none; visibility:hidden }
#hide_cxx17:checked ~ * fieldset.cxx17 { display:none; visibility:hidden }
#hide_icu:checked ~ * fieldset.icu { display:none; visibility:hidden }
#hide_win32:checked ~ * fieldset.win32 { display:none; visibility:hidden }
#hide_qt:checked ~ * fieldset.qt { display:none; visibility:hidden }
fieldset.use_case_example {
float: left;
margin: 2px;
border-width: medium;
border-style: solid;
}
fieldset.use_case_example:not([solution]) {
border-color: grey;
}
fieldset.use_case_example[solution="yes"] {
border-color: green;
}
fieldset.use_case_example[solution="partial"] {
border-color: blue;
}
fieldset.use_case_example[solution="ugly"] {
border-color: orange;
}
fieldset.use_case_example[solution="no"] {
border-color: red;
}
fieldset.use_case_example:not([solution])::before {
content: "?";
}
fieldset.use_case_example[solution="no"]::before {
content: "X";
}
div.use_case {
padding-left: 20px;
display: table; /* undo float:left effect */
}
ol.use_cases {
padding-left: 20px;
counter-reset: item;
}
ol.use_cases > li {
display: block;
}
ol.use_cases > li::before {
content: counters(item, ".") ") ";
counter-increment: item;
}
div.tocItems {
margin-left: 1em;
}
div.tocItem {
margin-left: 1em;
}
</style>
<script>
function generateTOCItemHTML(toc, index, elem) {
var id;
if (elem.hasAttribute("id")) {
id = elem.getAttribute("id");
} else {
id = "toc" + index;
elem.setAttribute("id", id);
}
var link = document.createElement("a");
link.setAttribute("href", "#" + id);
link.innerHTML = index + ") " + elem.firstChild.innerHTML;
var div = document.createElement("div");
div.setAttribute("class", "tocItem");
div.appendChild(link);
toc.appendChild(div);
}
function generateTOCItem(toc, prefix, item, elem) {
if (elem.tagName === "LI") {
var childPrefix = (prefix ? prefix + "." : "") + item;
generateTOCItemHTML(toc, childPrefix, elem);
var children = elem.children;
for (var i = 0; i < children.length; i++) {
generateTOCItems(toc, childPrefix, children[i]);
}
}
}
function generateTOCItems(toc, prefix, elem) {
if (elem.tagName === "OL" &&
elem.className === "use_cases")
{
var div = document.createElement("div");
div.setAttribute("class", "tocItems");
toc.appendChild(div);
var item=0;
var children = elem.children;
for (var i = 0; i < children.length; i++) {
if (children[i].tagName === "LI") {
item++;
generateTOCItem(div, prefix, item, children[i]);
}
}
}
}
function generateTOC() {
var toc = document.getElementById("toc");
var prefix = "";
var children = document.body.children;
for (var i = 0; i < children.length; i++) {
generateTOCItems(toc, prefix, children[i]);
}
}
</script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>
function highlightSyntax() {
var allFieldSets, i, j;
allFieldSets = document.getElementsByTagName("fieldset");
for (i = 0, j = allFieldSets.length; i < j; i++) {
allPre = allFieldSets[i].getElementsByTagName("pre");
for (k = 0, l = allPre.length; k < l; k++) {
hljs.highlightBlock(allPre[k]);
}
}
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
generateTOC();
highlightSyntax();
});
</script>
</head>
<body>
<div id="toc">Use cases:</div>
<br/>
<input type="checkbox" id="hide_text">Hide text examples</input><br/>
<input type="checkbox" id="hide_text_view">Hide text_view examples</input><br/>
<input type="checkbox" id="hide_cxx17">Hide C++17 examples</input><br/>
<input type="checkbox" id="hide_icu">Hide ICU examples</input><br/>
<input type="checkbox" id="hide_win32">Hide Win32 examples</input><br/>
<input type="checkbox" id="hide_qt">Hide QT examples</input><br/>
<br/>
<fieldset>
<legend>Legend</legend>
<span style="color: grey">Unidentified solution</span><br/>
<span style="color: green">Reasonable solution</span><br/>
<span style="color: blue">Partial solution</span><br/>
<span style="color: orange">Ugly/impractical solution</span><br/>
<span style="color: red">No solution</span><br/>
</fieldset>
<ol class="use_cases">
<li><span>Code point enumeration:</span>
<ol class="use_cases">
<li><span>Given <em>std::string</em> <em>s</em> encoded with encoding
<em>E</em>, enumerate all encoded code points with error checking</span>
<div class="use_case">
<fieldset class="use_case_example text_view" solution="yes">
<legend>text_view</legend>
<pre>
// Produces code points of type std::experimental::text::character.
</pre>
<pre>
// Error handling via exceptions:
auto tv =
std::experimental::text::make_text_view<E>(s);
try {
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
} catch(text_decode_error e) {
// error handling...
}
</pre>
<pre>
// Error handling via character substitution:
auto tv =
std::experimental::text::make_text_view<
E,
std::experimental::text::text_permissive_error_policy>(s);
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
</pre>
<pre>
// Proactive error handling:
auto tv =
std::experimental::text::make_text_view<E>(s);
for (auto tvi = tv.begin(); tvi != tv.end(); ++tvi) {
if (tvi.error_occurred()) {
// error handling...
} else {
// Use code point as tvi->get_code_point()...
}
}
</pre>
</fieldset>
<fieldset class="use_case_example cxx17" solution="no">
<legend>C++17</legend>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
<li><span>Given <em>std::string</em> <em>s</em> encoded as UTF-8,
enumerate all encoded code points with error checking</span>
<div class="use_case">
<fieldset class="use_case_example text_view" solution="yes">
<legend>text_view</legend>
<pre>
// Produces code points of type std::experimental::text::character.
</pre>
<pre>
// Error handling via exceptions:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf8_encoding>(s);
try {
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
} catch(text_decode_error e) {
// error handling...
}
</pre>
<pre>
// Error handling via character substitution:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf8_encoding,
std::experimental::text::text_permissive_error_policy>(s);
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
</pre>
<pre>
// Proactive error handling:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf8_encoding>(s);
for (auto tvi = tv.begin(); tvi != tv.end(); ++tvi) {
if (tvi.error_occurred()) {
// error handling...
} else {
// Use code point as tvi->get_code_point()...
}
}
</pre>
</fieldset>
<fieldset class="use_case_example cxx17" solution="ugly">
<legend>C++17</legend>
<pre>
// Produces code points of type char32_t.
// Uses interfaces deprecated in C++17.
// libstdcxx is buggy; returns std::codecvt_base::partial too eagerly.
const char *from_next = s.data();
const char *from_end = s.data() + s.size();
std::codecvt_utf8<char32_t> utf8_converter;
std::mbstate_t state = std::mbstate_t{};
std::codecvt_base::result r;
do {
char32_t to[1];
char32_t *to_next = &to[0];
char32_t *to_end = &to[1];
r = utf8_converter.in(
state,
from_next, from_end, from_next,
to_next, to_end, to_next);
switch (r) {
case std::codecvt_base::ok:
// Use code point as t[0]...
break;
case std::codecvt_base::error:
// error handling...
break;
case std::codecvt_base::partial:
// error handling...
break;
case std::codecvt_base::noconv:
// error handling...
break;
}
} while (r == std::codecvt_base::ok &&
from_next != from_end);
</pre>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
<li><span>Given <em>std::u16string</em> <em>s</em> encoded as UTF-16,
enumerate all encoded code points with error checking</span>
<div class="use_case">
<fieldset class="use_case_example text_view" solution="yes">
<legend>text_view</legend>
<pre>
// Produces code points of type std::experimental::text::character.
</pre>
<pre>
// Error handling via exceptions:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf16_encoding>(s);
try {
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
} catch(text_decode_error e) {
// error handling...
}
</pre>
<pre>
// Error handling via character substitution:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf16_encoding,
std::experimental::text::text_permissive_error_policy>(s);
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
</pre>
<pre>
// Proactive error handling:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf16_encoding>(s);
for (auto tvi = tv.begin(); tvi != tv.end(); ++tvi) {
if (tvi.error_occurred()) {
// error handling...
} else {
// Use code point as tvi->get_code_point()...
}
}
</pre>
</fieldset>
<fieldset class="use_case_example cxx17" solution="ugly">
<legend>C++17</legend>
<pre>
// Produces code points of type char32_t.
// Uses interfaces deprecated in C++17.
// Requires knowing if the system is big or little endian.
// libstdcxx is buggy; returns std::codecvt_base::partial too eagerly.
const char16_t *from_next = s.data();
const char16_t *from_end = s.data() + s.size();
std::codecvt_utf16<char32_t, 0x10ffffUL, std::little_endian> utf16_converter;
std::mbstate_t state = std::mbstate_t{};
std::codecvt_base::result r;
do {
char32_t to[1];
char32_t *to_next = &to[0];
char32_t *to_end = &to[1];
r = utf16_converter.in(
state,
from_next, from_end, from_next,
to_next, to_end, to_next);
switch (r) {
case std::codecvt_base::ok:
// Use code point as t[0]...
break;
case std::codecvt_base::error:
// error handling...
break;
case std::codecvt_base::partial:
// error handling...
break;
case std::codecvt_base::noconv:
// error handling...
break;
}
} while (r == std::codecvt_base::ok &&
from_next != from_end);
</pre>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
<li><span>Given <em>std::u32string</em> <em>s</em> encoded as UTF-32,
enumerate all encoded code points with error checking</span>
<div class="use_case">
<fieldset class="use_case_example text_view" solution="yes">
<legend>text_view</legend>
<pre>
// Produces code points of type std::experimental::text::character.
</pre>
<pre>
// Error handling via exceptions:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf32_encoding>(s);
try {
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
} catch(text_decode_error e) {
// error handling...
}
</pre>
<pre>
// Error handling via character substitution:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf32_encoding,
std::experimental::text::text_permissive_error_policy>(s);
for (auto c : tv) {
// Use code point as c.get_code_point()...
}
</pre>
<pre>
// Proactive error handling:
auto tv =
std::experimental::text::make_text_view<
std::experimental::text::utf32_encoding>(s);
for (auto tvi = tv.begin(); tvi != tv.end(); ++tvi) {
if (tvi.error_occurred()) {
// error handling...
} else {
// Use code point as tvi->get_code_point()...
}
}
</pre>
</fieldset>
<fieldset class="use_case_example cxx17" solution="ugly">
<legend>C++17</legend>
<pre>
// Produces code points of type char32_t.
// Requires manual error detection of invalid code points.
for (auto cp : s) {
if (cp < 0xD800U ||
(cp >= 0xE000U && cp <= 0x10FFFFU))
{
// Use code point as cp...
} else {
// error handling...
}
}
</pre>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
</ol>
</li>
<li><span>Search (for a non-normalized code point sequence)</span>
<ol class="use_cases">
<li><span>Given <em>std::string</em> <em>s</em> encoded with encoding
<em>E</em>, provide an iterator pointing to the first code unit of
the first code unit sequence that encodes a code point sequence
matching the code points specified in range <em>cps</em></span>
<div class="use_case">
<fieldset class="use_case_example text_view">
<legend>text_view</legend>
</fieldset>
<fieldset class="use_case_example cxx17">
<legend>C++17</legend>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
<li><span>Given <em>std::string</em> <em>s</em> encoded as UTF-8,
provide an iterator pointing to the first code unit of the first code
unit sequence that encodes a code point sequence matching the code</span>
points specified in range <em>cps</em>.
<div class="use_case">
<fieldset class="use_case_example text_view">
<legend>text_view</legend>
</fieldset>
<fieldset class="use_case_example cxx17">
<legend>C++17</legend>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
<li><span>Given <em>std::u16string</em> <em>s</em> encoded as UTF-16,
provide an iterator pointing to the first code unit of the first code
unit sequence that encodes a code point sequence matching the code</span>
points specified in range <em>cps</em>.
<div class="use_case">
<fieldset class="use_case_example text_view">
<legend>text_view</legend>
</fieldset>
<fieldset class="use_case_example cxx17">
<legend>C++17</legend>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
<li><span>Given <em>std::u32string</em> <em>s</em> encoded as UTF-32,
provide an iterator pointing to the first code unit of the first code
unit sequence that encodes a code point sequence matching the code
points specified in range <em>cps</em></span>
<div class="use_case">
<fieldset class="use_case_example text_view">
<legend>text_view</legend>
</fieldset>
<fieldset class="use_case_example cxx17">
<legend>C++17</legend>
</fieldset>
<fieldset class="use_case_example icu">
<legend>ICU</legend>
</fieldset>
<fieldset class="use_case_example win32">
<legend>Win32</legend>
</fieldset>
<fieldset class="use_case_example qt">
<legend>QT</legend>
</fieldset>
</div>
</li>
</ol>
</li>
</ol>
</body>