Coverage Report

Created: 2026-04-01 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xmlProtoConverter.cpp
Line
Count
Source
1
/*
2
 * Copyright (C) 2019 Google Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include "xmlProtoConverter.h"
18
19
#include <algorithm>
20
21
using namespace std;
22
using namespace xmlProtoFuzzer;
23
24
string ProtoConverter::removeNonAscii(string const& _utf8)
25
723k
{
26
723k
  string asciiStr{_utf8};
27
17.5M
  asciiStr.erase(remove_if(asciiStr.begin(), asciiStr.end(), [=](char c) -> bool {
28
17.5M
                        return !(std::isalpha(c) || std::isdigit(c));
29
17.5M
                }), asciiStr.end());
30
723k
  return asciiStr.empty() ? "fuzz" : asciiStr;
31
723k
}
32
33
34
void ProtoConverter::visit(Misc const& _x)
35
3.84k
{
36
3.84k
  switch (_x.misc_oneof_case())
37
3.84k
  {
38
1.66k
  case Misc::kComment:
39
1.66k
    m_output << "<!--" << _x.comment() << "-->\n";
40
1.66k
    break;
41
1.24k
  case Misc::kInst:
42
1.24k
    visit(_x.inst());
43
1.24k
    break;
44
939
  case Misc::MISC_ONEOF_NOT_SET:
45
939
    break;
46
3.84k
  }
47
3.84k
}
48
49
void ProtoConverter::visit(Prolog const& _x)
50
7.56k
{
51
7.56k
  visit(_x.decl());
52
7.56k
  visit(_x.doctype());
53
7.56k
  for (auto const& misc: _x.misc())
54
2.35k
    visit(misc);
55
7.56k
}
56
57
void ProtoConverter::visit(KeyValue const& _x)
58
18.8k
{
59
18.8k
  if (!KeyValue::XmlNamespace_IsValid(_x.type()))
60
248
    return;
61
62
18.6k
  switch (_x.type())
63
18.6k
  {
64
5.27k
  case KeyValue::ATTRIBUTES:
65
5.27k
    m_output << "xml:attributes=\"" << removeNonAscii(_x.value()) << "\" ";
66
5.27k
    break;
67
1.37k
  case KeyValue::BASE:
68
1.37k
    m_output << "xml:base=\"" << removeNonAscii(_x.value()) << "\" ";
69
1.37k
    break;
70
1.09k
  case KeyValue::CATALOG:
71
1.09k
    m_output << "xml:catalog=\"" << removeNonAscii(_x.value()) << "\" ";
72
1.09k
    break;
73
1.61k
  case KeyValue::ID:
74
1.61k
    m_output << "xml:id=\"" << removeNonAscii(_x.value()) << "\" ";
75
1.61k
    break;
76
538
  case KeyValue::LANG:
77
538
    m_output << "xml:lang=\"" << removeNonAscii(_x.value()) << "\" ";
78
538
    break;
79
349
  case KeyValue::LINK:
80
349
    m_output << "xml:link=\"" << removeNonAscii(_x.value()) << "\" ";
81
349
    break;
82
754
  case KeyValue::SPACE:
83
754
    m_output << "xml:space=\"" << removeNonAscii(_x.value()) << "\" ";
84
754
    break;
85
549
  case KeyValue::SPECIAL:
86
549
    m_output << "xml:special=\"" << removeNonAscii(_x.value()) << "\" ";
87
549
    break;
88
1.24k
  case KeyValue::TEST:
89
1.24k
    m_output << "xml:test=\"" << removeNonAscii(_x.value()) << "\" ";
90
1.24k
    break;
91
5.87k
  case KeyValue::FUZZ:
92
5.87k
    if (_x.ByteSizeLong() % 2)
93
1.45k
      m_output << "xmlns:" << removeNonAscii(_x.key()) << "=\"" << removeNonAscii(_x.value()) << "\" ";
94
4.42k
    else
95
4.42k
      m_output << removeNonAscii(_x.key()) << "=\"" << removeNonAscii(_x.value()) << "\" ";
96
5.87k
    break;
97
0
  case KeyValue_XmlNamespace_KeyValue_XmlNamespace_INT_MIN_SENTINEL_DO_NOT_USE_:
98
0
  case KeyValue_XmlNamespace_KeyValue_XmlNamespace_INT_MAX_SENTINEL_DO_NOT_USE_:
99
0
    break;
100
18.6k
  }
101
18.6k
}
102
103
void ProtoConverter::visit(ProcessingInstruction const& _x)
104
1.24k
{
105
1.24k
  m_output << "<?" << removeNonAscii(_x.name()) << " ";
106
1.24k
  for (auto const& prop: _x.kv())
107
1.30k
    visit(prop);
108
1.24k
  m_output << "?>\n";
109
1.24k
}
110
111
void ProtoConverter::visit(Content const& _x)
112
138k
{
113
138k
  switch (_x.content_oneof_case())
114
138k
  {
115
2.29k
  case Content::kStr:
116
2.29k
    m_output << _x.str() << "\n";
117
2.29k
    break;
118
1.93k
  case Content::kE:
119
1.93k
    visit(_x.e());
120
1.93k
    m_output << "\n";
121
1.93k
    break;
122
2.24k
  case Content::kC:
123
2.24k
    visit(_x.c());
124
2.24k
    m_output << "\n";
125
2.24k
    break;
126
131k
  case Content::CONTENT_ONEOF_NOT_SET:
127
131k
    break;
128
138k
  }
129
138k
}
130
131
void ProtoConverter::visit(ElementDecl const& _x)
132
4.93k
{
133
4.93k
  if (!ElementDecl::ContentSpec_IsValid(_x.spec()))
134
302
    return;
135
136
4.63k
  m_output << "<!ELEMENT " << _x.name() << " ";
137
4.63k
  switch (_x.spec())
138
4.63k
  {
139
2.27k
  case ElementDecl::EMPTY:
140
2.27k
    m_output << "EMPTY>";
141
2.27k
    break;
142
190
  case ElementDecl::ANY:
143
190
    m_output << "ANY>";
144
190
    break;
145
223
  case ElementDecl::FUZZ:
146
223
    m_output << "FUZZ>";
147
223
    break;
148
1.08k
  case ElementDecl::MIXED:
149
1.08k
    m_output << "(#PCDATA";
150
1.08k
    for (auto const& pcdata: _x.cdata())
151
2.14k
      m_output << "|" << pcdata;
152
1.08k
    m_output << ")";
153
1.08k
    if (_x.cdata_size() > 0)
154
814
      m_output << "*";
155
1.08k
    m_output << ">";
156
1.08k
    break;
157
865
  case ElementDecl::CHILDREN:
158
865
  {
159
865
    m_output << "(";
160
865
    string delim = "";
161
1.97k
    for (auto const& str: _x.cdata()) {
162
1.97k
      m_output << delim << removeNonAscii(str);
163
1.97k
      delim = ", ";
164
1.97k
    }
165
865
    m_output << ")>";
166
865
    break;
167
0
  }
168
0
  case ElementDecl_ContentSpec_ElementDecl_ContentSpec_INT_MIN_SENTINEL_DO_NOT_USE_:
169
0
  case ElementDecl_ContentSpec_ElementDecl_ContentSpec_INT_MAX_SENTINEL_DO_NOT_USE_:
170
0
    break;
171
4.63k
  }
172
4.63k
}
173
174
void ProtoConverter::visit(AttValue const& _x)
175
4.18k
{
176
4.18k
  if (!isValid(_x))
177
117
    return;
178
179
4.06k
  m_output << "\"";
180
4.06k
  string prefix;
181
4.06k
  switch (_x.type())
182
4.06k
  {
183
2.41k
  case AttValue::ENTITY:
184
2.41k
    prefix = "&";
185
2.41k
    break;
186
1.16k
  case AttValue::CHAR:
187
1.16k
    if (_x.ByteSizeLong() % 2)
188
138
      prefix = "&#";
189
1.02k
    else
190
      // TODO: Value that follows this must be a
191
      // sequence of hex digits.
192
1.02k
      prefix = "&#x";
193
1.16k
    break;
194
491
  case AttValue::FUZZ:
195
491
    prefix = "fuzz";
196
491
    break;
197
0
  case AttValue_Type_AttValue_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
198
0
  case AttValue_Type_AttValue_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
199
0
    break;
200
4.06k
  }
201
4.06k
  for (auto const& name: _x.value())
202
6.29k
    m_output << prefix << removeNonAscii(name) << ";";
203
4.06k
  m_output << "\"";
204
4.06k
}
205
206
void ProtoConverter::visit(DefaultDecl const& _x)
207
18.4k
{
208
18.4k
  if (!isValid(_x))
209
147
    return;
210
211
18.2k
  switch (_x.type())
212
18.2k
  {
213
13.2k
  case DefaultDecl::REQUIRED:
214
13.2k
    m_output << "#REQUIRED";
215
13.2k
    break;
216
489
  case DefaultDecl::IMPLIED:
217
489
    m_output << "#IMPLIED";
218
489
    break;
219
4.18k
  case DefaultDecl::FIXED:
220
4.18k
    m_output << "#FIXED ";
221
4.18k
    visit(_x.att());
222
4.18k
    break;
223
383
  case DefaultDecl::FUZZ:
224
383
    m_output << "#FUZZ";
225
383
    break;
226
0
  case DefaultDecl_Type_DefaultDecl_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
227
0
  case DefaultDecl_Type_DefaultDecl_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
228
0
    break;
229
18.2k
  }
230
18.2k
}
231
232
void ProtoConverter::visit(AttDef const& _x)
233
18.4k
{
234
18.4k
  if (!isValid(_x))
235
66
    return;
236
237
18.4k
  m_output << " " << removeNonAscii(_x.name()) << " ";
238
18.4k
  switch (_x.type())
239
18.4k
  {
240
10.5k
  case AttDef::CDATA:
241
10.5k
    m_output << "CDATA ";
242
10.5k
    break;
243
1.70k
  case AttDef::ID:
244
1.70k
    m_output << "ID ";
245
1.70k
    break;
246
3.12k
  case AttDef::IDREF:
247
3.12k
    m_output << "IDREF ";
248
3.12k
    break;
249
761
  case AttDef::IDREFS:
250
761
    m_output << "IDREFS ";
251
761
    break;
252
685
  case AttDef::ENTITY:
253
685
    m_output << "ENTITY ";
254
685
    break;
255
336
  case AttDef::ENTITIES:
256
336
    m_output << "ENTITIES ";
257
336
    break;
258
468
  case AttDef::NMTOKEN:
259
468
    m_output << "NMTOKEN ";
260
468
    break;
261
607
  case AttDef::NMTOKENS:
262
607
    m_output << "NMTOKENS ";
263
607
    break;
264
156
  case AttDef::FUZZ:
265
156
    m_output << "FUZZ ";
266
156
    break;
267
0
  case AttDef_Type_AttDef_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
268
0
  case AttDef_Type_AttDef_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
269
0
    break;
270
18.4k
  }
271
18.4k
  visit(_x.def());
272
18.4k
}
273
274
void ProtoConverter::visit(AttListDecl const& _x)
275
4.01k
{
276
4.01k
  m_output << "<!ATTLIST " << removeNonAscii(_x.name());
277
4.01k
  for (auto const& att: _x.attdefs())
278
18.4k
    visit(att);
279
4.01k
  m_output << ">";
280
4.01k
}
281
282
void ProtoConverter::visit(NotationDecl const& _x)
283
4.21k
{
284
4.21k
  m_output << "<!NOTATION " << removeNonAscii(_x.name()) << " ";
285
4.21k
  switch (_x.notation_oneof_case())
286
4.21k
  {
287
1.06k
  case NotationDecl::kExt:
288
1.06k
    visit(_x.ext());
289
1.06k
    break;
290
2.18k
  case NotationDecl::kPub:
291
2.18k
    m_output << "PUBLIC " << _x.pub();
292
2.18k
    break;
293
237
  case NotationDecl::kFuzz:
294
237
    m_output << "FUZZ " << _x.fuzz();
295
237
    break;
296
727
  case NotationDecl::NOTATION_ONEOF_NOT_SET:
297
727
    break;
298
4.21k
  }
299
4.21k
  m_output << ">";
300
4.21k
}
301
302
void ProtoConverter::visit(NDataDecl const& _x)
303
2.70k
{
304
2.70k
  m_output << " NDATA " << _x.name();
305
2.70k
}
306
307
void ProtoConverter::visit(EntityDef const& _x)
308
7.71k
{
309
7.71k
  switch (_x.entity_oneof_case())
310
7.71k
  {
311
3.53k
  case EntityDef::kExt:
312
3.53k
    visit(_x.ext());
313
3.53k
    if (_x.ByteSizeLong() % 2)
314
2.70k
      visit(_x.ndata());
315
3.53k
    break;
316
2.16k
  case EntityDef::kVal:
317
2.16k
    visit(_x.val());
318
2.16k
    break;
319
2.01k
  case EntityDef::ENTITY_ONEOF_NOT_SET:
320
2.01k
    break;
321
7.71k
  }
322
7.71k
}
323
324
void ProtoConverter::visit(PEDef const& _x)
325
3.74k
{
326
3.74k
  switch (_x.pedef_oneof_case())
327
3.74k
  {
328
1.51k
  case PEDef::kVal:
329
1.51k
    visit(_x.val());
330
1.51k
    break;
331
1.16k
  case PEDef::kId:
332
1.16k
    visit(_x.id());
333
1.16k
    break;
334
1.06k
  case PEDef::PEDEF_ONEOF_NOT_SET:
335
1.06k
    break;
336
3.74k
  }
337
3.74k
}
338
339
void ProtoConverter::visit(EntityValue const& _x)
340
3.68k
{
341
3.68k
  if (!isValid(_x))
342
97
    return;
343
344
3.58k
  m_output << "\"";
345
3.58k
  string prefix;
346
3.58k
  switch (_x.type())
347
3.58k
  {
348
1.73k
  case EntityValue::ENTITY:
349
1.73k
    prefix = "&";
350
1.73k
    break;
351
1.33k
  case EntityValue::CHAR:
352
1.33k
    if (_x.ByteSizeLong() % 2)
353
883
      prefix = "&#";
354
452
    else
355
452
      prefix = "&#x";
356
1.33k
    break;
357
90
  case EntityValue::PEREF:
358
90
    prefix = "%";
359
90
    break;
360
429
  case EntityValue::FUZZ:
361
429
    prefix = "fuzz";
362
429
    break;
363
0
  case EntityValue_Type_EntityValue_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
364
0
  case EntityValue_Type_EntityValue_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
365
0
    break;
366
3.58k
  }
367
3.58k
  for (auto const& ref: _x.name())
368
7.87k
    m_output << prefix << ref << ";";
369
3.58k
  m_output << "\"";
370
3.58k
}
371
372
void ProtoConverter::visit(EntityDecl const& _x)
373
11.5k
{
374
11.5k
  if (!isValid(_x))
375
86
    return;
376
377
11.4k
  m_output << "<!ENTITY ";
378
11.4k
  switch (_x.type())
379
11.4k
  {
380
7.71k
  case EntityDecl::GEDECL:
381
7.71k
    m_output << _x.name() << " ";
382
7.71k
    visit(_x.ent());
383
7.71k
    break;
384
3.74k
  case EntityDecl::PEDECL:
385
3.74k
    m_output << "% " << _x.name() << " ";
386
3.74k
    visit(_x.pedef());
387
3.74k
    break;
388
0
  case EntityDecl_Type_EntityDecl_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
389
0
  case EntityDecl_Type_EntityDecl_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
390
0
    break;
391
11.4k
  }
392
11.4k
  m_output << ">";
393
11.4k
}
394
395
void ProtoConverter::visit(ConditionalSect const& _x)
396
7.90k
{
397
7.90k
  if (!isValid(_x))
398
70
    return;
399
400
7.83k
  switch (_x.type())
401
7.83k
  {
402
5.61k
  case ConditionalSect::INCLUDE:
403
5.61k
    m_output << "<![ INCLUDE [";
404
5.61k
    visit(_x.ext());
405
5.61k
    m_output << "]]>";
406
5.61k
    break;
407
486
  case ConditionalSect::IGNORE:
408
486
    m_output << "<![ IGNORE [";
409
486
    for (auto const& str: _x.ignores())
410
895
      m_output << "<![" << removeNonAscii(str) << "]]>";
411
486
    m_output << "]]>";
412
486
    break;
413
1.73k
  case ConditionalSect::FUZZ:
414
1.73k
    m_output << "<![ FUZZ [";
415
1.73k
    visit(_x.ext());
416
1.73k
    m_output << "]]>";
417
1.73k
    break;
418
0
  case ConditionalSect_Type_ConditionalSect_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
419
0
  case ConditionalSect_Type_ConditionalSect_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
420
0
    break;
421
7.83k
  }
422
7.83k
}
423
424
425
void ProtoConverter::visit(OneExtSubsetDecl const& _x)
426
33.8k
{
427
33.8k
  switch (_x.extsubset_oneof_case())
428
33.8k
  {
429
17.5k
  case OneExtSubsetDecl::kM:
430
17.5k
    visit(_x.m());
431
17.5k
    break;
432
7.90k
  case OneExtSubsetDecl::kC:
433
7.90k
    visit(_x.c());
434
7.90k
    break;
435
8.38k
  case OneExtSubsetDecl::EXTSUBSET_ONEOF_NOT_SET:
436
8.38k
    break;
437
33.8k
  }
438
33.8k
}
439
440
441
void ProtoConverter::visit(ExtSubsetDecl const& _x)
442
11.8k
{
443
11.8k
  for (auto const& decl: _x.decls())
444
33.8k
    visit(decl);
445
11.8k
}
446
447
void ProtoConverter::visit(CData const& _x)
448
2.24k
{
449
2.24k
  m_output << "<![CDATA[" << removeNonAscii(_x.data()) << "]]>";
450
2.24k
}
451
452
void ProtoConverter::visit(MarkupDecl const& _x)
453
34.9k
{
454
34.9k
  switch (_x.markup_oneof_case())
455
34.9k
  {
456
4.93k
  case MarkupDecl::kE:
457
4.93k
    visit(_x.e());
458
4.93k
    break;
459
4.01k
  case MarkupDecl::kA:
460
4.01k
    visit(_x.a());
461
4.01k
    break;
462
4.21k
  case MarkupDecl::kN:
463
4.21k
    visit(_x.n());
464
4.21k
    break;
465
1.49k
  case MarkupDecl::kM:
466
1.49k
    visit(_x.m());
467
1.49k
    break;
468
11.5k
  case MarkupDecl::kEntity:
469
11.5k
    visit(_x.entity());
470
11.5k
    break;
471
4.45k
  case MarkupDecl::kExt:
472
4.45k
    visit(_x.ext());
473
4.45k
    break;
474
4.26k
  case MarkupDecl::MARKUP_ONEOF_NOT_SET:
475
4.26k
    break;
476
34.9k
  }
477
34.9k
}
478
479
/// Returns predefined element from an Element_Id enum
480
/// @param _x is an enum that holds the desired type of predefined value
481
/// @param _prop is a string that holds the value of the desired type
482
/// @return string holding the predefined value of the form
483
/// name attribute=\"value\"
484
string ProtoConverter::getPredefined(Element_Id _x, string const& _prop)
485
126k
{
486
126k
  string output{};
487
126k
  switch (_x)
488
126k
  {
489
117k
  case Element::XIINCLUDE:
490
119k
  case Element::XIFALLBACK:
491
121k
  case Element::XIHREF:
492
121k
    output = "xi:include href=\"fuzz.xml\"";
493
122k
  case Element::XIPARSE:
494
122k
    output = "xi:include parse=\"xml\"";
495
123k
  case Element::XIXPOINTER:
496
123k
    output = "xi:include xpointer=\"" + removeNonAscii(_prop) + "\"";
497
124k
  case Element::XIENCODING:
498
124k
    output = "xi:include encoding=\"" + removeNonAscii(_prop) + "\"";
499
126k
  case Element::XIACCEPT:
500
126k
    output = "xi:include accept=\"" + removeNonAscii(_prop) + "\"";
501
126k
  case Element::XIACCEPTLANG:
502
126k
    output = "xi:include accept-language=\"" + removeNonAscii(_prop) + "\"";
503
126k
  case Element_Id_Element_Id_INT_MIN_SENTINEL_DO_NOT_USE_:
504
126k
  case Element_Id_Element_Id_INT_MAX_SENTINEL_DO_NOT_USE_:
505
126k
    output = "xi:fuzz xifuzz=\"fuzz\"";
506
126k
  }
507
126k
  return output;
508
126k
}
509
510
/// Returns uri string for a given Element_Id type
511
string ProtoConverter::getUri(Element_Id _x)
512
126k
{
513
126k
  if (!Element::Id_IsValid(_x))
514
295
    return s_XInclude;
515
516
126k
  switch (_x)
517
126k
  {
518
117k
  case Element::XIINCLUDE:
519
119k
  case Element::XIFALLBACK:
520
121k
  case Element::XIHREF:
521
122k
  case Element::XIPARSE:
522
123k
  case Element::XIXPOINTER:
523
124k
  case Element::XIENCODING:
524
126k
  case Element::XIACCEPT:
525
126k
  case Element::XIACCEPTLANG:
526
126k
  case Element_Id_Element_Id_INT_MIN_SENTINEL_DO_NOT_USE_:
527
126k
  case Element_Id_Element_Id_INT_MAX_SENTINEL_DO_NOT_USE_:
528
126k
    return s_XInclude;
529
126k
  }
530
126k
}
531
532
void ProtoConverter::visit(Element const& _x)
533
138k
{
534
138k
  if (!isValid(_x))
535
233
    return;
536
537
  // Predefined child node
538
138k
  string child = {};
539
  // Predefined uri for child node
540
138k
  string pUri = {};
541
  // Element name
542
138k
  string name = removeNonAscii(_x.name());
543
544
138k
  switch (_x.type())
545
138k
  {
546
126k
  case Element::PREDEFINED:
547
126k
    child = getPredefined(_x.id(), _x.childprop());
548
126k
    pUri = getUri(_x.id());
549
126k
    break;
550
11.1k
  case Element::FUZZ:
551
11.1k
  case Element_Type_Element_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
552
11.1k
  case Element_Type_Element_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
553
11.1k
    break;
554
138k
  }
555
556
  // <name k1=v1 k2=v2 k3=v3>
557
  // <content>
558
  // </name>
559
560
  // Start name tag: Must be Ascii?
561
138k
  m_output << "<" << name << " ";
562
563
  // Add uri to name tag
564
138k
  if (!pUri.empty())
565
126k
    m_output << pUri << " ";
566
138k
  for (auto const& prop: _x.kv())
567
17.5k
    visit(prop);
568
138k
  m_output << ">\n";
569
570
  // Add attribute
571
138k
  if (!child.empty())
572
126k
    m_output << "<" << child << "/>\n";
573
574
  // Add content
575
138k
  visit(_x.content());
576
577
  // Close name tag
578
138k
  m_output << "</" << name << ">\n";
579
138k
}
580
581
void ProtoConverter::visit(ExternalId const& _x)
582
13.3k
{
583
13.3k
  if (!isValid(_x))
584
850
    return;
585
586
12.4k
  switch (_x.type())
587
12.4k
  {
588
9.65k
  case ExternalId::SYSTEM:
589
9.65k
    m_output << "SYSTEM " << "\"" << removeNonAscii(_x.system()) << "\"";
590
9.65k
    break;
591
814
  case ExternalId::PUBLIC:
592
814
    m_output << "PUBLIC " << "\"" << removeNonAscii(_x.pub()) << "\""
593
814
      << " " << "\"" << removeNonAscii(_x.system()) << "\"";
594
814
    break;
595
2.00k
  case ExternalId::FUZZ:
596
2.00k
    m_output << "FUZZ " << "\"" << removeNonAscii(_x.pub()) << "\"";
597
2.00k
    break;
598
0
  case ExternalId_Type_ExternalId_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
599
0
  case ExternalId_Type_ExternalId_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
600
0
    break;
601
12.4k
  }
602
12.4k
}
603
604
void ProtoConverter::visit(DocTypeDecl const& _x)
605
7.56k
{
606
7.56k
  m_output << "<!DOCTYPE " << removeNonAscii(_x.name()) << " ";
607
7.56k
  visit(_x.ext());
608
7.56k
  m_output << "[";
609
7.56k
  for (auto const& m: _x.mdecl())
610
17.3k
    visit(m);
611
7.56k
  m_output << "]";
612
7.56k
  m_output << ">\n";
613
7.56k
}
614
615
void ProtoConverter::visit(VersionNum const& _x)
616
7.56k
{
617
7.56k
  if (!isValid(_x))
618
7
    return;
619
620
7.55k
  switch (_x.type())
621
7.55k
  {
622
7.40k
  case VersionNum::STANDARD:
623
7.40k
    m_output << "\"1.0\"";
624
7.40k
    break;
625
146
  case VersionNum::FUZZ:
626
146
  case VersionNum_Type_VersionNum_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
627
146
  case VersionNum_Type_VersionNum_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
628
146
    m_output << "\"" << _x.major() << "." << _x.minor() << "\"";
629
146
    break;
630
7.55k
  }
631
7.55k
}
632
633
void ProtoConverter::visit(Encodings const& _x)
634
7.56k
{
635
7.56k
  if (!Encodings::Enc_IsValid(_x.name()))
636
595
    return;
637
638
6.96k
  m_output << " encoding=\"";
639
6.96k
  switch (_x.name())
640
6.96k
  {
641
6.12k
  case Encodings::BIG5:
642
6.12k
    m_output << "BIG5";
643
6.12k
    break;
644
10
  case Encodings::EUCJP:
645
10
    m_output << "EUC-JP";
646
10
    break;
647
35
  case Encodings::EUCKR:
648
35
    m_output << "EUC-KR";
649
35
    break;
650
20
  case Encodings::GB18030:
651
20
    m_output << "GB18030";
652
20
    break;
653
3
  case Encodings::ISO2022JP:
654
3
    m_output << "ISO-2022-JP";
655
3
    break;
656
125
  case Encodings::ISO2022KR:
657
125
    m_output << "ISO-2022-KR";
658
125
    break;
659
63
  case Encodings::ISO88591:
660
63
    m_output << "ISO-8859-1";
661
63
    break;
662
2
  case Encodings::ISO88592:
663
2
    m_output << "ISO-8859-2";
664
2
    break;
665
5
  case Encodings::ISO88593:
666
5
    m_output << "ISO-8859-3";
667
5
    break;
668
10
  case Encodings::ISO88594:
669
10
    m_output << "ISO-8859-4";
670
10
    break;
671
12
  case Encodings::ISO88595:
672
12
    m_output << "ISO-8859-5";
673
12
    break;
674
4
  case Encodings::ISO88596:
675
4
    m_output << "ISO-8859-6";
676
4
    break;
677
9
  case Encodings::ISO88597:
678
9
    m_output << "ISO-8859-7";
679
9
    break;
680
4
  case Encodings::ISO88598:
681
4
    m_output << "ISO-8859-8";
682
4
    break;
683
12
  case Encodings::ISO88599:
684
12
    m_output << "ISO-8859-9";
685
12
    break;
686
98
  case Encodings::SHIFTJIS:
687
98
    m_output << "SHIFT_JIS";
688
98
    break;
689
13
  case Encodings::TIS620:
690
13
    m_output << "TIS-620";
691
13
    break;
692
75
  case Encodings::USASCII:
693
75
    m_output << "US-ASCII";
694
75
    break;
695
83
  case Encodings::UTF8:
696
83
    m_output << "UTF-8";
697
83
    break;
698
47
  case Encodings::UTF16:
699
47
    m_output << "UTF-16";
700
47
    break;
701
24
  case Encodings::UTF16BE:
702
24
    m_output << "UTF-16BE";
703
24
    break;
704
8
  case Encodings::UTF16LE:
705
8
    m_output << "UTF-16LE";
706
8
    break;
707
35
  case Encodings::WINDOWS31J:
708
35
    m_output << "WINDOWS-31J";
709
35
    break;
710
4
  case Encodings::WINDOWS1255:
711
4
    m_output << "WINDOWS-1255";
712
4
    break;
713
7
  case Encodings::WINDOWS1256:
714
7
    m_output << "WINDOWS-1256";
715
7
    break;
716
130
  case Encodings::FUZZ:
717
130
    m_output << removeNonAscii(_x.fuzz());
718
130
    break;
719
0
  case Encodings_Enc_Encodings_Enc_INT_MIN_SENTINEL_DO_NOT_USE_:
720
0
  case Encodings_Enc_Encodings_Enc_INT_MAX_SENTINEL_DO_NOT_USE_:
721
0
    break;
722
6.96k
  }
723
6.96k
  m_output << "\"";
724
6.96k
}
725
726
void ProtoConverter::visit(XmlDeclaration const& _x)
727
7.56k
{
728
7.56k
  m_output << R"(<?xml version=)";
729
7.56k
  visit(_x.ver());
730
7.56k
  visit(_x.enc());
731
7.56k
  switch (_x.standalone())
732
7.56k
  {
733
7.19k
  case XmlDeclaration::YES:
734
7.19k
    m_output << " standalone=\'yes\'";
735
7.19k
    break;
736
312
  case XmlDeclaration::NO:
737
312
    m_output << " standalone=\'no\'";
738
312
    break;
739
0
  case XmlDeclaration_Standalone_XmlDeclaration_Standalone_INT_MIN_SENTINEL_DO_NOT_USE_:
740
0
  case XmlDeclaration_Standalone_XmlDeclaration_Standalone_INT_MAX_SENTINEL_DO_NOT_USE_:
741
58
  default:
742
58
    break;
743
7.56k
  }
744
7.56k
  m_output << "?>\n";
745
7.56k
}
746
747
void ProtoConverter::visit(XmlDocument const& _x)
748
7.56k
{
749
7.56k
  visit(_x.p());
750
7.56k
  for (auto const& element: _x.e())
751
136k
    visit(element);
752
7.56k
}
753
754
string ProtoConverter::protoToString(XmlDocument const& _x)
755
7.56k
{
756
7.56k
  visit(_x);
757
7.56k
  return m_output.str();
758
7.56k
}