Doxygen
Loading...
Searching...
No Matches
DotAttributes Class Reference

Class representing an attribute list of a dot graph object. More...

#include <src/dotattributes.h>

+ Collaboration diagram for DotAttributes:

Public Member Functions

 DotAttributes (const QCString &input)
 Creates an instance of a DotAttribute list given its initial string representation.
 
QCString str () const
 Return the string representation of the attribute list.
 
void updateValue (const QCString &key, const QCString &inpValue)
 update a given attribute with a new value.
 

Private Attributes

QCString m_input
 

Detailed Description

Class representing an attribute list of a dot graph object.

Definition at line 26 of file dotattributes.h.

Constructor & Destructor Documentation

◆ DotAttributes()

DotAttributes::DotAttributes ( const QCString & input)
inline

Creates an instance of a DotAttribute list given its initial string representation.

Definition at line 30 of file dotattributes.h.

30: m_input(input) {}
QCString m_input

References m_input.

Member Function Documentation

◆ str()

QCString DotAttributes::str ( ) const
inline

Return the string representation of the attribute list.

Definition at line 33 of file dotattributes.h.

33{ return m_input; }

References m_input.

Referenced by Config::updateObsolete().

◆ updateValue()

void DotAttributes::updateValue ( const QCString & key,
const QCString & inpValue )
inline

update a given attribute with a new value.

If the attribute is not found a new attribute will be appended.

Definition at line 37 of file dotattributes.h.

38 {
39 // look for key\s*=
40 const std::string regStr = key.str()+R"(\s*=)";
41 const reg::Ex re { regStr };
42 reg::Match match;
43 std::string s = m_input.str();
44 if (reg::search(s,match,re)) // replace existing attribute
45 {
46 size_t len = s.length();
47 size_t startPos = match.position()+match.length(); // position after =
48 size_t pos = startPos;
49 while (pos<len && qisspace(s[pos])) pos++;
50 if (pos<len && s[pos]=='"') // quoted value, search for end quote, ignoring escaped quotes
51 {
52 char pc=s[pos];
53 pos++; // skip over start quote
54 while (pos<len && (s[pos]!='"' || (s[pos]=='"' && pc=='\\'))) pc=s[pos++];
55 if (pos<len) pos++; // skip over end quote
56 }
57 else // unquoted value, search for attribute separator (space,comma, or semicolon)
58 {
59 while (pos<len && s[pos]!=',' && s[pos]!=';' && !qisspace(s[pos])) pos++;
60 }
61 QCString value;
62 if (inpValue.isEmpty())
63 {
64 value = m_input.mid(startPos,pos-startPos);
65 }
66 else
67 {
68 value = inpValue;
69 }
70 // pos is now the position after the value, so replace the part between [start..pos) with the new value
71 m_input=m_input.left(startPos)+value.quoted()+m_input.mid(pos);
72 }
73 else // append new attribute
74 {
75 if (!inpValue.isEmpty())
76 {
77 if (!m_input.isEmpty()) m_input+=",";
78 m_input+=key+"="+inpValue.quoted();
79 }
80 }
81 }
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
QCString quoted() const
Definition qcstring.h:260
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:748
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:759
bool qisspace(char c)
Definition qcstring.h:81

References QCString::isEmpty(), m_input, qisspace(), QCString::quoted(), reg::search(), and QCString::str().

Referenced by updateAttribute().

Member Data Documentation

◆ m_input

QCString DotAttributes::m_input
private

Definition at line 84 of file dotattributes.h.

Referenced by DotAttributes(), str(), and updateValue().


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