summaryrefslogtreecommitdiffstats
path: root/vhdlparser/vhdlstring.h
diff options
context:
space:
mode:
authorDimitri van Heesch <dimitri@stack.nl>2014-07-27 14:31:34 (GMT)
committerDimitri van Heesch <dimitri@stack.nl>2014-08-02 10:05:26 (GMT)
commit36122e49ed1d9e640b1ceca52536ec7c55e10474 (patch)
treec61b21164b0445eb23631aa812810f4712cd8f61 /vhdlparser/vhdlstring.h
parent6a60477b418e21dbadd3e62dc557a038e319581b (diff)
downloadDoxygen-36122e49ed1d9e640b1ceca52536ec7c55e10474.zip
Doxygen-36122e49ed1d9e640b1ceca52536ec7c55e10474.tar.gz
Doxygen-36122e49ed1d9e640b1ceca52536ec7c55e10474.tar.bz2
New VHDL parser implementation
Diffstat (limited to 'vhdlparser/vhdlstring.h')
-rw-r--r--vhdlparser/vhdlstring.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/vhdlparser/vhdlstring.h b/vhdlparser/vhdlstring.h
new file mode 100644
index 0000000..16e1d9a
--- /dev/null
+++ b/vhdlparser/vhdlstring.h
@@ -0,0 +1,100 @@
+#ifndef VHDLSTRING_H
+#define VHDLSTRING_H
+
+#include <stdio.h>
+#include <string.h>
+
+/** @brief Minimal string class with std::string like behaviour that fulfills the JavaCC
+ * string requirements.
+ */
+class VhdlString
+{
+ public:
+ VhdlString()
+ {
+ init();
+ }
+ VhdlString(const VhdlString &other)
+ {
+ m_str = (char*)malloc(other.m_len+1);
+ memcpy(m_str,other.m_str,other.m_len);
+ m_len = other.m_len;
+ m_str[m_len]=0;
+ }
+ VhdlString &operator=(const VhdlString &other)
+ {
+ if (this!=&other)
+ {
+ free(m_str);
+ m_str = (char*)malloc(other.m_len+1);
+ memcpy(m_str,other.m_str,other.m_len);
+ m_len = other.m_len;
+ m_str[m_len]=0;
+ }
+ return *this;
+ }
+ VhdlString(const char *s)
+ {
+ m_len = strlen(s);
+ m_str=(char*)malloc(m_len+1);
+ memcpy(m_str,s,m_len+1);
+ }
+ VhdlString(const char *s,int size)
+ {
+ m_str = (char*)malloc(size+1);
+ memcpy(m_str,s,size);
+ m_str[size]=0;
+ m_len=size;
+ }
+ ~VhdlString()
+ {
+ delete[] m_str;
+ }
+ VhdlString& append(const char *s,int size)
+ {
+ int oldlen = m_len;
+ m_len+=size+1;
+ if (m_len)
+ {
+ m_str = (char*)realloc(m_str,m_len);
+ memcpy(m_str+oldlen,s,m_len-oldlen-1);
+ m_str[m_len-1]=0;
+ }
+ return *this;
+ }
+ VhdlString& append(const char *s)
+ {
+ return append(s,strlen(s));
+ }
+ VhdlString& append(const VhdlString &other)
+ {
+ return append(other.m_str,other.m_len);
+ }
+ VhdlString substr(int pos=0,int len=-1)
+ {
+ return VhdlString(m_str?m_str+pos:0,len==-1?m_len-pos:m_len);
+ }
+ int copy(char *s,int len,int pos=0) const
+ {
+ if (len==0) return 0;
+ if (pos>=m_len) { s[0]=0; return 0; }
+ int r=m_len<pos+len ? m_len-pos : len;
+ memcpy(s,m_str+pos,r);
+ return r;
+ }
+ const char *c_str() const { return m_str; }
+ const char *data() const { return m_str; }
+ int size() const { return m_len; }
+ int length() const { return m_len; }
+ char & operator[](int i) { return m_str[i]; }
+ const char &operator[](int i) const { return m_str[i]; }
+ void clear() { free(m_str); init(); }
+ VhdlString operator+=(char c) { char s[2]; s[0]=c; s[1]=0; return append(s); }
+
+ private:
+ void init() { m_str=(char*)calloc(1,1); m_len=0; }
+ char *m_str;
+ int m_len;
+};
+
+#endif