Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
dotattributes.h
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2022 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
#ifndef DOTATTRIBUTES_H
17
#define DOTATTRIBUTES_H
18
19
#include <map>
20
#include <string>
21
22
#include "
regex.h
"
23
#include "
qcstring.h
"
24
25
//! Class representing an attribute list of a dot graph object.
26
class
DotAttributes
27
{
28
public
:
29
//! Creates an instance of a DotAttribute list given its initial string representation
30
DotAttributes
(
const
QCString
&input) :
m_input
(input) {}
31
32
//! Return the string representation of the attribute list
33
QCString
str
()
const
{
return
m_input
; }
34
35
//! update a given attribute with a new value.
36
//! If the attribute is not found a new attribute will be appended.
37
void
updateValue
(
const
QCString
&key,
const
QCString
&inpValue)
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
}
82
83
private
:
84
QCString
m_input
;
85
};
86
87
#endif
// DOTATTRIBUTES_H
DotAttributes::updateValue
void updateValue(const QCString &key, const QCString &inpValue)
Definition
dotattributes.h:37
DotAttributes::DotAttributes
DotAttributes(const QCString &input)
Creates an instance of a DotAttribute list given its initial string representation.
Definition
dotattributes.h:30
DotAttributes::str
QCString str() const
Return the string representation of the attribute list.
Definition
dotattributes.h:33
DotAttributes::m_input
QCString m_input
Definition
dotattributes.h:84
QCString
This is an alternative implementation of QCString.
Definition
qcstring.h:101
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition
qcstring.h:163
QCString::str
const std::string & str() const
Definition
qcstring.h:552
QCString::quoted
QCString quoted() const
Definition
qcstring.h:275
reg::Ex
Class representing a regular expression.
Definition
regex.h:39
reg::Match
Object representing the matching results.
Definition
regex.h:151
reg::search
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:844
qcstring.h
qisspace
bool qisspace(char c)
Definition
qcstring.h:81
regex.h
src
dotattributes.h
Generated by
1.17.0