-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
2159 lines (2076 loc) · 123 KB
/
index.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
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
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html><html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>The WTF-8 encoding</title>
<style>
@media print {
html { margin: 0 !important; }
body { font-family: serif; }
th, td { font-family: inherit; }
a { color: inherit !important; }
.example:before { font-family: serif !important; }
a:link, a:visited { text-decoration: none !important; }
a:link:after, a:visited:after { /* create a cross-ref "see..." */; }
}
@page {
margin: 1.5cm 1.1cm;
}
h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
figure, div.figure, div.sidefigure, pre, table.propdef, table.propdef-extra,
.example { page-break-inside: avoid; }
dt { page-break-after: avoid; }
body {
background: white;
/* background-image: floating-margin-image-goes-here; */
background-position: top left;
background-attachment: fixed;
background-repeat: no-repeat;
color: black;
counter-reset: exampleno figure issue;
line-height: 1.5;
margin: 0 1em 0 8em;
max-width: 50em;
padding: 2em 1em;
}
html, :before {
font: 1em/1.45 Helvetica Neue, sans-serif, Droid Sans Fallback;
}
/* General structural markup */
h1, h2, h3, h4, h5, h6 { text-align: left; }
h1, h2, h3 { color: #3C790A }
h1 { font: 900 170% sans-serif; }
h2 { font: 800 140% sans-serif; }
h3 { font: 800 120% sans-serif; }
h4 { font: bold 100% sans-serif; }
h5 { font: italic 100% sans-serif; }
h6 { font: small-caps 100% sans-serif; }
h2, h3, h4, h5, h6 { margin-top: 3em; }
h1 + h2 { margin-top: 0em; }
h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 1.2em; }
hr {
border: none;
border-top: 1px solid silver;
}
.logo img { position: absolute; top: 1em; right: 1em; border: none }
.head { margin-bottom: 1em; }
.head h1 { clear: both; }
.head table { margin-left: 2em; margin-top: 2em; }
.head dd { margin-bottom: 0; }
p.copyright { font-size: small; }
p.copyright small { font-size: small; }
pre { margin: 1em 0 1em 2em; overflow: auto; }
pre, code, .idl-code {
font-size: .9em;
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
}
dt dfn code { font-size: inherit; }
dfn { font-weight: bolder; }
dfn var { font-style: normal; }
s, del {text-decoration: line-through; color: red; }
u, ins {text-decoration: underline; background: #bfa; }
sup {
vertical-align: super;
font-size: 80%
}
details { display: block; }
dt { font-weight: bold; }
dd { margin: 0 0 1em 2em; }
ul, ol { margin-left: 0; padding-left: 2em; }
li { margin: 0.25em 2em 0.5em 0; padding-left: 0; }
[data-md] > :first-child { margin-top: 0; }
[data-md] > :last-child { margin-bottom: 0; }
td.pre {
white-space: pre-wrap;
}
.css, .property { color: #005a9c; }
.property { white-space: nowrap; }
/* Boilerplate sections */
ul.indexlist { margin-left: 0; columns: 13em; }
ul.indexlist li { margin-left: 0; list-style: none }
ul.indexlist li li { margin-left: 1em; }
ul.indexlist a { font-weight: bold; }
ul.indexlist ul, ul.indexlist dl { font-size: smaller; }
ul.indexlist dl { margin-top: 0; }
ul.indexlist dt { margin: .2em 0 .2em 20px; }
ul.indexlist dd { margin: .2em 0 .2em 40px; }
.toc {
font-weight: bold;
line-height: 1.3;
list-style: none;
margin: 1em 0 0 5em;
padding: 0;
}
.toc ul { margin: 0; padding: 0; font-weight: normal; }
.toc ul ul { margin: 0 0 0 2em; font-style: italic; }
.toc ul ul ul { margin: 0}
.toc > li { margin: 1.5em 0; padding: 0; }
.toc li { clear: both; }
.toc ul.toc li { margin: 0.3em 0 0 0; }
.toc a { border-bottom-style: none; }
.toc a:hover, ul.toc a:focus { border-bottom-style: solid; }
/* Section numbers in a column of their own */
.toc span.secno {float: left; width: 4em; margin-left: -5em}
.toc ul ul span.secno { margin-left: -7em; }
table.proptable {
font-size: small;
border-collapse: collapse;
border-spacing: 0;
text-align: left;
margin: 1em 0;
}
table.proptable td, table.proptable th {
padding: 0.4em;
text-align: center;
}
table.proptable tr:hover td { background: #DEF; }
/* Links */
a[href] { color: inherit; border-bottom: 1px solid silver; text-decoration: none; }
a[href]:hover { background: #ffa; }
a[href]:active { color: #C00; background: transparent; }
img, a.logo { border-style: none; }
.heading, .issue, .note, .example, li, dt { position: relative; }
/* CSS-ish link types */
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {content: "“";}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {content: "”";}
[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after { content: ""; }
/* Element-type link styling */
[data-link-type=element] { font-family: monospace; }
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }
/* Self-links */
a.self-link {
position: absolute;
left: -2.5em;
width: 2em;
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: -3.5em;
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: gray;
color: white;
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: black;
}
a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }
:target:not(.note):not(.example):not(.warning):not(.domintro)::before {
position: absolute;
left: 0.25em;
transform: rotate(5deg);
color: black;
content: '\27BC';
line-height: 1.5em;
margin: -0.55em 0.25em 0 0.25em;
padding: 0 0.3em;
font-size: 3em;
font-size: 3rem;
}
.heading:target:not(#undefined)::before,
dt:target:not(#undefined)::before {
left: -3em;
}
/* Figures */
figure {
display: block;
text-align: center;
margin: 2.5em 0;
}
figure.sidefigure {
float: right;
width: 50%;
margin: 0 0 0.5em 0.5em
}
figure pre {
text-align: left;
display: table;
margin: 1em auto;
}
figure table {
margin: auto;
}
figure img, figure object {
display: block;
margin: auto;
max-width: 100%
}
figcaption {
counter-increment: figure;
font-size: 90%;
font-style: italic;
text-align: center;
}
figcaption::before {
content: "Figure " counter(figure) ". ";
font-weight: bold;
}
dd figure { margin-left: -2em; }
/* Definition tables */
table.definition {
border-spacing: 0;
padding: 0 1em 0.5em;
width: 100%;
table-layout: fixed;
margin: 1.2em 0;
}
table.definition td, table.definition th {
padding: 0.5em;
vertical-align: baseline;
border-bottom: 1px solid #bbd7e9;
}
table.definition th:first-child {
font-style: italic;
font-weight: normal;
text-align: left;
width: 8.3em;
padding-left: 1em;
}
table.definition > tbody > tr:last-child > th,
table.definition > tbody > tr:last-child > td {
border-bottom: none;
}
table.definition tr:first-child > th,
table.definition tr:first-child > td {
padding-top: 1em;
}
/* Footnotes at the bottom of a definition table */
table.definition td.footnote {
font-style: normal;
padding-top: .6em;
width: auto;
}
table.definition td.footnote::before {
content: " ";
display: block;
height: 0.6em;
width: 4em;
border-top: thin solid;
}
/* IDL fragments */
pre.idl {
padding: .5em 1em;
margin: 1.2em 0;
}
pre.idl :link, pre.idl :visited {
color:inherit;
background:transparent;
}
/* Data tables */
/* Comes in plain, long, complex, or define varieties */
.data {
margin: 1em auto;
border-collapse: collapse;
width: 100%;
border: hidden;
}
.data {
width: auto;
text-align: center;
}
.data caption {
text-align: left;
}
.data caption p:first-child {
font-style: italic;
text-align: center;
}
.data td, .data th {
padding: 0.5em;
border-width: 1px;
border-color: silver;
border-top-style: solid;
}
.data thead td:empty {
padding: 0;
border: 0;
}
.data thead th[scope="row"] {
text-align: right;
color: inherit;
}
.data thead,
.data tbody {
color: inherit;
border-bottom: 2px solid;
}
.data colgroup {
border-left: 2px solid;
}
.data tbody td[scope="row"]:first-child {
text-align: right;
color: inherit;
border-right: 2px solid;
border-top: 1px solid silver;
padding-right: 1em;
}
.data.define td:last-child {
text-align: left;
}
.data tbody th[rowspan],
.data tbody td[rowspan] {
border-left: 1px solid silver;
}
.data tbody th[rowspan]:first-child,
.data tbody td[rowspan]:first-child {
border-left: 0;
border-right: 1px solid silver;
}
.data.complex th,
.data.complex td {
border: 1px solid silver;
}
.data td.long {
vertical-align: baseline;
text-align: left;
}
.data img {
vertical-align: middle;
}
/* Switch/case <dl>s */
dl.switch {
padding-left: 2em;
}
dl.switch > dt {
text-indent: -1.5em;
}
dl.switch > dt:before {
content: '↪';
padding: 0 0.5em 0 0;
display: inline-block;
width: 1em;
text-align: right;
line-height: 0.5em;
}
/* Style for At Risk features (intended as editorial aid, not intended for publishing) */
.atrisk::before {
position: absolute;
margin-left: -5em;
margin-top: -2px;
padding: 4px;
border: 1px solid;
content: 'At risk';
font-size: small;
background-color: white;
color: gray;
border-radius: 1em;
text-align: center;
}
/* Obsoletion notice */
details.annoying-warning[open] {
background: #fdd;
color: red;
font-weight: bold;
text-align: center;
padding: .5em;
border: thick solid red;
border-radius: 1em;
position: fixed;
left: 1em;
right: 1em;
bottom: 1em;
z-index: 1000;
}
details.annoying-warning:not([open]) > summary {
background: #fdd;
color: red;
font-weight: bold;
text-align: center;
padding: .5em;
}
/* Examples */
.example {
counter-increment: exampleno;
}
.example::before {
content: "Example";
content: "Example " counter(exampleno);
min-width: 7.5em;
text-transform: uppercase;
display: block;
}
.illegal-example::before {
content: "Invalid Example";
content: "Invalid Example" counter(exampleno);
}
.example, .illegal-example, .html, .illegal-html, .xml, .illegal-xml {
padding: 0.5em;
margin: 1em 0;
position: relative;
clear: both;
}
pre.example, pre.illegal-example, pre.html,
pre.illegal-html, pre.xml, pre.illegal-xml {
padding-top: 1.5em;
}
.illegal-example { color: red; }
.illegal-example p { color: black; }
.html { color: #600; }
.illegal-html { color: red; }
.illegal-html p { color: black; }
.xml { color: #600; }
.illegal-xml { color: red; }
.illegal-xml p { color: black; }
code.css { font-family: inherit; font-size: 100% }
code.html { color: #600 } /* inline HTML */
code.xml { color: #600 } /* inline XML */
/* Issues */
.issue {
border-color: #E05252;
background: #FBE9E9;
counter-increment: issue;
}
.issue:before {
content: "Issue " counter(issue);
padding-right: 1em;
text-transform: uppercase;
color: #E05252;
}
/* Whys */
details.why > summary {
font-style: italic;
}
details.why[open] > summary {
border-bottom: 1px silver solid;
}
/* All the blocks get similarly styled */
table.definition, pre.idl, .example, .note, details.why, .issue {
border: none;
border-left: .5em solid black;
border-left: .5rem solid black;
}
.issue, .note, .example, .why {
padding: .5em;
margin-top: 1em;
margin-bottom: 1em;
}
table.definition, pre.idl {
background: hsl(210, 70%, 95%);
border-color: hsl(210, 80%, 75%);
}
.example {
background: hsl(50, 70%, 95%);
border-color: hsl(50, 70%, 60%);
}
.example::before {
color: hsl(50, 70%, 60%);
}
.note, details.why {
background: hsl(120, 70%, 95%);
border-color: hsl(120, 70%, 60%);
}
.note::before {
color: hsl(120, 70%, 60%);
}
.issue {
background: hsl(0, 70%, 95%);
border-color: hsl(0, 70%, 60%);
}
.issue::before {
color: hsl(0, 70%, 60%);
}
span.issue, span.note {
padding: .1em .5em .15em;
border-right-width: .5em;
border-right-style: solid;
}
</style>
<meta content="Bikeshed version 5a13603bcd59b77875c0c2472b981928dd11f21e" name="generator">
<link href="logo-wtf-8.svg" rel="icon">
<style>/* style-md-lists */
/* This is a weird hack for me not yet following the commonmark spec
regarding paragraph and lists. */
[data-md] > :first-child {
margin-top: 0;
}
[data-md] > :last-child {
margin-bottom: 0;
}</style>
<style>/* style-counters */
body {
counter-reset: example figure issue;
}
.issue {
counter-increment: issue;
}
.issue:not(.no-marker)::before {
content: "Issue " counter(issue);
}
.example {
counter-increment: example;
}
.example:not(.no-marker)::before {
content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
content: "Invalid Example" counter(example);
}
figcaption {
counter-increment: figure;
}
figcaption:not(.no-marker)::before {
content: "Figure " counter(figure) " ";
}</style>
<style>/* style-dfn-panel */
.dfn-panel {
position: absolute;
z-index: 35;
height: auto;
width: -webkit-fit-content;
width: fit-content;
max-width: 300px;
max-height: 500px;
overflow: auto;
padding: 0.5em 0.75em;
font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
background: #DDDDDD;
color: black;
border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
display: inline-block;
position: fixed;
left: .5em;
bottom: 2em;
margin: 0 auto;
max-width: calc(100vw - 1.5em - .4em - .5em);
max-height: 30vh;
}
.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-selflinks */
.heading, .issue, .note, .example, li, dt {
position: relative;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: gray;
color: white;
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: black;
}
a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }</style>
<style>/* style-autolinks */
.css.css, .property.property, .descriptor.descriptor {
color: #005a9c;
font-size: inherit;
font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
content: "‘";
}
.css::after, .property::after, .descriptor::after {
content: "’";
}
.property, .descriptor {
/* Don't wrap property and descriptor names */
white-space: nowrap;
}
.type { /* CSS value <type> */
font-style: italic;
}
pre .property::before, pre .property::after {
content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
content: "’";
}
[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
content: "";
}
[data-link-type=element],
[data-link-type=element-attr] {
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }
[data-link-type=biblio] {
white-space: pre;
}</style>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"></p>
<h1>The WTF-8 encoding</h1>
<div data-fill-with="spec-metadata">
<dl>
<dt class="editor">Editor:
<dd class="editor p-author h-card vcard"><a class="p-name fn u-url url" href="https://exyr.org/">Simon Sapin</a> (<a class="p-org org" href="https://www.mozilla.org/">Mozilla</a>)
<dt>Issue tracking:
<dd><span><a href="https://github.com/SimonSapin/wtf-8/issues">On GitHub</a></span>
<dt>Change history:
<dd><span><a href="https://github.com/SimonSapin/wtf-8/commits/gh-pages">On GitHub</a></span>
<dt>Last updated:
<dd><span>23 February 2022</span>
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright"><a href="http://creativecommons.org/publicdomain/zero/1.0/" rel="license"><img alt="CC0" src="zero.png"></a> To the extent possible under law, the editors have waived all copyright
and related or neighboring rights to this work. </p>
<hr title="Separator for header">
</div>
<div class="p-summary" data-fill-with="abstract">
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<p>WTF-8 (Wobbly Transformation Format − 8-bit) is a superset of <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8">UTF-8</a> that encodes <a data-link-type="dfn" href="#surrogate-code-point" id="ref-for-surrogate-code-point">surrogate code points</a> if they are not in a <a data-link-type="dfn" href="#surrogate-code-point-pair" id="ref-for-surrogate-code-point-pair">pair</a>. It represents, in a way compatible with UTF-8, text from systems such as JavaScript and Windows that use <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16">UTF-16</a> internally but don’t enforce the <a data-link-type="dfn" href="#well-formed" id="ref-for-well-formed">well-formedness</a> invariant that surrogates must be paired.</p>
</div>
<div data-fill-with="at-risk"></div>
<div data-fill-with="table-of-contents">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<ol class="toc" role="directory">
<li><a href="#intended-audience"><span class="secno">1</span> <span class="content"> Intended audience</span></a>
<li>
<a href="#motivation"><span class="secno">2</span> <span class="content"> Background and motivation</span></a>
<ol class="toc">
<li><a href="#cesu-8"><span class="secno">2.1</span> <span class="content"> Differences with CESU-8</span></a>
</ol>
<li>
<a href="#terminology"><span class="secno">3</span> <span class="content"> Terminology</span></a>
<ol class="toc">
<li><a href="#surrogates-code-points"><span class="secno">3.1</span> <span class="content"> Surrogate code points</span></a>
<li><a href="#surrogates-code-units"><span class="secno">3.2</span> <span class="content"> Surrogate 16-bit code units</span></a>
<li><a href="#surrogates-byte-sequences"><span class="secno">3.3</span> <span class="content"> Surrogate byte sequences</span></a>
</ol>
<li>
<a href="#ill-formed-utf-16"><span class="secno">4</span> <span class="content"> Potentially ill-formed UTF-16</span></a>
<ol class="toc">
<li><a href="#encoding-ill-formed-utf-16"><span class="secno">4.1</span> <span class="content"> Encoding</span></a>
<li><a href="#decoding-ill-formed-utf-16"><span class="secno">4.2</span> <span class="content"> Decoding</span></a>
</ol>
<li><a href="#generalized-utf8"><span class="secno">5</span> <span class="content"> Generalized UTF-8</span></a>
<li>
<a href="#the-wtf-8-encoding"><span class="secno">6</span> <span class="content"> The WTF-8 encoding</span></a>
<ol class="toc">
<li><a href="#encoding-wtf-8"><span class="secno">6.1</span> <span class="content"> Encoding</span></a>
<li><a href="#decoding-wtf-8"><span class="secno">6.2</span> <span class="content"> Decoding</span></a>
<li><a href="#converting-wtf-8-ill-formed-utf-16"><span class="secno">6.3</span> <span class="content"> Converting between WTF-8 and potentially ill-formed UTF-16</span></a>
<li><a href="#converting-wtf-8-utf-8"><span class="secno">6.4</span> <span class="content"> Converting between WTF-8 and UTF-8</span></a>
<li><a href="#concatenating"><span class="secno">6.5</span> <span class="content"> Concatenating WTF-8 strings</span></a>
</ol>
<li><a href="#implementations"><span class="secno">7</span> <span class="content"> Implementations</span></a>
<li><a href="#acknowledgments"><span class="secno">8</span> <span class="content"> Acknowledgments</span></a>
<li><a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ol class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
</ol>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ol class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
</ol>
</ol>
</div>
<p class="logo"><img height="100" src="logo-wtf-8.svg" width="100"> </p>
<h2 class="heading settled" data-level="1" id="intended-audience"><span class="secno">1. </span><span class="content"> Intended audience</span><a class="self-link" href="#intended-audience"></a></h2>
<p><a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8">WTF-8</a> is a hack intended to be used internally in self-contained systems
with components that need to support <a data-link-type="dfn" href="#potentially-ill-formed-utf-16" id="ref-for-potentially-ill-formed-utf-16">potentially ill-formed UTF-16</a> for legacy reasons.</p>
<p>Any <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8①">WTF-8</a> data <em>must</em> be converted
to a <a data-link-type="dfn" href="#unicode-text" id="ref-for-unicode-text">Unicode</a> encoding at the system’s boundary
before being emitted. <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8①">UTF-8</a> is recommended. <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8②">WTF-8</a> <em>must not</em> be used to represent text
in a file format or for transmission over the Internet.</p>
<p>In particular,
the <a href="https://encoding.spec.whatwg.org/">Encoding Standard</a> <a data-link-type="biblio" href="#biblio-encoding">[ENCODING]</a> defines <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8②">UTF-8</a> and other encodings for the Web.
There is no and will not be any <a href="https://encoding.spec.whatwg.org/#names-and-labels"> encoding label</a> <a data-link-type="biblio" href="#biblio-encoding">[ENCODING]</a> or <a href="http://www.iana.org/assignments/character-sets/character-sets.xhtml"> IANA charset alias</a> <a data-link-type="biblio" href="#biblio-charsets">[CHARSETS]</a> for <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8③">WTF-8</a>.</p>
<h2 class="heading settled" data-level="2" id="motivation"><span class="secno">2. </span><span class="content"> Background and motivation</span><a class="self-link" href="#motivation"></a></h2>
<p><em>This section is non-normative.</em></p>
<p>When <a href="http://www.unicode.org/versions/Unicode1.0.0/">Unicode 1.0</a> was published in 1991,
it defined 65536 <a data-link-type="dfn" href="#code-point" id="ref-for-code-point">code points</a> from U+0000 to U+FFFF
and assigned characters to around half of them.
Many software implementations chose the obvious memory representation
for Unicode text of 16 bits per <a data-link-type="dfn" href="#code-point" id="ref-for-code-point①">code point</a> / character.</p>
<p>At the time, “Unicode” was synonymous with that particular encoding.
To disambiguate, that encoding is now called <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="ucs-2">UCS-2</dfn>.</p>
<p>As subsequent versions of Unicode assigned more characters,
it became apparent that 65536 <a data-link-type="dfn" href="#code-point" id="ref-for-code-point②">code points</a> would not be sufficient.
Unicode was extended to 1114112 <a data-link-type="dfn" href="#code-point" id="ref-for-code-point③">code points</a> from U+0000 to U+10FFFF,
and the <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16①">UTF-16</a> encoding was introduced.
This encoding preserves compatibility with existing 16-bit based systems
and represents new (<a data-link-type="dfn" href="#supplementary-code-point" id="ref-for-supplementary-code-point">supplementary</a>) code points
as a <a data-link-type="dfn" href="#surrogate-16-bit-code-unit-pair" id="ref-for-surrogate-16-bit-code-unit-pair">pair</a> of “surrogates”.</p>
<p><a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16②">UTF-16</a> is designed to represent any Unicode text,
but it can not represent a <a data-link-type="dfn" href="#surrogate-code-point-pair" id="ref-for-surrogate-code-point-pair①">surrogate code point pair</a> since the corresponding <a data-link-type="dfn" href="#surrogate-16-bit-code-unit-pair" id="ref-for-surrogate-16-bit-code-unit-pair①">surrogate 16-bit code unit pairs</a> would instead represent a <a data-link-type="dfn" href="#supplementary-code-point" id="ref-for-supplementary-code-point①">supplementary code point</a>.
Therefore, the concept of <a data-link-type="dfn" href="#unicode-scalar-value" id="ref-for-unicode-scalar-value">Unicode scalar value</a> was introduced
and <a data-link-type="dfn" href="#unicode-text" id="ref-for-unicode-text①">Unicode text</a> was restricted to not contain any <a data-link-type="dfn" href="#surrogate-code-point" id="ref-for-surrogate-code-point①">surrogate code point</a>.
(This was presumably deemed simpler that only restricting pairs.)</p>
<p><a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16③">UTF-16</a> was redefined to be <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed">ill-formed</a> if it contains <a data-link-type="dfn" href="#unpaired-surrogate-16-bit-code-unit" id="ref-for-unpaired-surrogate-16-bit-code-unit">unpaired surrogate 16-bit code units</a>. <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8③">UTF-8</a> was similarly redefined to be <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed①">ill-formed</a> if it contains <a data-link-type="dfn" href="#surrogate-byte-sequence" id="ref-for-surrogate-byte-sequence">surrogate byte sequences</a>.</p>
<p>Meanwhile, 16-bit based systems had little to no incentive
to do anything about surrogates:
For several years,
Unicode did not assign any character to <a data-link-type="dfn" href="#supplementary-code-point" id="ref-for-supplementary-code-point②">supplementary code points</a>,
and then (until emoji) only comparatively rare characters.
Additionally, the Unicode Standard does not require conforming implementations
to maintain <a data-link-type="dfn" href="#well-formed" id="ref-for-well-formed①">well-formedness</a> of <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16④">UTF-16</a> strings.</p>
<p>As a result, surrogates do occur in practice and need to be preserved.
For example:</p>
<ul>
<li> In ECMAScript (a.k.a. JavaScript), <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.16"> a <code>String</code> value</a> is defined as a sequence of 16-bit integers
that <em>usually</em> represents <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16⑤">UTF-16</a> text
but may or may not be <a data-link-type="dfn" href="#well-formed" id="ref-for-well-formed②">well-formed</a>.
<li> <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd374069%28v=vs.85%29.aspx"> Windows applications normally use UTF-16</a>, but <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#maxpath"> the file system treats path and file names as an opaque sequence of <code>WCHAR</code>s</a> (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx#WCHAR">16-bit
code units</a>).
</ul>
<p>We say that strings in these systems are encoded in <a data-link-type="dfn" href="#potentially-ill-formed-utf-16" id="ref-for-potentially-ill-formed-utf-16①">potentially ill-formed UTF-16</a> or <a data-link-type="dfn" href="#wtf-16" id="ref-for-wtf-16">WTF-16</a>.</p>
<p><a data-link-type="dfn" href="#unpaired-surrogate-16-bit-code-unit" id="ref-for-unpaired-surrogate-16-bit-code-unit①">Unpaired surrogate 16-bit code units</a> are the only case
where an arbitrary sequence of <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit">16-bit code units</a> is <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed②">ill-formed</a> in <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16⑥">UTF-16</a>. <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8④">UTF-8</a>, however, is more complex
and maintaining its <a data-link-type="dfn" href="#well-formed" id="ref-for-well-formed③">well-formedness</a> is arguably more valuable.</p>
<p>This specification defines <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8④">WTF-8</a>,
a superset of <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8⑤">UTF-8</a> that can losslessly represent
arbitrary sequences of <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit①">16-bit code unit</a> (even if <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed③">ill-formed</a> in <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16⑦">UTF-16</a>)
but preserves the other <a data-link-type="dfn" href="#well-formed" id="ref-for-well-formed④">well-formedness</a> constraints of <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8⑥">UTF-8</a>.</p>
<h3 class="heading settled" data-level="2.1" id="cesu-8"><span class="secno">2.1. </span><span class="content"> Differences with CESU-8</span><a class="self-link" href="#cesu-8"></a></h3>
<p>Unicode defines a <a href="http://www.unicode.org/reports/tr26/"> Compatibility Encoding Scheme for UTF-16: 8-Bit (CESU-8)</a>. <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8⑤">WTF-8</a> is different from CESU-8.</p>
<p>CESU-8 encodes <a data-link-type="dfn" href="#supplementary-code-point" id="ref-for-supplementary-code-point③">supplementary code points</a> as <a data-link-type="dfn" href="#surrogate-pair-byte-sequence" id="ref-for-surrogate-pair-byte-sequence">surrogate pair byte sequences</a> of six bytes,
whereas <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8⑥">WTF-8</a>, like <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8⑦">UTF-8</a>, encodes them as sequences of four bytes.
Therefore, CESU-8 is not a superset of <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8⑧">UTF-8</a>.</p>
<p>CESU-8 is also a mapping on <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16⑧">UTF-16</a> code units.
Therefore <a data-link-type="dfn" href="#unpaired-surrogate-byte-sequence" id="ref-for-unpaired-surrogate-byte-sequence">unpaired surrogate byte sequences</a> are <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed④">ill-formed</a> in CESU-8,
whereas supporting them is the entire point of <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8⑦">WTF-8</a>.</p>
<h2 class="heading settled" data-level="3" id="terminology"><span class="secno">3. </span><span class="content"> Terminology</span><a class="self-link" href="#terminology"></a></h2>
<p>These definitions correspond to those of the <a href="http://www.unicode.org/glossary/">Glossary of Unicode Terms</a>. <a data-link-type="biblio" href="#biblio-unicode">[UNICODE]</a></p>
<p>A Unicode <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="code-point">code point</dfn> is any value in the Unicode codespace;
that is, the range of integers from 0 to 1114111.
It is noted with a “U+” prefix and four to six hexadecimal digits:
the first and last code points are U+0000 and U+10FFFF.</p>
<p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="basic-multilingual-plane">Basic Multilingual Plane</dfn> is
the range of <a data-link-type="dfn" href="#code-point" id="ref-for-code-point④">code points</a> from U+0000 to U+FFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="bmp-code-point">BMP code point</dfn> is a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point⑤">code point</a> in the <a data-link-type="dfn" href="#basic-multilingual-plane" id="ref-for-basic-multilingual-plane">Basic Multilingual Plane</a>.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="supplementary-code-point">supplementary code point</dfn> is a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point⑥">code point</a> not in the Basic Multilingual Plane.
That is, a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point⑦">code point</a> in the range from U+10000 to U+10FFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="unicode-scalar-value">Unicode scalar value</dfn> is a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point⑧">code point</a> that is not a <a data-link-type="dfn" href="#surrogate-code-point" id="ref-for-surrogate-code-point②">surrogate code point</a>.
That is, a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point⑨">code point</a> in the range from U+0000 to U+D7FF,
or in the range U+E000 to U+10FFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="bmp-scalar-value">BMP scalar value</dfn> is a <a data-link-type="dfn" href="#unicode-scalar-value" id="ref-for-unicode-scalar-value①">Unicode scalar value</a> in the <a data-link-type="dfn" href="#basic-multilingual-plane" id="ref-for-basic-multilingual-plane①">Basic Multilingual Plane</a>.
That is, a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point①⓪">code point</a> in the range from U+0000 to U+D7FF,
or in the range U+E000 to U+FFFF.</p>
<p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="unicode-text">Unicode text</dfn> is a sequence of <a data-link-type="dfn" href="#unicode-scalar-value" id="ref-for-unicode-scalar-value②">Unicode scalar values</a>.</p>
<p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="utf-8">UTF-8</dfn> is an encoding of <a data-link-type="dfn" href="#unicode-text" id="ref-for-unicode-text②">Unicode text</a> using 8-bit bytes.
Each <a data-link-type="dfn" href="#unicode-scalar-value" id="ref-for-unicode-scalar-value③">Unicode scalar value</a> is represented as a sequence of one to four bytes.</p>
<p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="utf-16">UTF-16</dfn> is an encoding of <a data-link-type="dfn" href="#unicode-text" id="ref-for-unicode-text③">Unicode text</a> using <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit②">16-bit code units</a>. <a data-link-type="dfn" href="#bmp-scalar-value" id="ref-for-bmp-scalar-value">BMP scalar values</a> are represented as a single <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit③">16-bit code unit</a> with the same value. <a data-link-type="dfn" href="#supplementary-code-point" id="ref-for-supplementary-code-point④">Supplementary code points</a> are represented as a <a data-link-type="dfn" href="#surrogate-16-bit-code-unit-pair" id="ref-for-surrogate-16-bit-code-unit-pair②">surrogate 16-bit code unit pair</a>.</p>
<p class="note" role="note"><span>Note:</span> this specification is only concerned with the UTF-16 <a href="http://www.unicode.org/glossary/#character_encoding_form">encoding form</a> (based on <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit④">16-bit code units</a>),
and not with the <a href="http://www.unicode.org/glossary/#character_encoding_scheme">encoding scheme</a> (based on bytes, with UTF-16BE and UTF-16LE variants).</p>
<p>A string is <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="well-formed|well-formedness" data-noexport="" id="well-formed">well-formed</dfn> (not <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="ill-formed|ill-formedness" data-noexport="" id="ill-formed">ill-formed</dfn>)
in a given encoding if it follows the specification of that encoding. <a data-link-type="biblio" href="#biblio-unicode">[UNICODE]</a> defines <a href="http://www.unicode.org/glossary/#well_formed_code_unit_sequence"> Well-Formed Code Unit Sequence</a> for <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8⑨">UTF-8</a> and <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16⑨">UTF-16</a>.</p>
<div class="note" role="note">
In particular:
<ul>
<li><a data-link-type="dfn" href="#unpaired-surrogate-16-bit-code-unit" id="ref-for-unpaired-surrogate-16-bit-code-unit②">Unpaired surrogate 16-bit code units</a> are <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed⑤">ill-formed</a> in <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16①⓪">UTF-16</a>.
<li><a data-link-type="dfn" href="#surrogate-byte-sequence" id="ref-for-surrogate-byte-sequence①">Surrogate byte sequences</a> are <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed⑥">ill-formed</a> in <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8①⓪">UTF-8</a>.
<li><a data-link-type="dfn" href="#surrogate-pair-byte-sequence" id="ref-for-surrogate-pair-byte-sequence①">Surrogate pair byte sequences</a> are <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed⑦">ill-formed</a> in <a data-link-type="dfn" href="#wtf-8" id="ref-for-wtf-8⑧">WTF-8</a>.
</ul>
</div>
<p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="replacement-character">replacement character</dfn> is the <a data-link-type="dfn" href="#code-point" id="ref-for-code-point①①">code point</a> U+FFFD <code>REPLACEMENT CHARACTER</code> (�).
It is used as a substitute to replace <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed⑧">ill-formed</a> sub-sequences
during a conversion.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="16-bit-code-unit">16-bit code unit</dfn> is a 16-bit integer used in <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16①①">UTF-16</a>.
It is noted with a “0x” prefix and four hexadecimal digits:
the first and last 16-bit code units are 0x0000 and 0xFFFF.</p>
<p class="note" role="note"><span>Note:</span> The byte serialization or memory representation of a <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit⑤">16-bit code unit</a> (little-endian or big-endian)
is out of scope for this specification.</p>
<p>When an algorithm iterates over a sequence (“For every <var>i</var> in …”), <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="consume" data-noexport="" id="consume">consuming</dfn> the next item means advancing in the sequence
such that that item will be skipped during the following iteration of the loop:
the item after the next becomes the next item.</p>
<div class="example" id="example-1815b2e1">
<a class="self-link" href="#example-1815b2e1"></a>
<p>The following algorithm prints “1”, “2”, and “4”.</p>
<p>For every digit <var>i</var> in “1234”, run these substeps:</p>
<ol>
<li>Print <var>i</var>
<li>If <var>i</var> is 2, <a data-link-type="dfn" href="#consume" id="ref-for-consume">consume</a> the next digit.
</ol>
</div>
<h3 class="heading settled" data-level="3.1" id="surrogates-code-points"><span class="secno">3.1. </span><span class="content"> Surrogate code points</span><a class="self-link" href="#surrogates-code-points"></a></h3>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="lead-surrogate-code-point">lead surrogate code point</dfn> or <dfn data-dfn-type="dfn" data-noexport="" id="high-surrogate-code-point">high surrogate code point<a class="self-link" href="#high-surrogate-code-point"></a></dfn> is a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point①②">code point</a> in the range from U+D800 to U+DBFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="trail-surrogate-code-point">trail surrogate code point</dfn> or <dfn data-dfn-type="dfn" data-noexport="" id="low-surrogate-code-point">low surrogate code point<a class="self-link" href="#low-surrogate-code-point"></a></dfn> is a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point①③">code point</a> in the range from U+DC00 to U+DFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="surrogate-code-point">surrogate code point</dfn> is
either a <a data-link-type="dfn" href="#lead-surrogate-code-point" id="ref-for-lead-surrogate-code-point">lead surrogate code point</a> or a <a data-link-type="dfn" href="#trail-surrogate-code-point" id="ref-for-trail-surrogate-code-point">trail surrogate code point</a>.
That is, a <a data-link-type="dfn" href="#code-point" id="ref-for-code-point①④">code point</a> in the range from U+D800 to U+DFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="surrogate-code-point-pair">surrogate code point pair</dfn> is a sequence of
a <a data-link-type="dfn" href="#lead-surrogate-code-point" id="ref-for-lead-surrogate-code-point①">lead surrogate code point</a> followed by a <a data-link-type="dfn" href="#trail-surrogate-code-point" id="ref-for-trail-surrogate-code-point①">trail surrogate code point</a>.</p>
<p>An <dfn data-dfn-type="dfn" data-noexport="" id="unpaired-surrogate-code-point">unpaired surrogate code point<a class="self-link" href="#unpaired-surrogate-code-point"></a></dfn> is a <a data-link-type="dfn" href="#surrogate-code-point" id="ref-for-surrogate-code-point③">surrogate code point</a> that is not part of a <a data-link-type="dfn" href="#surrogate-code-point-pair" id="ref-for-surrogate-code-point-pair②">surrogate code point pair</a>.</p>
<h3 class="heading settled" data-level="3.2" id="surrogates-code-units"><span class="secno">3.2. </span><span class="content"> Surrogate 16-bit code units</span><a class="self-link" href="#surrogates-code-units"></a></h3>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="lead-surrogate-16-bit-code-unit">lead surrogate 16-bit code unit</dfn> or <dfn data-dfn-type="dfn" data-noexport="" id="high-surrogate-16-bit-code-unit">high surrogate 16-bit code unit<a class="self-link" href="#high-surrogate-16-bit-code-unit"></a></dfn> is a <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit⑥">16-bit code unit</a> in the range from 0xD800 to 0xDBFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="trail-surrogate-16-bit-code-unit">trail surrogate 16-bit code unit</dfn> or <dfn data-dfn-type="dfn" data-noexport="" id="low-surrogate-16-bit-code-unit">low surrogate 16-bit code unit<a class="self-link" href="#low-surrogate-16-bit-code-unit"></a></dfn> is a <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit⑦">16-bit code unit</a> in the range from 0xDC00 to 0xDFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="surrogate-16-bit-code-unit">surrogate 16-bit code unit</dfn> is
either a <a data-link-type="dfn" href="#lead-surrogate-16-bit-code-unit" id="ref-for-lead-surrogate-16-bit-code-unit">lead surrogate 16-bit code unit</a> or a <a data-link-type="dfn" href="#trail-surrogate-16-bit-code-unit" id="ref-for-trail-surrogate-16-bit-code-unit">trail surrogate 16-bit code unit</a>.
That is, a <a data-link-type="dfn" href="#16-bit-code-unit" id="ref-for-16-bit-code-unit⑧">16-bit code unit</a> in the range from 0xD800 to 0xDFFF.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="surrogate-16-bit-code-unit-pair">surrogate 16-bit code unit pair</dfn> is a sequence of
a <a data-link-type="dfn" href="#lead-surrogate-16-bit-code-unit" id="ref-for-lead-surrogate-16-bit-code-unit①">lead surrogate 16-bit code unit</a> followed by a <a data-link-type="dfn" href="#trail-surrogate-16-bit-code-unit" id="ref-for-trail-surrogate-16-bit-code-unit①">trail surrogate 16-bit code unit</a>.
In <a data-link-type="dfn" href="#utf-16" id="ref-for-utf-16①②">UTF-16</a>, it represents a <a data-link-type="dfn" href="#supplementary-code-point" id="ref-for-supplementary-code-point⑤">supplementary code point</a>.</p>
<p>An <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="unpaired-surrogate-16-bit-code-unit">unpaired surrogate 16-bit code unit</dfn> is a <a data-link-type="dfn" href="#surrogate-16-bit-code-unit" id="ref-for-surrogate-16-bit-code-unit">surrogate 16-bit code unit</a> that is not part of a <a data-link-type="dfn" href="#surrogate-16-bit-code-unit-pair" id="ref-for-surrogate-16-bit-code-unit-pair③">surrogate 16-bit code unit pair</a>.</p>
<h3 class="heading settled" data-level="3.3" id="surrogates-byte-sequences"><span class="secno">3.3. </span><span class="content"> Surrogate byte sequences</span><a class="self-link" href="#surrogates-byte-sequences"></a></h3>
<p class="note" role="note"><span>Note:</span> A <a data-link-type="dfn" href="#surrogate-byte-sequence" id="ref-for-surrogate-byte-sequence②">surrogate byte sequence</a> (and therefore any byte sequence described in this section)
is <a data-link-type="dfn" href="#ill-formed" id="ref-for-ill-formed⑨">ill-formed</a> in <a data-link-type="dfn" href="#utf-8" id="ref-for-utf-8①①">UTF-8</a>.
Decoders are required to treat it as an error.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="lead-surrogate-byte-sequence">lead surrogate byte sequence</dfn> or <dfn data-dfn-type="dfn" data-noexport="" id="high-surrogate-byte-sequence">high surrogate byte sequence<a class="self-link" href="#high-surrogate-byte-sequence"></a></dfn> is a sequence of three bytes
that represents a <a data-link-type="dfn" href="#lead-surrogate-code-point" id="ref-for-lead-surrogate-code-point②">lead surrogate code point</a> in <a data-link-type="dfn" href="#generalized-utf-8" id="ref-for-generalized-utf-8">generalized UTF-8</a>.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="trail-surrogate-byte-sequence">trail surrogate byte sequence</dfn> or <dfn data-dfn-type="dfn" data-noexport="" id="low-surrogate-byte-sequence">low surrogate byte sequence<a class="self-link" href="#low-surrogate-byte-sequence"></a></dfn> is a sequence of three bytes
that represents a <a data-link-type="dfn" href="#trail-surrogate-code-point" id="ref-for-trail-surrogate-code-point②">trail surrogate code point</a> in <a data-link-type="dfn" href="#generalized-utf-8" id="ref-for-generalized-utf-8①">generalized UTF-8</a>.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="surrogate-byte-sequence">surrogate byte sequence</dfn> is
either a <a data-link-type="dfn" href="#lead-surrogate-byte-sequence" id="ref-for-lead-surrogate-byte-sequence">lead surrogate byte sequence</a> or a <a data-link-type="dfn" href="#trail-surrogate-byte-sequence" id="ref-for-trail-surrogate-byte-sequence">trail surrogate byte sequence</a>.
That is, a sequence of three bytes
that represents a <a data-link-type="dfn" href="#surrogate-code-point" id="ref-for-surrogate-code-point④">surrogate code point</a> in <a data-link-type="dfn" href="#generalized-utf-8" id="ref-for-generalized-utf-8②">generalized UTF-8</a>.</p>
<table class="data">
<caption>
<p>Table 1. Surrogate byte sequences</p>
<p>Bytes noted in hexadecimal.</p>
</caption>
<tbody>
<tr>
<th>
<th>First byte
<th>Second byte
<th>Third byte
<tr>
<th><a data-link-type="dfn" href="#lead-surrogate-byte-sequence" id="ref-for-lead-surrogate-byte-sequence①">Lead surrogate byte sequence</a>
<td>ED
<td>A0 to AF
<td>80 to BF
<tr>
<th><a data-link-type="dfn" href="#trail-surrogate-byte-sequence" id="ref-for-trail-surrogate-byte-sequence①">Trail surrogate byte sequence</a>
<td>ED