File: escape.c

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (236 lines) | stat: -rw-r--r-- 8,852 bytes parent folder | download
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
/* autogenerated. */
/* src="transcode-tblgen.rb", len=30823, checksum=59589 */
/* src="escape.trans", len=2009, checksum=24965 */

#include "transcode_data.h"



static const unsigned char
escape_byte_array[1062] = {
#define from__to_amp_escape_offsets 0
0, 255,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  1,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,

#define str1_amp makeSTR1(258)
    makeSTR1LEN(5), 0x26, 0x61, 0x6D, 0x70, 0x3B,

#define from__to_xml_text_escape_offsets 264
0, 255,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  1,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  2,  0,  3,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,

#define str1_lt makeSTR1(522)
    makeSTR1LEN(4), 0x26, 0x6C, 0x74, 0x3B,

#define str1_gt makeSTR1(527)
    makeSTR1LEN(4), 0x26, 0x67, 0x74, 0x3B,

#define from__to_xml_attr_content_escape_offsets 532
0, 255,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  1,  0,  0,  0,  2,  3,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  4,  0,  5,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,

#define str1_quot makeSTR1(790)
    makeSTR1LEN(6), 0x26, 0x71, 0x75, 0x6F, 0x74, 0x3B,

#define str1_apos makeSTR1(797)
    makeSTR1LEN(6), 0x26, 0x61, 0x70, 0x6F, 0x73, 0x3B,

#define escape_xml_attr_quote_offsets 804
0, 255,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,

};
static const unsigned int
escape_word_array[21] = {
#define from__to_amp_escape_infos WORDINDEX2INFO(0)
        NOMAP, str1_amp,

#define from__to_amp_escape WORDINDEX2INFO(2)
    from__to_amp_escape_offsets,
    from__to_amp_escape_infos,

#define from__to_xml_text_escape_infos WORDINDEX2INFO(4)
        NOMAP, str1_amp,  str1_lt,  str1_gt,

#define from__to_xml_text_escape WORDINDEX2INFO(8)
    from__to_xml_text_escape_offsets,
    from__to_xml_text_escape_infos,

#define from__to_xml_attr_content_escape_infos WORDINDEX2INFO(10)
         NOMAP, str1_quot,  str1_amp, str1_apos,
       str1_lt,   str1_gt,

#define from__to_xml_attr_content_escape WORDINDEX2INFO(16)
    from__to_xml_attr_content_escape_offsets,
    from__to_xml_attr_content_escape_infos,

#define escape_xml_attr_quote_infos WORDINDEX2INFO(18)
     FUNso,

#define escape_xml_attr_quote WORDINDEX2INFO(19)
    escape_xml_attr_quote_offsets,
    escape_xml_attr_quote_infos,

};
#define TRANSCODE_TABLE_INFO escape_byte_array, 1062, escape_word_array, 21, ((int)sizeof(unsigned int))
static const rb_transcoder
rb_from__to_amp_escape = {
    "", "amp_escape", from__to_amp_escape,
    TRANSCODE_TABLE_INFO,
    1, /* input_unit_length */
    1, /* max_input */
    5, /* max_output */
    asciicompat_converter, /* asciicompat_type */
    0, 0, 0, /* state_size, state_init, state_fini */
    0, 0, 0, 0,
    0, 0, 0
};
static const rb_transcoder
rb_from__to_xml_text_escape = {
    "", "xml_text_escape", from__to_xml_text_escape,
    TRANSCODE_TABLE_INFO,
    1, /* input_unit_length */
    1, /* max_input */
    5, /* max_output */
    asciicompat_converter, /* asciicompat_type */
    0, 0, 0, /* state_size, state_init, state_fini */
    0, 0, 0, 0,
    0, 0, 0
};
static const rb_transcoder
rb_from__to_xml_attr_content_escape = {
    "", "xml_attr_content_escape", from__to_xml_attr_content_escape,
    TRANSCODE_TABLE_INFO,
    1, /* input_unit_length */
    1, /* max_input */
    6, /* max_output */
    asciicompat_converter, /* asciicompat_type */
    0, 0, 0, /* state_size, state_init, state_fini */
    0, 0, 0, 0,
    0, 0, 0
};


#define END 0
#define NORMAL  1

static int
escape_xml_attr_quote_init(void *statep)
{
    unsigned char *sp = statep;
    *sp = END;
    return 0;
}

static ssize_t
fun_so_escape_xml_attr_quote(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
{
    unsigned char *sp = statep;
    int n = 0;
    if (*sp == END) {
        *sp = NORMAL;
        o[n++] = '"';
    }
    o[n++] = s[0];
    return n;
}

static ssize_t
escape_xml_attr_quote_finish(void *statep, unsigned char *o, size_t osize)
{
    unsigned char *sp = statep;
    int n = 0;

    if (*sp == END) {
        o[n++] = '"';
    }

    o[n++] = '"';
    *sp = END;

    return n;
}

static const rb_transcoder
rb_escape_xml_attr_quote = {
    "", "xml_attr_quote", escape_xml_attr_quote,
    TRANSCODE_TABLE_INFO,
    1, /* input_unit_length */
    1, /* max_input */
    7, /* max_output */
    asciicompat_encoder, /* asciicompat_type */
    1, escape_xml_attr_quote_init, escape_xml_attr_quote_init,
    NULL, NULL, NULL, fun_so_escape_xml_attr_quote,
    escape_xml_attr_quote_finish
};

TRANS_INIT(escape)
{
    rb_register_transcoder(&rb_from__to_amp_escape);
    rb_register_transcoder(&rb_from__to_xml_text_escape);
    rb_register_transcoder(&rb_from__to_xml_attr_content_escape);

    rb_register_transcoder(&rb_escape_xml_attr_quote);
}