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 DString &input)
 Creates an instance of a DotAttribute list given its initial string representation.
DString str () const
 Return the string representation of the attribute list.
void updateValue (const DString &key, const DString &inpValue)

Private Attributes

DString 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 DString & 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) {}

References m_input.

Member Function Documentation

◆ str()

DString 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 DString & key,
const DString & 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 && disspace(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]!=';' && !disspace(s[pos])) pos++;
60 }
61 DString value;
62 if (inpValue.empty())
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.empty())
76 {
77 if (!m_input.empty()) m_input+=",";
78 m_input+=key+"="+inpValue.quoted();
79 }
80 }
81 }
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:323
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
DString quoted() const
Definition dstring.h:357
DString left(size_t len) const
Definition dstring.h:311
const std::string & str() const
Definition dstring.h:634
bool disspace(char c)
Definition dstring.h:67
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:847
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:858

References disspace(), DString::empty(), DString::left(), m_input, DString::mid(), DString::quoted(), reg::search(), and DString::str().

Referenced by updateAttribute().

Member Data Documentation

◆ m_input

DString 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: