Coverage Report

Created: 2025-11-16 06:28

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
778k
{
26
778k
  string asciiStr{_utf8};
27
16.7M
  asciiStr.erase(remove_if(asciiStr.begin(), asciiStr.end(), [=](char c) -> bool {
28
16.7M
                        return !(std::isalpha(c) || std::isdigit(c));
29
16.7M
                }), asciiStr.end());
30
778k
  return asciiStr.empty() ? "fuzz" : asciiStr;
31
778k
}
32
33
34
void ProtoConverter::visit(Misc const& _x)
35
4.46k
{
36
4.46k
  switch (_x.misc_oneof_case())
37
4.46k
  {
38
1.70k
  case Misc::kComment:
39
1.70k
    m_output << "<!--" << _x.comment() << "-->\n";
40
1.70k
    break;
41
1.57k
  case Misc::kInst:
42
1.57k
    visit(_x.inst());
43
1.57k
    break;
44
1.18k
  case Misc::MISC_ONEOF_NOT_SET:
45
1.18k
    break;
46
4.46k
  }
47
4.46k
}
48
49
void ProtoConverter::visit(Prolog const& _x)
50
8.13k
{
51
8.13k
  visit(_x.decl());
52
8.13k
  visit(_x.doctype());
53
8.13k
  for (auto const& misc: _x.misc())
54
2.33k
    visit(misc);
55
8.13k
}
56
57
void ProtoConverter::visit(KeyValue const& _x)
58
19.6k
{
59
19.6k
  if (!KeyValue::XmlNamespace_IsValid(_x.type()))
60
276
    return;
61
62
19.3k
  switch (_x.type())
63
19.3k
  {
64
5.13k
  case KeyValue::ATTRIBUTES:
65
5.13k
    m_output << "xml:attributes=\"" << removeNonAscii(_x.value()) << "\" ";
66
5.13k
    break;
67
1.17k
  case KeyValue::BASE:
68
1.17k
    m_output << "xml:base=\"" << removeNonAscii(_x.value()) << "\" ";
69
1.17k
    break;
70
968
  case KeyValue::CATALOG:
71
968
    m_output << "xml:catalog=\"" << removeNonAscii(_x.value()) << "\" ";
72
968
    break;
73
1.59k
  case KeyValue::ID:
74
1.59k
    m_output << "xml:id=\"" << removeNonAscii(_x.value()) << "\" ";
75
1.59k
    break;
76
565
  case KeyValue::LANG:
77
565
    m_output << "xml:lang=\"" << removeNonAscii(_x.value()) << "\" ";
78
565
    break;
79
555
  case KeyValue::LINK:
80
555
    m_output << "xml:link=\"" << removeNonAscii(_x.value()) << "\" ";
81
555
    break;
82
651
  case KeyValue::SPACE:
83
651
    m_output << "xml:space=\"" << removeNonAscii(_x.value()) << "\" ";
84
651
    break;
85
431
  case KeyValue::SPECIAL:
86
431
    m_output << "xml:special=\"" << removeNonAscii(_x.value()) << "\" ";
87
431
    break;
88
1.35k
  case KeyValue::TEST:
89
1.35k
    m_output << "xml:test=\"" << removeNonAscii(_x.value()) << "\" ";
90
1.35k
    break;
91
6.91k
  case KeyValue::FUZZ:
92
6.91k
    if (_x.ByteSizeLong() % 2)
93
2.07k
      m_output << "xmlns:" << removeNonAscii(_x.key()) << "=\"" << removeNonAscii(_x.value()) << "\" ";
94
4.84k
    else
95
4.84k
      m_output << removeNonAscii(_x.key()) << "=\"" << removeNonAscii(_x.value()) << "\" ";
96
6.91k
    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
19.3k
  }
101
19.3k
}
102
103
void ProtoConverter::visit(ProcessingInstruction const& _x)
104
1.57k
{
105
1.57k
  m_output << "<?" << removeNonAscii(_x.name()) << " ";
106
1.57k
  for (auto const& prop: _x.kv())
107
1.50k
    visit(prop);
108
1.57k
  m_output << "?>\n";
109
1.57k
}
110
111
void ProtoConverter::visit(Content const& _x)
112
148k
{
113
148k
  switch (_x.content_oneof_case())
114
148k
  {
115
1.96k
  case Content::kStr:
116
1.96k
    m_output << _x.str() << "\n";
117
1.96k
    break;
118
2.54k
  case Content::kE:
119
2.54k
    visit(_x.e());
120
2.54k
    m_output << "\n";
121
2.54k
    break;
122
2.01k
  case Content::kC:
123
2.01k
    visit(_x.c());
124
2.01k
    m_output << "\n";
125
2.01k
    break;
126
142k
  case Content::CONTENT_ONEOF_NOT_SET:
127
142k
    break;
128
148k
  }
129
148k
}
130
131
void ProtoConverter::visit(ElementDecl const& _x)
132
4.86k
{
133
4.86k
  if (!ElementDecl::ContentSpec_IsValid(_x.spec()))
134
46
    return;
135
136
4.82k
  m_output << "<!ELEMENT " << _x.name() << " ";
137
4.82k
  switch (_x.spec())
138
4.82k
  {
139
2.37k
  case ElementDecl::EMPTY:
140
2.37k
    m_output << "EMPTY>";
141
2.37k
    break;
142
264
  case ElementDecl::ANY:
143
264
    m_output << "ANY>";
144
264
    break;
145
257
  case ElementDecl::FUZZ:
146
257
    m_output << "FUZZ>";
147
257
    break;
148
1.07k
  case ElementDecl::MIXED:
149
1.07k
    m_output << "(#PCDATA";
150
1.07k
    for (auto const& pcdata: _x.cdata())
151
2.63k
      m_output << "|" << pcdata;
152
1.07k
    m_output << ")";
153
1.07k
    if (_x.cdata_size() > 0)
154
787
      m_output << "*";
155
1.07k
    m_output << ">";
156
1.07k
    break;
157
853
  case ElementDecl::CHILDREN:
158
853
  {
159
853
    m_output << "(";
160
853
    string delim = "";
161
2.69k
    for (auto const& str: _x.cdata()) {
162
2.69k
      m_output << delim << removeNonAscii(str);
163
2.69k
      delim = ", ";
164
2.69k
    }
165
853
    m_output << ")>";
166
853
    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.82k
  }
172
4.82k
}
173
174
void ProtoConverter::visit(AttValue const& _x)
175
5.07k
{
176
5.07k
  if (!isValid(_x))
177
52
    return;
178
179
5.02k
  m_output << "\"";
180
5.02k
  string prefix;
181
5.02k
  switch (_x.type())
182
5.02k
  {
183
2.61k
  case AttValue::ENTITY:
184
2.61k
    prefix = "&";
185
2.61k
    break;
186
1.57k
  case AttValue::CHAR:
187
1.57k
    if (_x.ByteSizeLong() % 2)
188
342
      prefix = "&#";
189
1.23k
    else
190
      // TODO: Value that follows this must be a
191
      // sequence of hex digits.
192
1.23k
      prefix = "&#x";
193
1.57k
    break;
194
840
  case AttValue::FUZZ:
195
840
    prefix = "fuzz";
196
840
    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
5.02k
  }
201
5.02k
  for (auto const& name: _x.value())
202
6.01k
    m_output << prefix << removeNonAscii(name) << ";";
203
5.02k
  m_output << "\"";
204
5.02k
}
205
206
void ProtoConverter::visit(DefaultDecl const& _x)
207
17.1k
{
208
17.1k
  if (!isValid(_x))
209
83
    return;
210
211
17.0k
  switch (_x.type())
212
17.0k
  {
213
11.2k
  case DefaultDecl::REQUIRED:
214
11.2k
    m_output << "#REQUIRED";
215
11.2k
    break;
216
374
  case DefaultDecl::IMPLIED:
217
374
    m_output << "#IMPLIED";
218
374
    break;
219
5.07k
  case DefaultDecl::FIXED:
220
5.07k
    m_output << "#FIXED ";
221
5.07k
    visit(_x.att());
222
5.07k
    break;
223
341
  case DefaultDecl::FUZZ:
224
341
    m_output << "#FUZZ";
225
341
    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
17.0k
  }
230
17.0k
}
231
232
void ProtoConverter::visit(AttDef const& _x)
233
17.2k
{
234
17.2k
  if (!isValid(_x))
235
67
    return;
236
237
17.1k
  m_output << " " << removeNonAscii(_x.name()) << " ";
238
17.1k
  switch (_x.type())
239
17.1k
  {
240
8.73k
  case AttDef::CDATA:
241
8.73k
    m_output << "CDATA ";
242
8.73k
    break;
243
1.58k
  case AttDef::ID:
244
1.58k
    m_output << "ID ";
245
1.58k
    break;
246
3.14k
  case AttDef::IDREF:
247
3.14k
    m_output << "IDREF ";
248
3.14k
    break;
249
649
  case AttDef::IDREFS:
250
649
    m_output << "IDREFS ";
251
649
    break;
252
1.15k
  case AttDef::ENTITY:
253
1.15k
    m_output << "ENTITY ";
254
1.15k
    break;
255
473
  case AttDef::ENTITIES:
256
473
    m_output << "ENTITIES ";
257
473
    break;
258
351
  case AttDef::NMTOKEN:
259
351
    m_output << "NMTOKEN ";
260
351
    break;
261
490
  case AttDef::NMTOKENS:
262
490
    m_output << "NMTOKENS ";
263
490
    break;
264
561
  case AttDef::FUZZ:
265
561
    m_output << "FUZZ ";
266
561
    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
17.1k
  }
271
17.1k
  visit(_x.def());
272
17.1k
}
273
274
void ProtoConverter::visit(AttListDecl const& _x)
275
5.01k
{
276
5.01k
  m_output << "<!ATTLIST " << removeNonAscii(_x.name());
277
5.01k
  for (auto const& att: _x.attdefs())
278
17.2k
    visit(att);
279
5.01k
  m_output << ">";
280
5.01k
}
281
282
void ProtoConverter::visit(NotationDecl const& _x)
283
5.55k
{
284
5.55k
  m_output << "<!NOTATION " << removeNonAscii(_x.name()) << " ";
285
5.55k
  switch (_x.notation_oneof_case())
286
5.55k
  {
287
1.70k
  case NotationDecl::kExt:
288
1.70k
    visit(_x.ext());
289
1.70k
    break;
290
2.31k
  case NotationDecl::kPub:
291
2.31k
    m_output << "PUBLIC " << _x.pub();
292
2.31k
    break;
293
827
  case NotationDecl::kFuzz:
294
827
    m_output << "FUZZ " << _x.fuzz();
295
827
    break;
296
711
  case NotationDecl::NOTATION_ONEOF_NOT_SET:
297
711
    break;
298
5.55k
  }
299
5.55k
  m_output << ">";
300
5.55k
}
301
302
void ProtoConverter::visit(NDataDecl const& _x)
303
2.90k
{
304
2.90k
  m_output << " NDATA " << _x.name();
305
2.90k
}
306
307
void ProtoConverter::visit(EntityDef const& _x)
308
9.31k
{
309
9.31k
  switch (_x.entity_oneof_case())
310
9.31k
  {
311
4.82k
  case EntityDef::kExt:
312
4.82k
    visit(_x.ext());
313
4.82k
    if (_x.ByteSizeLong() % 2)
314
2.90k
      visit(_x.ndata());
315
4.82k
    break;
316
2.04k
  case EntityDef::kVal:
317
2.04k
    visit(_x.val());
318
2.04k
    break;
319
2.44k
  case EntityDef::ENTITY_ONEOF_NOT_SET:
320
2.44k
    break;
321
9.31k
  }
322
9.31k
}
323
324
void ProtoConverter::visit(PEDef const& _x)
325
3.95k
{
326
3.95k
  switch (_x.pedef_oneof_case())
327
3.95k
  {
328
2.34k
  case PEDef::kVal:
329
2.34k
    visit(_x.val());
330
2.34k
    break;
331
719
  case PEDef::kId:
332
719
    visit(_x.id());
333
719
    break;
334
898
  case PEDef::PEDEF_ONEOF_NOT_SET:
335
898
    break;
336
3.95k
  }
337
3.95k
}
338
339
void ProtoConverter::visit(EntityValue const& _x)
340
4.38k
{
341
4.38k
  if (!isValid(_x))
342
18
    return;
343
344
4.36k
  m_output << "\"";
345
4.36k
  string prefix;
346
4.36k
  switch (_x.type())
347
4.36k
  {
348
1.60k
  case EntityValue::ENTITY:
349
1.60k
    prefix = "&";
350
1.60k
    break;
351
2.28k
  case EntityValue::CHAR:
352
2.28k
    if (_x.ByteSizeLong() % 2)
353
693
      prefix = "&#";
354
1.59k
    else
355
1.59k
      prefix = "&#x";
356
2.28k
    break;
357
143
  case EntityValue::PEREF:
358
143
    prefix = "%";
359
143
    break;
360
334
  case EntityValue::FUZZ:
361
334
    prefix = "fuzz";
362
334
    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
4.36k
  }
367
4.36k
  for (auto const& ref: _x.name())
368
8.11k
    m_output << prefix << ref << ";";
369
4.36k
  m_output << "\"";
370
4.36k
}
371
372
void ProtoConverter::visit(EntityDecl const& _x)
373
13.3k
{
374
13.3k
  if (!isValid(_x))
375
82
    return;
376
377
13.2k
  m_output << "<!ENTITY ";
378
13.2k
  switch (_x.type())
379
13.2k
  {
380
9.31k
  case EntityDecl::GEDECL:
381
9.31k
    m_output << _x.name() << " ";
382
9.31k
    visit(_x.ent());
383
9.31k
    break;
384
3.95k
  case EntityDecl::PEDECL:
385
3.95k
    m_output << "% " << _x.name() << " ";
386
3.95k
    visit(_x.pedef());
387
3.95k
    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
13.2k
  }
392
13.2k
  m_output << ">";
393
13.2k
}
394
395
void ProtoConverter::visit(ConditionalSect const& _x)
396
8.96k
{
397
8.96k
  if (!isValid(_x))
398
199
    return;
399
400
8.76k
  switch (_x.type())
401
8.76k
  {
402
5.81k
  case ConditionalSect::INCLUDE:
403
5.81k
    m_output << "<![ INCLUDE [";
404
5.81k
    visit(_x.ext());
405
5.81k
    m_output << "]]>";
406
5.81k
    break;
407
1.08k
  case ConditionalSect::IGNORE:
408
1.08k
    m_output << "<![ IGNORE [";
409
1.08k
    for (auto const& str: _x.ignores())
410
890
      m_output << "<![" << removeNonAscii(str) << "]]>";
411
1.08k
    m_output << "]]>";
412
1.08k
    break;
413
1.86k
  case ConditionalSect::FUZZ:
414
1.86k
    m_output << "<![ FUZZ [";
415
1.86k
    visit(_x.ext());
416
1.86k
    m_output << "]]>";
417
1.86k
    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
8.76k
  }
422
8.76k
}
423
424
425
void ProtoConverter::visit(OneExtSubsetDecl const& _x)
426
42.0k
{
427
42.0k
  switch (_x.extsubset_oneof_case())
428
42.0k
  {
429
25.7k
  case OneExtSubsetDecl::kM:
430
25.7k
    visit(_x.m());
431
25.7k
    break;
432
8.96k
  case OneExtSubsetDecl::kC:
433
8.96k
    visit(_x.c());
434
8.96k
    break;
435
7.36k
  case OneExtSubsetDecl::EXTSUBSET_ONEOF_NOT_SET:
436
7.36k
    break;
437
42.0k
  }
438
42.0k
}
439
440
441
void ProtoConverter::visit(ExtSubsetDecl const& _x)
442
13.4k
{
443
13.4k
  for (auto const& decl: _x.decls())
444
42.0k
    visit(decl);
445
13.4k
}
446
447
void ProtoConverter::visit(CData const& _x)
448
2.01k
{
449
2.01k
  m_output << "<![CDATA[" << removeNonAscii(_x.data()) << "]]>";
450
2.01k
}
451
452
void ProtoConverter::visit(MarkupDecl const& _x)
453
41.7k
{
454
41.7k
  switch (_x.markup_oneof_case())
455
41.7k
  {
456
4.86k
  case MarkupDecl::kE:
457
4.86k
    visit(_x.e());
458
4.86k
    break;
459
5.01k
  case MarkupDecl::kA:
460
5.01k
    visit(_x.a());
461
5.01k
    break;
462
5.55k
  case MarkupDecl::kN:
463
5.55k
    visit(_x.n());
464
5.55k
    break;
465
2.13k
  case MarkupDecl::kM:
466
2.13k
    visit(_x.m());
467
2.13k
    break;
468
13.3k
  case MarkupDecl::kEntity:
469
13.3k
    visit(_x.entity());
470
13.3k
    break;
471
5.73k
  case MarkupDecl::kExt:
472
5.73k
    visit(_x.ext());
473
5.73k
    break;
474
5.13k
  case MarkupDecl::MARKUP_ONEOF_NOT_SET:
475
5.13k
    break;
476
41.7k
  }
477
41.7k
}
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
136k
{
486
136k
  string output{};
487
136k
  switch (_x)
488
136k
  {
489
125k
  case Element::XIINCLUDE:
490
127k
  case Element::XIFALLBACK:
491
130k
  case Element::XIHREF:
492
130k
    output = "xi:include href=\"fuzz.xml\"";
493
131k
  case Element::XIPARSE:
494
131k
    output = "xi:include parse=\"xml\"";
495
132k
  case Element::XIXPOINTER:
496
132k
    output = "xi:include xpointer=\"" + removeNonAscii(_prop) + "\"";
497
133k
  case Element::XIENCODING:
498
133k
    output = "xi:include encoding=\"" + removeNonAscii(_prop) + "\"";
499
135k
  case Element::XIACCEPT:
500
135k
    output = "xi:include accept=\"" + removeNonAscii(_prop) + "\"";
501
136k
  case Element::XIACCEPTLANG:
502
136k
    output = "xi:include accept-language=\"" + removeNonAscii(_prop) + "\"";
503
136k
  case Element_Id_Element_Id_INT_MIN_SENTINEL_DO_NOT_USE_:
504
136k
  case Element_Id_Element_Id_INT_MAX_SENTINEL_DO_NOT_USE_:
505
136k
    output = "xi:fuzz xifuzz=\"fuzz\"";
506
136k
  }
507
136k
  return output;
508
136k
}
509
510
/// Returns uri string for a given Element_Id type
511
string ProtoConverter::getUri(Element_Id _x)
512
136k
{
513
136k
  if (!Element::Id_IsValid(_x))
514
246
    return s_XInclude;
515
516
136k
  switch (_x)
517
136k
  {
518
125k
  case Element::XIINCLUDE:
519
127k
  case Element::XIFALLBACK:
520
130k
  case Element::XIHREF:
521
131k
  case Element::XIPARSE:
522
132k
  case Element::XIXPOINTER:
523
133k
  case Element::XIENCODING:
524
135k
  case Element::XIACCEPT:
525
136k
  case Element::XIACCEPTLANG:
526
136k
  case Element_Id_Element_Id_INT_MIN_SENTINEL_DO_NOT_USE_:
527
136k
  case Element_Id_Element_Id_INT_MAX_SENTINEL_DO_NOT_USE_:
528
136k
    return s_XInclude;
529
136k
  }
530
136k
}
531
532
void ProtoConverter::visit(Element const& _x)
533
149k
{
534
149k
  if (!isValid(_x))
535
33
    return;
536
537
  // Predefined child node
538
148k
  string child = {};
539
  // Predefined uri for child node
540
148k
  string pUri = {};
541
  // Element name
542
148k
  string name = removeNonAscii(_x.name());
543
544
148k
  switch (_x.type())
545
148k
  {
546
136k
  case Element::PREDEFINED:
547
136k
    child = getPredefined(_x.id(), _x.childprop());
548
136k
    pUri = getUri(_x.id());
549
136k
    break;
550
12.4k
  case Element::FUZZ:
551
12.4k
  case Element_Type_Element_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
552
12.4k
  case Element_Type_Element_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
553
12.4k
    break;
554
148k
  }
555
556
  // <name k1=v1 k2=v2 k3=v3>
557
  // <content>
558
  // </name>
559
560
  // Start name tag: Must be Ascii?
561
148k
  m_output << "<" << name << " ";
562
563
  // Add uri to name tag
564
148k
  if (!pUri.empty())
565
136k
    m_output << pUri << " ";
566
148k
  for (auto const& prop: _x.kv())
567
18.1k
    visit(prop);
568
148k
  m_output << ">\n";
569
570
  // Add attribute
571
148k
  if (!child.empty())
572
136k
    m_output << "<" << child << "/>\n";
573
574
  // Add content
575
148k
  visit(_x.content());
576
577
  // Close name tag
578
148k
  m_output << "</" << name << ">\n";
579
148k
}
580
581
void ProtoConverter::visit(ExternalId const& _x)
582
15.3k
{
583
15.3k
  if (!isValid(_x))
584
1.03k
    return;
585
586
14.3k
  switch (_x.type())
587
14.3k
  {
588
11.3k
  case ExternalId::SYSTEM:
589
11.3k
    m_output << "SYSTEM " << "\"" << removeNonAscii(_x.system()) << "\"";
590
11.3k
    break;
591
1.30k
  case ExternalId::PUBLIC:
592
1.30k
    m_output << "PUBLIC " << "\"" << removeNonAscii(_x.pub()) << "\""
593
1.30k
      << " " << "\"" << removeNonAscii(_x.system()) << "\"";
594
1.30k
    break;
595
1.68k
  case ExternalId::FUZZ:
596
1.68k
    m_output << "FUZZ " << "\"" << removeNonAscii(_x.pub()) << "\"";
597
1.68k
    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
14.3k
  }
602
14.3k
}
603
604
void ProtoConverter::visit(DocTypeDecl const& _x)
605
8.13k
{
606
8.13k
  m_output << "<!DOCTYPE " << removeNonAscii(_x.name()) << " ";
607
8.13k
  visit(_x.ext());
608
8.13k
  m_output << "[";
609
8.13k
  for (auto const& m: _x.mdecl())
610
16.0k
    visit(m);
611
8.13k
  m_output << "]";
612
8.13k
  m_output << ">\n";
613
8.13k
}
614
615
void ProtoConverter::visit(VersionNum const& _x)
616
8.13k
{
617
8.13k
  if (!isValid(_x))
618
3
    return;
619
620
8.13k
  switch (_x.type())
621
8.13k
  {
622
7.99k
  case VersionNum::STANDARD:
623
7.99k
    m_output << "\"1.0\"";
624
7.99k
    break;
625
136
  case VersionNum::FUZZ:
626
136
  case VersionNum_Type_VersionNum_Type_INT_MIN_SENTINEL_DO_NOT_USE_:
627
136
  case VersionNum_Type_VersionNum_Type_INT_MAX_SENTINEL_DO_NOT_USE_:
628
136
    m_output << "\"" << _x.major() << "." << _x.minor() << "\"";
629
136
    break;
630
8.13k
  }
631
8.13k
}
632
633
void ProtoConverter::visit(Encodings const& _x)
634
8.13k
{
635
8.13k
  if (!Encodings::Enc_IsValid(_x.name()))
636
554
    return;
637
638
7.58k
  m_output << " encoding=\"";
639
7.58k
  switch (_x.name())
640
7.58k
  {
641
6.58k
  case Encodings::BIG5:
642
6.58k
    m_output << "BIG5";
643
6.58k
    break;
644
12
  case Encodings::EUCJP:
645
12
    m_output << "EUC-JP";
646
12
    break;
647
38
  case Encodings::EUCKR:
648
38
    m_output << "EUC-KR";
649
38
    break;
650
18
  case Encodings::GB18030:
651
18
    m_output << "GB18030";
652
18
    break;
653
2
  case Encodings::ISO2022JP:
654
2
    m_output << "ISO-2022-JP";
655
2
    break;
656
148
  case Encodings::ISO2022KR:
657
148
    m_output << "ISO-2022-KR";
658
148
    break;
659
73
  case Encodings::ISO88591:
660
73
    m_output << "ISO-8859-1";
661
73
    break;
662
4
  case Encodings::ISO88592:
663
4
    m_output << "ISO-8859-2";
664
4
    break;
665
12
  case Encodings::ISO88593:
666
12
    m_output << "ISO-8859-3";
667
12
    break;
668
11
  case Encodings::ISO88594:
669
11
    m_output << "ISO-8859-4";
670
11
    break;
671
21
  case Encodings::ISO88595:
672
21
    m_output << "ISO-8859-5";
673
21
    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
3
  case Encodings::ISO88598:
681
3
    m_output << "ISO-8859-8";
682
3
    break;
683
13
  case Encodings::ISO88599:
684
13
    m_output << "ISO-8859-9";
685
13
    break;
686
133
  case Encodings::SHIFTJIS:
687
133
    m_output << "SHIFT_JIS";
688
133
    break;
689
16
  case Encodings::TIS620:
690
16
    m_output << "TIS-620";
691
16
    break;
692
88
  case Encodings::USASCII:
693
88
    m_output << "US-ASCII";
694
88
    break;
695
109
  case Encodings::UTF8:
696
109
    m_output << "UTF-8";
697
109
    break;
698
42
  case Encodings::UTF16:
699
42
    m_output << "UTF-16";
700
42
    break;
701
19
  case Encodings::UTF16BE:
702
19
    m_output << "UTF-16BE";
703
19
    break;
704
16
  case Encodings::UTF16LE:
705
16
    m_output << "UTF-16LE";
706
16
    break;
707
43
  case Encodings::WINDOWS31J:
708
43
    m_output << "WINDOWS-31J";
709
43
    break;
710
6
  case Encodings::WINDOWS1255:
711
6
    m_output << "WINDOWS-1255";
712
6
    break;
713
4
  case Encodings::WINDOWS1256:
714
4
    m_output << "WINDOWS-1256";
715
4
    break;
716
153
  case Encodings::FUZZ:
717
153
    m_output << removeNonAscii(_x.fuzz());
718
153
    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
7.58k
  }
723
7.58k
  m_output << "\"";
724
7.58k
}
725
726
void ProtoConverter::visit(XmlDeclaration const& _x)
727
8.13k
{
728
8.13k
  m_output << R"(<?xml version=)";
729
8.13k
  visit(_x.ver());
730
8.13k
  visit(_x.enc());
731
8.13k
  switch (_x.standalone())
732
8.13k
  {
733
7.73k
  case XmlDeclaration::YES:
734
7.73k
    m_output << " standalone=\'yes\'";
735
7.73k
    break;
736
346
  case XmlDeclaration::NO:
737
346
    m_output << " standalone=\'no\'";
738
346
    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
50
  default:
742
50
    break;
743
8.13k
  }
744
8.13k
  m_output << "?>\n";
745
8.13k
}
746
747
void ProtoConverter::visit(XmlDocument const& _x)
748
8.13k
{
749
8.13k
  visit(_x.p());
750
8.13k
  for (auto const& element: _x.e())
751
146k
    visit(element);
752
8.13k
}
753
754
string ProtoConverter::protoToString(XmlDocument const& _x)
755
8.13k
{
756
8.13k
  visit(_x);
757
8.13k
  return m_output.str();
758
8.13k
}