Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
XMLUtf8BufferWriter Class Referencefinal

#include <XMLWriter.h>

Collaboration diagram for XMLUtf8BufferWriter:
[legend]

Public Member Functions

void StartTag (const std::string_view &name)
 
void EndTag (const std::string_view &name)
 
void WriteAttr (const std::string_view &name, const Identifier &value)
 
void WriteAttr (const std::string_view &name, const std::string_view &value)
 
void WriteAttr (const std::string_view &name, int value)
 
void WriteAttr (const std::string_view &name, bool value)
 
void WriteAttr (const std::string_view &name, long value)
 
void WriteAttr (const std::string_view &name, long long value)
 
void WriteAttr (const std::string_view &name, size_t value)
 
void WriteAttr (const std::string_view &name, float value, int digits=-1)
 
void WriteAttr (const std::string_view &name, double value, int digits=-1)
 
void WriteData (const std::string_view &value)
 
void WriteSubTree (const std::string_view &value)
 
void Write (const std::string_view &value)
 
MemoryStream ConsumeResult ()
 

Private Member Functions

void WriteEscaped (const std::string_view &value)
 

Private Attributes

MemoryStream mStream
 
bool mInTag { false }
 

Detailed Description

Definition at line 152 of file XMLWriter.h.

Member Function Documentation

◆ ConsumeResult()

MemoryStream XMLUtf8BufferWriter::ConsumeResult ( )

Definition at line 578 of file XMLWriter.cpp.

579{
580 return std::move(mStream);
581}
MemoryStream mStream
Definition: XMLWriter.h:182

References mStream.

◆ EndTag()

void XMLUtf8BufferWriter::EndTag ( const std::string_view &  name)

Definition at line 446 of file XMLWriter.cpp.

447{
448 if (mInTag)
449 {
450 Write("/>");
451 mInTag = false;
452 }
453 else
454 {
455 Write("</");
456 Write(name);
457 Write(">");
458 }
459}
const TranslatableString name
Definition: Distortion.cpp:76
void Write(const std::string_view &value)
Definition: XMLWriter.cpp:573

References mInTag, name, and Write().

Here is the call graph for this function:

◆ StartTag()

void XMLUtf8BufferWriter::StartTag ( const std::string_view &  name)

Definition at line 435 of file XMLWriter.cpp.

436{
437 if (mInTag)
438 Write(">");
439
440 Write("<");
441 Write(name);
442
443 mInTag = true;
444}

References mInTag, name, and Write().

Here is the call graph for this function:

◆ Write()

void XMLUtf8BufferWriter::Write ( const std::string_view &  value)

Definition at line 573 of file XMLWriter.cpp.

574{
575 mStream.AppendData(value.data(), value.length());
576}
void AppendData(const void *data, const size_t length)

References MemoryStream::AppendData(), and mStream.

Referenced by EndTag(), StartTag(), WriteAttr(), WriteData(), WriteEscaped(), and WriteSubTree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteAttr() [1/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
bool  value 
)

Definition at line 485 of file XMLWriter.cpp.

486{
487 WriteAttr(name, static_cast<long long>(value));
488}
void WriteAttr(const std::string_view &name, const Identifier &value)
Definition: XMLWriter.cpp:461

References name, and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [2/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
const Identifier value 
)

Definition at line 461 of file XMLWriter.cpp.

462{
463 const wxScopedCharBuffer utf8Value = value.GET().utf8_str();
464
465 WriteAttr(name, { utf8Value.data(), utf8Value.length() });
466}
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66

References Identifier::GET(), name, and WriteAttr().

Referenced by WriteAttr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteAttr() [3/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
const std::string_view &  value 
)

Definition at line 468 of file XMLWriter.cpp.

470{
471 assert(mInTag);
472
473 Write(" ");
474 Write(name);
475 Write("=\"");
476 WriteEscaped(value);
477 Write("\"");
478}
void WriteEscaped(const std::string_view &value)
Definition: XMLWriter.cpp:583

References mInTag, name, Write(), and WriteEscaped().

Here is the call graph for this function:

◆ WriteAttr() [4/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
double  value,
int  digits = -1 
)

Definition at line 534 of file XMLWriter.cpp.

536{
537 constexpr size_t bufferSize = std::numeric_limits<double>::max_digits10 +
538 5 + // No constexpr log2 yet!
539 3; // Dot, sign an 0 separator
540
541 char buffer[bufferSize];
542
543 const auto result = ToChars(buffer, buffer + bufferSize, value, digits);
544
545 if (result.ec != std::errc())
547
548 WriteAttr(name, std::string_view(buffer, result.ptr - buffer));
549}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
STRING_UTILS_API ToCharsResult ToChars(char *buffer, char *last, float value, int digitsAfterDecimalPoint) noexcept
Convert a single precision floating point number to a string, always uses the dot as decimal.
Definition: ToChars.cpp:1225

