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

Minimal string class with std::string like behavior that fulfills the JavaCC string requirements. More...

#include <vhdlparser/vhdlstring.h>

Public Member Functions

 VhdlString ()
 
 VhdlString (const VhdlString &other)
 
VhdlStringoperator= (const VhdlString &other)
 
 VhdlString (const char *s)
 
 VhdlString (const char *s, int size)
 
 ~VhdlString ()
 
VhdlStringappend (const char *s, int size)
 
VhdlStringappend (const char *s)
 
VhdlStringappend (const VhdlString &other)
 
VhdlString substr (int pos=0, int len=-1)
 
int copy (char *s, int len, int pos=0) const
 
const char * c_str () const
 
const char * data () const
 
int size () const
 
int length () const
 
char & operator[] (int i)
 
const char & operator[] (int i) const
 
void clear ()
 
VhdlStringoperator+= (char c)
 
VhdlStringoperator+= (const char *s)
 
VhdlStringoperator+= (VhdlString s)
 
VhdlString operator+ (const char *s)
 

Private Member Functions

void init ()
 

Private Attributes

char * m_str
 
int m_len
 

Detailed Description

Minimal string class with std::string like behavior that fulfills the JavaCC string requirements.

Definition at line 33 of file vhdlstring.h.

Constructor & Destructor Documentation

◆ VhdlString() [1/4]

VhdlString::VhdlString ( )
inline

Definition at line 36 of file vhdlstring.h.

37 {
38 init();
39 }
void init()
Definition vhdlstring.h:121

References init().

Referenced by append(), append(), append(), operator+(), operator+=(), operator+=(), operator+=(), operator=(), substr(), and VhdlString().

◆ VhdlString() [2/4]

VhdlString::VhdlString ( const VhdlString & other)
inline

Definition at line 40 of file vhdlstring.h.

41 {
42 m_str = (char*)malloc(other.m_len+1);
43 memcpy(m_str,other.m_str,other.m_len);
44 m_len = other.m_len;
45 m_str[m_len]=0;
46 }
char * m_str
Definition vhdlstring.h:122

References m_len, m_str, and VhdlString().

◆ VhdlString() [3/4]

VhdlString::VhdlString ( const char * s)
inline

Definition at line 59 of file vhdlstring.h.

60 {
61 m_len = (int)strlen(s);
62 m_str=(char*)malloc(m_len+1);
63 memcpy(m_str,s,m_len+1);
64 }

References m_len, and m_str.

◆ VhdlString() [4/4]

VhdlString::VhdlString ( const char * s,
int size )
inline

Definition at line 65 of file vhdlstring.h.

66 {
67 m_str = (char*)malloc(size+1);
68 memcpy(m_str,s,size);
69 m_str[size]=0;
70 m_len=size;
71 }
int size() const
Definition vhdlstring.h:110

References m_len, m_str, and size().

◆ ~VhdlString()

VhdlString::~VhdlString ( )
inline

Definition at line 72 of file vhdlstring.h.

73 {
74 free(m_str);
75 }

References m_str.

Member Function Documentation

◆ append() [1/3]

VhdlString & VhdlString::append ( const char * s)
inline

Definition at line 88 of file vhdlstring.h.

89 {
90 return append(s,(int)strlen(s));
91 }
VhdlString & append(const char *s, int size)
Definition vhdlstring.h:76

References append(), and VhdlString().

◆ append() [2/3]

VhdlString & VhdlString::append ( const char * s,
int size )
inline

Definition at line 76 of file vhdlstring.h.

77 {
78 int oldlen = m_len;
79 m_len+=size+1;
80 if (m_len)
81 {
82 m_str = (char*)realloc(m_str,m_len);
83 memcpy(m_str+oldlen,s,m_len-oldlen-1);
84 m_str[m_len-1]=0;
85 }
86 return *this;
87 }

References m_len, m_str, size(), and VhdlString().

