Doxygen
Loading...
Searching...
No Matches
vhdlstring.h
Go to the documentation of this file.
1#ifndef VHDLSTRING_H
2#define VHDLSTRING_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include "VhdlParser.h"
9// super class for VhdlParserTokenManager
10// is generated in vhdlparser.jj
11// -option TOKEN_MANAGER_SUPER_CLASS = "TokenParser"
12// sets the Vhdlparser in vhdljjparser.cpp
13// tokenManager->setLexParser(vhdlParser);
14
15namespace vhdl {
16 namespace parser {
18 public:
19 VhdlParser* parser = nullptr;
21 {
22 parser = p;
23 }
24 };
25 }
26}
27
28
29/** @brief Minimal string class with std::string like behavior that fulfills the JavaCC
30 * string requirements.
31 */
32
34{
35 public:
37 {
38 init();
39 }
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 }
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 }
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 }
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;
70 m_len=size;
71 }
73 {
74 free(m_str);
75 }
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 }
88 VhdlString& append(const char *s)
89 {
90 return append(s,(int)strlen(s));
91 }
93 {
94 return append(other.m_str,other.m_len);
95 }
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 }
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 }
108 const char *c_str() const { return m_str; }
109 const char *data() const { return m_str; }
110 int size() const { return m_len; }
111 int length() const { return m_len; }
112 char & operator[](int i) { return m_str[i]; }
113 const char &operator[](int i) const { return m_str[i]; }
114 void clear() { free(m_str); init(); }
115 VhdlString &operator+=(char c) { char s[2]; s[0]=c; s[1]=0; return append(s); }
116 VhdlString &operator+=(const char *s) { return append(s); }
118 VhdlString operator+ (const char *s) { return append(s); }
119
120 private:
121 void init() { m_str=(char*)calloc(1,1); m_len=0; }
122 char *m_str;
123 int m_len;
124};
125
126inline VhdlString operator+ (const char *s, VhdlString v) { return VhdlString(s).append(v); }
127
128#endif
Minimal string class with std::string like behavior that fulfills the JavaCC string requirements.
Definition vhdlstring.h:34
int length() const
Definition vhdlstring.h:111
VhdlString & operator=(const VhdlString &other)
Definition vhdlstring.h:47
VhdlString & operator+=(const char *s)
Definition vhdlstring.h:116
char & operator[](int i)
Definition vhdlstring.h:112
VhdlString & operator+=(VhdlString s)
Definition vhdlstring.h:117
int size() const
Definition vhdlstring.h:110
void clear()
Definition vhdlstring.h:114
VhdlString operator+(const char *s)
Definition vhdlstring.h:118
VhdlString & append(const char *s, int size)
Definition vhdlstring.h:76
const char * c_str() const
Definition vhdlstring.h:108
const char & operator[](int i) const
Definition vhdlstring.h:113
VhdlString & operator+=(char c)
Definition vhdlstring.h:115
VhdlString & append(const char *s)
Definition vhdlstring.h:88
VhdlString(const VhdlString &other)
Definition vhdlstring.h:40
const char * data() const
Definition vhdlstring.h:109
VhdlString(const char *s, int size)
Definition vhdlstring.h:65
VhdlString substr(int pos=0, int len=-1)
Definition vhdlstring.h:96
VhdlString(const char *s)
Definition vhdlstring.h:59
VhdlString & append(const VhdlString &other)
Definition vhdlstring.h:92
int copy(char *s, int len, int pos=0) const
Definition vhdlstring.h:100
void init()
Definition vhdlstring.h:121
char * m_str
Definition vhdlstring.h:122
void setLexParser(VhdlParser *p)
Definition vhdlstring.h:20
Token literal values and constants.
Definition CharStream.h:12
VhdlString operator+(const char *s, VhdlString v)
Definition vhdlstring.h:126