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

Class representing a string buffer optimized for growing. More...

#include <src/growbuf.h>

Public Member Functions

 GrowBuf ()
 
 GrowBuf (size_t initialSize)
 
 ~GrowBuf ()
 
 GrowBuf (const GrowBuf &other)
 
GrowBufoperator= (const GrowBuf &other)
 
 GrowBuf (GrowBuf &&other)
 
GrowBufoperator= (GrowBuf &&other)
 
void reserve (size_t size)
 
void clear ()
 
void addChar (char c)
 
void addStr (const QCString &s)
 
void addStr (const std::string &s)
 
void addStr (const char *s)
 
void addStr (const char *s, size_t n)
 
void addInt (const char *fmt, int value)
 
char * get ()
 
const char * get () const
 
size_t getPos () const
 
void setPos (size_t newPos)
 
const char & at (size_t i) const
 
bool empty () const
 

Private Attributes

char * m_str
 
size_t m_pos
 
size_t m_len
 

Detailed Description

Class representing a string buffer optimized for growing.

Definition at line 27 of file growbuf.h.

Constructor & Destructor Documentation

◆ GrowBuf() [1/4]

GrowBuf::GrowBuf ( )
inline

Definition at line 30 of file growbuf.h.

30: m_str(nullptr), m_pos(0), m_len(0) {}
size_t m_pos
Definition growbuf.h:122
char * m_str
Definition growbuf.h:121
size_t m_len
Definition growbuf.h:123

References m_len, m_pos, and m_str.

Referenced by GrowBuf(), GrowBuf(), operator=(), and operator=().

◆ GrowBuf() [2/4]

GrowBuf::GrowBuf ( size_t initialSize)
inline

Definition at line 31 of file growbuf.h.

31: m_pos(0), m_len(initialSize) { m_str=static_cast<char*>(malloc(m_len)); }

References m_len, m_pos, and m_str.

◆ ~GrowBuf()

GrowBuf::~GrowBuf ( )
inline

Definition at line 32 of file growbuf.h.

32{ free(m_str); }

References m_str.

◆ GrowBuf() [3/4]

GrowBuf::GrowBuf ( const GrowBuf & other)
inline

Definition at line 33 of file growbuf.h.

34 {
35 m_len = other.m_len;
36 m_pos = other.m_pos;
37 m_str = static_cast<char*>(malloc(m_len));
38 memcpy(m_str,other.m_str,m_len);
39 }

References GrowBuf(), m_len, m_pos, and m_str.

◆ GrowBuf() [4/4]

GrowBuf::GrowBuf ( GrowBuf && other)
inline

Definition at line 52 of file growbuf.h.

53 : m_str(std::exchange(other.m_str,static_cast<char*>(nullptr)))
54 , m_pos(std::exchange(other.m_pos,0))
55 , m_len(std::exchange(other.m_len,0))
56 {
57 }

References GrowBuf(), m_len, m_pos, and m_str.

Member Function Documentation

◆ addChar()

◆ addInt()

void GrowBuf::addInt ( const char * fmt,
int value )
inline

Definition at line 109 of file growbuf.h.

109 {
110 char tmp[50];
111 snprintf(tmp,50,fmt,value);
112 addStr(tmp);
113 }
void addStr(const QCString &s)
Definition growbuf.h:72

References addStr().

Referenced by formatDateTime().

◆ addStr() [1/4]

void GrowBuf::addStr ( const char * s)
inline

Definition at line 90 of file growbuf.h.

90 {
91 if (s)
92 {
93 size_t l=strlen(s);
94 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
95 strcpy(&m_str[m_pos],s);
96 m_pos+=l;
97 }
98 }

References GROW_AMOUNT, m_len, m_pos, and m_str.

◆ addStr() [2/4]

void GrowBuf::addStr ( const char * s,
size_t n )
inline

Definition at line 99 of file growbuf.h.

99 {
100 if (s)
101 {
102 size_t l=strlen(s);
103 if (n<l) l=n;
104 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
105 strncpy(&m_str[m_pos],s,n);
106 m_pos+=l;
107 }
108 }

References GROW_AMOUNT, m_len, m_pos, and m_str.

◆ addStr() [3/4]

void GrowBuf::addStr ( const QCString & s)
inline

Definition at line 72 of file growbuf.h.

72 {
73 if (!s.isEmpty())
74 {
75 size_t l=s.length();
76 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
77 strcpy(&m_str[m_pos],s.data());
78 m_pos+=l;
79 }
80 }
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159

References QCString::data(), GROW_AMOUNT, QCString::isEmpty(), QCString::length(), m_len, m_pos, and m_str.

Referenced by addInt(), SearchIndexExternal::addWord(), convertCharEntitiesToUTF8(), convertToDocBook(), convertToHtml(), convertToId(), convertToJSString(), convertToPSString(), convertToXML(), detab(), escapeCharsInString(), filterId(), HtmlDocVisitor::filterQuotedCdataAttr(), formatDateTime(), getConvertLatexMacro(), CitationManager::getFormulas(), DocParser::processCopyDoc(), and replaceVariables().

◆ addStr() [4/4]

void GrowBuf::addStr ( const std::string & s)
inline

Definition at line 81 of file growbuf.h.

81 {
82 if (!s.empty())
83 {
84 size_t l=s.length();
85 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
86 strcpy(&m_str[m_pos],s.c_str());
87 m_pos+=l;
88 }
89 }

References GROW_AMOUNT, m_len, m_pos, and m_str.

◆ at()

const char & GrowBuf::at ( size_t i) const
inline

Definition at line 118 of file growbuf.h.

118{ return m_str[i]; }

References m_str.

Referenced by filter2008VhdlComment().

◆ clear()

void GrowBuf::clear ( )
inline

Definition at line 68 of file growbuf.h.

68{ m_pos=0; }

References m_pos.

Referenced by filterId(), and CitationManager::getFormulas().

◆ empty()

bool GrowBuf::empty ( ) const
inline

Definition at line 119 of file growbuf.h.

119{ return m_pos==0; }

References m_pos.

◆ get() [1/2]

◆ get() [2/2]

const char * GrowBuf::get ( ) const
inline

Definition at line 115 of file growbuf.h.

115{ return m_str; }

References m_str.

◆ getPos()

size_t GrowBuf::getPos ( ) const
inline

Definition at line 116 of file growbuf.h.

116{ return m_pos; }

References m_pos.

Referenced by SearchIndexExternal::addWord(), filter2008VhdlComment(), and DocParser::processCopyDoc().

◆ operator=() [1/2]

GrowBuf & GrowBuf::operator= ( const GrowBuf & other)
inline

Definition at line 40 of file growbuf.h.

41 {
42 if (this!=&other)
43 {
44 free(m_str);
45 m_len = other.m_len;
46 m_pos = other.m_pos;
47 m_str = static_cast<char*>(malloc(m_len));
48 memcpy(m_str,other.m_str,m_len);
49 }
50 return *this;
51 }

References GrowBuf(), m_len, m_pos, and m_str.

◆ operator=() [2/2]

GrowBuf & GrowBuf::operator= ( GrowBuf && other)
inline

Definition at line 58 of file growbuf.h.

59 {
60 if (this==&other)
61 return *this;
62 m_len = std::exchange(other.m_len,0);
63 m_pos = std::exchange(other.m_pos,0);
64 m_str = std::exchange(other.m_str,static_cast<char*>(nullptr));
65 return *this;
66 }

References GrowBuf(), m_len, m_pos, and m_str.

◆ reserve()

void GrowBuf::reserve ( size_t size)
inline

Definition at line 67 of file growbuf.h.

67{ if (m_len<size) { m_len = size; m_str = static_cast<char*>(realloc(m_str,m_len)); } }

References m_len, and m_str.

◆ setPos()

void GrowBuf::setPos ( size_t newPos)
inline

Definition at line 117 of file growbuf.h.

117{ m_pos = newPos; }

References m_pos.

Referenced by filter2008VhdlComment().

Member Data Documentation

◆ m_len

size_t GrowBuf::m_len
private

◆ m_pos

size_t GrowBuf::m_pos
private

◆ m_str

char* GrowBuf::m_str
private

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