Referenced by append(), append(), operator+(), operator+(), operator+=(), operator+=(), and operator+=().

◆ append() [3/3]

VhdlString & VhdlString::append ( const VhdlString & other)
inline

Definition at line 92 of file vhdlstring.h.

93 {
94 return append(other.m_str,other.m_len);
95 }

References append(), m_len, m_str, and VhdlString().

◆ c_str()

const char * VhdlString::c_str ( ) const
inline

Definition at line 108 of file vhdlstring.h.

108{ return m_str; }

References m_str.

◆ clear()

void VhdlString::clear ( )
inline

Definition at line 114 of file vhdlstring.h.

114{ free(m_str); init(); }

References init(), and m_str.

◆ copy()

int VhdlString::copy ( char * s,
int len,
int pos = 0 ) const
inline

Definition at line 100 of file vhdlstring.h.

101 {
102 if (len==0) return 0;
103 if (pos>=m_len) { s[0]=0; return 0; }
104 int r=m_len<pos+len ? m_len-pos : len;
105 memcpy(s,m_str+pos,r);
106 return r;
107 }

References m_len, and m_str.

◆ data()

const char * VhdlString::data ( ) const
inline

Definition at line 109 of file vhdlstring.h.

109{ return m_str; }

References m_str.

◆ init()

void VhdlString::init ( )
inlineprivate

Definition at line 121 of file vhdlstring.h.

121{ m_str=(char*)calloc(1,1); m_len=0; }

References m_len, and m_str.

Referenced by clear(), and VhdlString().

◆ length()

int VhdlString::length ( ) const
inline

Definition at line 111 of file vhdlstring.h.

111{ return m_len; }

References m_len.

◆ operator+()

VhdlString VhdlString::operator+ ( const char * s)
inline

Definition at line 118 of file vhdlstring.h.

118{ return append(s); }

References append(), and VhdlString().

◆ operator+=() [1/3]

VhdlString & VhdlString::operator+= ( char c)
inline

Definition at line 115 of file vhdlstring.h.

115{ char s[2]; s[0]=c; s[1]=0; return append(s); }

References append(), and VhdlString().

◆ operator+=() [2/3]

VhdlString & VhdlString::operator+= ( const char * s)
inline

Definition at line 116 of file vhdlstring.h.

116{ return append(s); }

References append(), and VhdlString().

◆ operator+=() [3/3]

VhdlString & VhdlString::operator+= ( VhdlString s)
inline

Definition at line 117 of file vhdlstring.h.

117{ return append(s); }

References append(), and VhdlString().

◆ operator=()

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

Definition at line 47 of file vhdlstring.h.

48 {
49 if (this!=&other)
50 {
51 free(m_str);
52 m_str = (char*)malloc(other.m_len+1);
53 memcpy(m_str,other.m_str,other.m_len);
54 m_len = other.m_len;
55 m_str[m_len]=0;
56 }
57 return *this;
58 }

References m_len, m_str, and VhdlString().

◆ operator[]() [1/2]

char & VhdlString::operator[] ( int i)
inline

Definition at line 112 of file vhdlstring.h.

112{ return m_str[i]; }

References m_str.

◆ operator[]() [2/2]

const char & VhdlString::operator[] ( int i) const
inline

Definition at line 113 of file vhdlstring.h.

113{ return m_str[i]; }

References m_str.

◆ size()

int VhdlString::size ( ) const
inline

Definition at line 110 of file vhdlstring.h.

110{ return m_len; }

References m_len.

Referenced by append(), and VhdlString().

◆ substr()

VhdlString VhdlString::substr ( int pos = 0,
int len = -1 )
inline

Definition at line 96 of file vhdlstring.h.

97 {
98 return VhdlString(m_str ? m_str+pos : nullptr, len==-1 ? m_len-pos : m_len);
99 }

References m_len, m_str, and VhdlString().

Member Data Documentation

◆ m_len

int VhdlString::m_len
private

◆ m_str

char* VhdlString::m_str
private

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