Coverage Report

Created: 2026-02-11 06:51

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