References name, THROW_INCONSISTENCY_EXCEPTION, ToChars(), and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [5/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
float  value,
int  digits = -1 
)

Definition at line 517 of file XMLWriter.cpp.

519{
520 constexpr size_t bufferSize = std::numeric_limits<float>::max_digits10 +
521 5 + // No constexpr log2 yet! example - e-308
522 3; // Dot, sign an 0 separator
523
524 char buffer[bufferSize];
525
526 const auto result = ToChars(buffer, buffer + bufferSize, value, digits);
527
528 if (result.ec != std::errc())
530
531 WriteAttr(name, std::string_view(buffer, result.ptr - buffer));
532}

References name, THROW_INCONSISTENCY_EXCEPTION, ToChars(), and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [6/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
int  value 
)

Definition at line 480 of file XMLWriter.cpp.

481{
482 WriteAttr(name, static_cast<long long>(value));
483}

References name, and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [7/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
long long  value 
)

Definition at line 496 of file XMLWriter.cpp.

498{
499 // -9223372036854775807 is the worst case
500 constexpr size_t bufferSize = 21;
501 char buffer[bufferSize];
502
503 const auto result = ToChars(buffer, buffer + bufferSize, value);
504
505 if (result.ec != std::errc())
507
508 WriteAttr(name, std::string_view(buffer, result.ptr - buffer));
509}

References name, THROW_INCONSISTENCY_EXCEPTION, ToChars(), and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [8/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
long  value 
)

Definition at line 490 of file XMLWriter.cpp.

491{
492 // long can be int or long long. Assume the longest!
493 WriteAttr(name, static_cast<long long>(value));
494}

References name, and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [9/9]

void XMLUtf8BufferWriter::WriteAttr ( const std::string_view &  name,
size_t  value 
)

Definition at line 511 of file XMLWriter.cpp.

512{
513 // Well, that maintains the original behavior
514 WriteAttr(name, static_cast<long long>(value));
515}

References name, and WriteAttr().

Here is the call graph for this function:

◆ WriteData()

void XMLUtf8BufferWriter::WriteData ( const std::string_view &  value)

Definition at line 551 of file XMLWriter.cpp.

552{
553 if (mInTag)
554 {
555 Write(">");
556 mInTag = false;
557 }
558
559 WriteEscaped(value);
560}

References mInTag, Write(), and WriteEscaped().

Here is the call graph for this function:

◆ WriteEscaped()

void XMLUtf8BufferWriter::WriteEscaped ( const std::string_view &  value)
private

Definition at line 583 of file XMLWriter.cpp.

584{
585 for (auto c : value)
586 {
587 switch (c)
588 {
589 case wxT('\''):
590 Write("&apos;");
591 break;
592
593 case wxT('"'):
594 Write("&quot;");
595 break;
596
597 case wxT('&'):
598 Write("&amp;");
599 break;
600
601 case wxT('<'):
602 Write("&lt;");
603 break;
604
605 case wxT('>'):
606 Write("&gt;");
607 break;
608 default:
609 if (static_cast<uint8_t>(c) > 0x1F || charXMLCompatiblity[c] != 0)
611 }
612 }
613}
wxT("CloseDown"))
static int charXMLCompatiblity[]
Definition: XMLWriter.cpp:41
void AppendByte(char data)

References MemoryStream::AppendByte(), charXMLCompatiblity, mStream, Write(), and wxT().

Referenced by WriteAttr(), and WriteData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteSubTree()

void XMLUtf8BufferWriter::WriteSubTree ( const std::string_view &  value)

Definition at line 562 of file XMLWriter.cpp.

563{
564 if (mInTag)
565 {
566 Write(">");
567 mInTag = false;
568 }
569
570 Write(value);
571}

References mInTag, and Write().

Here is the call graph for this function:

Member Data Documentation

◆ mInTag

bool XMLUtf8BufferWriter::mInTag { false }
private

Definition at line 184 of file XMLWriter.h.

Referenced by EndTag(), StartTag(), WriteAttr(), WriteData(), and WriteSubTree().

◆ mStream

MemoryStream XMLUtf8BufferWriter::mStream
private

Definition at line 182 of file XMLWriter.h.

Referenced by ConsumeResult(), Write(), and WriteEscaped().


The documentation for this class was generated from the following files: