/
507.txt
240 lines (189 loc) · 5.52 KB
/
507.txt
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
[SEE[ [[ISO/IEC 2022]] ]]
* ISO/IEC 2022 Decoder
[1] A [DFN[state]] is:
[FIG(list members)[
: [F[C0 designated]] : [[C0 set]].
Initially, the [[initial C0 set]].
: [F[2/0 designated]] : [CODE(charname)@en[SP]] or [CODE(charname)@en[MSP]].
Initially, [CODE(charname)@en[SP]].
: [F[7/15 designated]] : [CODE(charname)@en[DEL]].
: [F[C1 designated]] : [[C1 set]].
Initially. the [[empty C1 set]].
: [F[10/0 designated]] : [CODE(charname)@en[MSP]] or ([I[unassigned]], [[10/0]]).
Initially, ([I[unassigned]], [[10/0]]).
: [F[15/15 designated]] : ([I[unassigned]], [[15/15]]).
: [F[decoder state]] : One of [[decoder states][decoder state]].
Initially, [[initial state]].
]FIG]
[20] A [[state initialization steps]] is a set of zero or more steps
that modifies [VAR[state]]. It [MAY[MAY]] modify [VAR[state]] in these ways:
- [21] Modify values of [VAR[state]]'s
[F[C0 designated]],
[F[2/0 designated]],
[F[7/15 designated]],
[F[C1 designated]],
[F[10/0 designated]],
and/or
[F[15/15 designated]].
[4]
To [DFN[emit a [[character]]]] [VAR[char]], run these steps:
[FIG(steps)[
=
[5]
[[Append][append]]
[VAR[char]]
to
[VAR[output stream]].
]FIG]
@@
[VAR[input stream]],
[VAR[initialization steps]] a [[state initialization steps]],
run these steps:
[FIG(steps)[
= [8] Let [VAR[state]] be a new [[state]].
= [9] Run [VAR[initialization steps]] with [VAR[state]].
= [6]
Let [VAR[output stream]] be a [[list]].
= [10]
@@
Process the input stream,
a sequence of zero or more [[bit combinations][bit combination]]
= [7]
Return [VAR[output stream]].
]FIG]
@@[DFN[reconsume]]
@@
** Decoder states
[2] There are the following [DFN[decoder states][decoder state]]:
*** Initial state
[3] The [DFN[initial state]] switches by the [[bit combination]] [VAR[bc]]:
[FIG(switch)[
: [ [N[0/0]], [N[1/15]] ] :
[FIG(steps)[
= [11] Let [VAR[set]] be [VAR[state]]'s [F[C0 designated]].
= [12] Let [VAR[char]] be [VAR[set]] [ [VAR[bc]] ].
= [29] If [VAR[char]] is [CODE(charname)@en[ESC]]:
== [30]
Set [VAR[state]]'s [F[decoder state]] to [[escape state]].
= [31] Otherwise:
== [13] [[Emit a character][emit a character]] [VAR[char]].
]FIG]
: [N[2/0]] :
[[Emit a character][emit a character]] [VAR[state]]'s [F[2/0 designated]].
: [N[7/15]] :
[[Emit a character][emit a character]] [VAR[state]]'s [F[7/15 designated]].
: [ [N[8/0]], [N[9/15]] ] :
[FIG(steps)[
= [26] Let [VAR[set]] be [VAR[state]]'s [F[C1 designated]].
= [27] Let [VAR[char]] be [VAR[set]] [ [VAR[bc]] ].
= [28] [[Emit a character][emit a character]] [VAR[char]].
]FIG]
: [N[10/0]] :
[[Emit a character][emit a character]] [VAR[state]]'s [F[10/0 designated]].
: [N[15/15]] :
[[Emit a character][emit a character]] [VAR[state]]'s [F[15/15 designated]].
: Otherwise :
@@
]FIG]
*** Escape state
[32] The [DFN[escape state]] switches by the [[bit combination]] [VAR[bc]]:
[FIG(switch)[
:[ [N[2/0]], [N[2/15]] ]:
@@
:[ [N[4/0]], [N[5/15]] ]:
[FIG(steps)[
= [36] Let [VAR[set]] be [VAR[state]]'s [F[C1 designated]].
= [37] Let [VAR[char]] be [VAR[set]] [ [VAR[bc]] + 0x40 ].
= [38] [[Emit a character][emit a character]] [VAR[char]].
= [39] Set [VAR[state]]'s [F[decoder state]] to [I[initial state]].
]FIG]
:[ [N[3/0]], [N[3/15]] ], [ [N[6/0]], [N[7/15]] ]:
[FIG(steps)[
= [35] [[Emit a character][emit a character]]
([VAR[escape]], [VAR[bc]]).
= [40] Set [VAR[state]]'s [F[decoder state]] to [I[initial state]].
]FIG]
: Otherwise :
[FIG(steps)[
= [33] Set [VAR[state]]'s [F[decoder state]] to [I[initial state]].
= [34] [[Reconsume][reconsume]] [VAR[bc]].
]FIG]
]FIG]
* Definitions
[14]
This document depends on the [CITE[Infra Standard]].
[15]
The terms
[[byte]],
[[byte sequence]],
[[tuple]],
[[list]],
[[append]],
[[ordered map]],
[[entry]],
[[key]],
and
[[value]]
are defined by the [CITE[Infra Standard]].
[16]
A [DFN[bit combination]] is a [[byte]].
A [[bit combination]] is represented as "[VAR[X]]/[VAR[Y]]",
where [VAR[X]] and [VAR[Y]] are integers in [ [N[0]], [N[15]] ],
which represents a [[byte]] [VAR[X]] × [N[16]] + [VAR[Y]].
[18]
A [DFN[character]] is one of followings:
- [CODE(charname)@en[ESC]]
- [CODE(charname)@en[SP]]
- [CODE(charname)@en[MSP]]
- [CODE(charname)@en[DEL]]
- [[tuple]] ([I[escape]], [VAR[bc]]), where [VAR[bc]] is a [[bit combination]]
- [[tuple]] ([I[unassigned]], [VAR[bc]]), where [VAR[bc]] is a [[bit combination]]
[17]
A [DFN[character set]] is an [[ordered map]],
where [[keys][key]] are [[byte sequences][byte sequence]] and
[[values][value]] are a [[character]].
[22]
A [DFN[C0 set]] is a [[character set]] whose [[keys][key]]
are «
[[0/0]],
[[0/1]],
...,
[[1/15]]
».
[19]
The [DFN[initial C0 set]] is a [[C0 set]]
«[
[[0/0]] → ([I[unassigned]], [[0/0]]),
[[0/1]] → ([I[unassigned]], [[0/1]]),
...,
[[1/10]] → ([I[unassigned]], [[1/10]]),
[[1/11]] → [CODE(charname)@en[ESC]],
[[1/12]] → ([I[unassigned]], [[1/12]]),
...,
[[1/15]] → ([I[unassigned]], [[1/15]])
]».
[25]
The [DFN[empty C0 set]] is a [[C0 set]]
«[
[[0/0]] → ([I[unassigned]], [[0/0]]),
[[0/1]] → ([I[unassigned]], [[0/1]]),
...,
[[1/15]] → ([I[unassigned]], [[1/15]])
]».
[23]
A [DFN[C1 set]] is a [[character set]] whose [[keys][key]]
are «
[[8/0]],
[[0/1]],
...,
[[9/15]]
».
[24]
The [DFN[empty C1 set]] is a [[C1 set]]
«[
[[8/0]] → ([I[unassigned]], [[8/0]]),
[[8/1]] → ([I[unassigned]], [[8/1]]),
...,
[[9/15]] → ([I[unassigned]], [[9/15]])
]».
* Notes