Skip to main content

The VhdlString Class Reference

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

Declaration

class VhdlString { ... }

Included Headers

Public Constructors Index

VhdlString ()
VhdlString (const VhdlString &other)
VhdlString (const char *s)
VhdlString (const char *s, int size)

Public Destructor Index

~VhdlString ()

Public Operators Index

VhdlString &operator= (const VhdlString &other)
char &operator[] (int i)
const char &operator[] (int i) const
VhdlString &operator+= (char c)
VhdlString &operator+= (const char *s)
VhdlString &operator+= (VhdlString s)
VhdlStringoperator+ (const char *s)

Public Member Functions Index

VhdlString &append (const char *s, int size)
VhdlString &append (const char *s)
VhdlString &append (const VhdlString &other)
VhdlStringsubstr (int pos=0, int len=-1)
intcopy (char *s, int len, int pos=0) const
const char *c_str () const
const char *data () const
intsize () const
intlength () const
voidclear ()

Private Member Functions Index

voidinit ()

Private Member Attributes Index

char *m_str
intm_len

Description

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

Definition at line 33 of file vhdlstring.h.

Public Constructors

VhdlString()

VhdlString::VhdlString ()
inline

Definition at line 36 of file vhdlstring.h.

37 {
38 init();
39 }

Reference init.

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

VhdlString()

VhdlString::VhdlString (const VhdlString & other)
inline

Definition at line 40 of file vhdlstring.h.

40 VhdlString(const VhdlString &other)
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 }

References m_len, m_str and VhdlString.

VhdlString()

VhdlString::VhdlString (const char * s)
inline

Definition at line 59 of file vhdlstring.h.

59 VhdlString(const char *s)
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()

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

Definition at line 65 of file vhdlstring.h.

65 VhdlString(const char *s,int size)
66 {
67 m_str = (char*)malloc(size+1);
68 memcpy(m_str,s,size);
69 m_str[size]=0;
71 }

References m_len, m_str and size.

Public Destructor

~VhdlString()

VhdlString::~VhdlString ()
inline

Definition at line 72 of file vhdlstring.h.

73 {
74 free(m_str);
75 }

Reference m_str.

Public Operators

operator[]()

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

Definition at line 112 of file vhdlstring.h.

112 char & operator[](int i) { return m_str[i]; }

Reference m_str.

operator[]()

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

Definition at line 113 of file vhdlstring.h.

113 const char &operator[](int i) const { return m_str[i]; }

Reference m_str.

operator+()

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

Definition at line 118 of file vhdlstring.h.

118 VhdlString operator+(const char *s) { return append(s); }

References append and VhdlString.

operator+=()

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

Definition at line 115 of file vhdlstring.h.

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

References append and VhdlString.

operator+=()

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

Definition at line 116 of file vhdlstring.h.

116 VhdlString &operator+=(const char *s) { return append(s); }

References append and VhdlString.

operator+=()

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

Definition at line 117 of file vhdlstring.h.

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.

Public Member Functions

append()

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

Definition at line 76 of file vhdlstring.h.

76 VhdlString& append(const char *s,int size)
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()

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

Definition at line 88 of file vhdlstring.h.

88 VhdlString& append(const char *s)
89 {
90 return append(s,(int)strlen(s));
91 }

References append and VhdlString.

append()

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 ()
inline

Definition at line 108 of file vhdlstring.h.

108 const char *c_str() const { return m_str; }

Reference m_str.

clear()

void VhdlString::clear ()
inline

Definition at line 114 of file vhdlstring.h.

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

References init and m_str.

copy()

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

Definition at line 100 of file vhdlstring.h.

100 int copy(char *s,int len,int pos=0) const
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 ()
inline

Definition at line 109 of file vhdlstring.h.

109 const char *data() const { return m_str; }

Reference m_str.

length()

int VhdlString::length ()
inline

Definition at line 111 of file vhdlstring.h.

111 int length() const { return m_len; }

Reference m_len.

size()

int VhdlString::size ()
inline

Definition at line 110 of file vhdlstring.h.

110 int size() const { return m_len; }

Reference 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.

96 VhdlString substr(int pos=0,int len=-1)
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.

Private Member Functions

init()

void VhdlString::init ()
inline

Definition at line 121 of file vhdlstring.h.

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

References m_len and m_str.

Referenced by clear and VhdlString.

Private Member Attributes

m_len

int VhdlString::m_len

Definition at line 123 of file vhdlstring.h.

123 int m_len;

Referenced by append, append, copy, init, length, operator=, size, substr, VhdlString, VhdlString and VhdlString.

m_str

char* VhdlString::m_str

Definition at line 122 of file vhdlstring.h.

122 char *m_str;

Referenced by append, append, c_str, clear, copy, data, init, operator=, operator[], operator[], substr, VhdlString, VhdlString, VhdlString and ~VhdlString.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.