Public Member Functions | Private Member Functions | Private Attributes | List of all members
VhdlString Class Reference

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

#include <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)
 

Private Member Functions

void init ()
 

Private Attributes

char * m_str
 
int m_len
 

Detailed Description

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

Definition at line 12 of file vhdlstring.h.

Constructor & Destructor Documentation

VhdlString::VhdlString ( )
inline

Definition at line 15 of file vhdlstring.h.

16  {
17  init();
18  }
void init()
Definition: vhdlstring.h:98
VhdlString::VhdlString ( const VhdlString other)
inline

Definition at line 19 of file vhdlstring.h.

20  {
21  m_str = (char*)malloc(other.m_len+1);
22  memcpy(m_str,other.m_str,other.m_len);
23  m_len = other.m_len;
24  m_str[m_len]=0;
25  }
char * m_str
Definition: vhdlstring.h:99
VhdlString::VhdlString ( const char *  s)
inline

Definition at line 38 of file vhdlstring.h.

39  {
40  m_len = strlen(s);
41  m_str=(char*)malloc(m_len+1);
42  memcpy(m_str,s,m_len+1);
43  }
char * m_str
Definition: vhdlstring.h:99
static QCString * s
Definition: config.cpp:1042
VhdlString::VhdlString ( const char *  s,
int  size 
)
inline

Definition at line 44 of file vhdlstring.h.

45  {
46  m_str = (char*)malloc(size+1);
47  memcpy(m_str,s,size);
48  m_str[size]=0;
49  m_len=size;
50  }
char * m_str
Definition: vhdlstring.h:99
int size() const
Definition: vhdlstring.h:89
static QCString * s
Definition: config.cpp:1042
VhdlString::~VhdlString ( )
inline

Definition at line 51 of file vhdlstring.h.

52  {
53  free(m_str);
54  }
char * m_str
Definition: vhdlstring.h:99

Member Function Documentation

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

Definition at line 55 of file vhdlstring.h.

56  {
57  int oldlen = m_len;
58  m_len+=size+1;
59  if (m_len)
60  {
61  m_str = (char*)realloc(m_str,m_len);
62  memcpy(m_str+oldlen,s,m_len-oldlen-1);
63  m_str[m_len-1]=0;
64  }
65  return *this;
66  }
char * m_str
Definition: vhdlstring.h:99
int size() const
Definition: vhdlstring.h:89
static QCString * s
Definition: config.cpp:1042
VhdlString& VhdlString::append ( const char *  s)
inline

Definition at line 67 of file vhdlstring.h.

68  {
69  return append(s,strlen(s));
70  }
VhdlString & append(const char *s, int size)
Definition: vhdlstring.h:55
static QCString * s
Definition: config.cpp:1042
VhdlString& VhdlString::append ( const VhdlString other)
inline

Definition at line 71 of file vhdlstring.h.

72  {
73  return append(other.m_str,other.m_len);
74  }
char * m_str
Definition: vhdlstring.h:99
VhdlString & append(const char *s, int size)
Definition: vhdlstring.h:55
const char* VhdlString::c_str ( ) const
inline

Definition at line 87 of file vhdlstring.h.

87 { return m_str; }
char * m_str
Definition: vhdlstring.h:99
void VhdlString::clear ( )
inline

Definition at line 93 of file vhdlstring.h.

93 { free(m_str); init(); }
char * m_str
Definition: vhdlstring.h:99
void init()
Definition: vhdlstring.h:98
int VhdlString::copy ( char *  s,
int  len,
int  pos = 0 
) const
inline

Definition at line 79 of file vhdlstring.h.

80  {
81  if (len==0) return 0;
82  if (pos>=m_len) { s[0]=0; return 0; }
83  int r=m_len<pos+len ? m_len-pos : len;
84  memcpy(s,m_str+pos,r);
85  return r;
86  }
char * m_str
Definition: vhdlstring.h:99
static QCString * s
Definition: config.cpp:1042
const char* VhdlString::data ( ) const
inline

Definition at line 88 of file vhdlstring.h.

88 { return m_str; }
char * m_str
Definition: vhdlstring.h:99
void VhdlString::init ( )
inlineprivate

Definition at line 98 of file vhdlstring.h.

98 { m_str=(char*)calloc(1,1); m_len=0; }
char * m_str
Definition: vhdlstring.h:99
int VhdlString::length ( ) const
inline

Definition at line 90 of file vhdlstring.h.

90 { return m_len; }
VhdlString& VhdlString::operator+= ( char  c)
inline

Definition at line 94 of file vhdlstring.h.

94 { char s[2]; s[0]=c; s[1]=0; return append(s); }
VhdlString & append(const char *s, int size)
Definition: vhdlstring.h:55
static QCString * s
Definition: config.cpp:1042
VhdlString& VhdlString::operator+= ( const char *  s)
inline

Definition at line 95 of file vhdlstring.h.

95 { return append(s); }
VhdlString & append(const char *s, int size)
Definition: vhdlstring.h:55
static QCString * s
Definition: config.cpp:1042
VhdlString& VhdlString::operator= ( const VhdlString other)
inline

Definition at line 26 of file vhdlstring.h.

27  {
28  if (this!=&other)
29  {
30  free(m_str);
31  m_str = (char*)malloc(other.m_len+1);
32  memcpy(m_str,other.m_str,other.m_len);
33  m_len = other.m_len;
34  m_str[m_len]=0;
35  }
36  return *this;
37  }
char * m_str
Definition: vhdlstring.h:99
char& VhdlString::operator[] ( int  i)
inline

Definition at line 91 of file vhdlstring.h.

91 { return m_str[i]; }
char * m_str
Definition: vhdlstring.h:99
const char& VhdlString::operator[] ( int  i) const
inline

Definition at line 92 of file vhdlstring.h.

92 { return m_str[i]; }
char * m_str
Definition: vhdlstring.h:99
int VhdlString::size ( ) const
inline

Definition at line 89 of file vhdlstring.h.

89 { return m_len; }
VhdlString VhdlString::substr ( int  pos = 0,
int  len = -1 
)
inline

Definition at line 75 of file vhdlstring.h.

76  {
77  return VhdlString(m_str?m_str+pos:0,len==-1?m_len-pos:m_len);
78  }
char * m_str
Definition: vhdlstring.h:99

Member Data Documentation

int VhdlString::m_len
private

Definition at line 100 of file vhdlstring.h.

char* VhdlString::m_str
private

Definition at line 99 of file vhdlstring.h.


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