File: mystring.hpp

package info (click to toggle)
netgen 6.2.2601%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,076 kB
  • sloc: cpp: 166,627; tcl: 6,310; python: 2,868; sh: 528; makefile: 90
file content (226 lines) | stat: -rw-r--r-- 4,888 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

//**************************************************************
//
// filename:             mystring.h
//
// project:              doctoral thesis, program smart
//
// author:               Dipl.-Ing. Gerstmayr Johannes
//
// generated:            20.12.98
// last change:          20.12.98
// description:          base class for strings
// remarks:              string with n characters has
//                       0..n-1 characters and at pos n a 0
//
//**************************************************************


#ifndef MYSTRING__H
#define MYSTRING__H

#include <filesystem>

namespace netgen
{

class Point3d;
class Vec3d;


// extract string str which is enclosed by the given character encl from a given string in
void ReadEnclString(istream & in, string & str, const char encl);


class MyStr;

DLL_HEADER MyStr operator + (const MyStr &, const MyStr &);
DLL_HEADER int operator == (const MyStr &, const MyStr &);
DLL_HEADER int operator < (const MyStr &, const MyStr &);
DLL_HEADER int operator <= (const MyStr &, const MyStr &);
DLL_HEADER int operator > (const MyStr &, const MyStr &);
DLL_HEADER int operator >= (const MyStr &, const MyStr &);
DLL_HEADER int operator != (const MyStr &, const MyStr &);
DLL_HEADER ostream& operator << (ostream &, const MyStr &);
DLL_HEADER istream& operator >> (istream &, MyStr &);

class DLL_HEADER MyStr
{
public:
  MyStr();
  MyStr(const char *);
  MyStr(char);
  MyStr(const MyStr &);
  MyStr(int);
  MyStr(size_t);
  MyStr(void *);
  // MyStr(long);
  // MyStr(unsigned long);
  MyStr(double);
  MyStr(const Point3d& p);
  MyStr(const Vec3d& p);
  MyStr(const string & st);
  MyStr(string_view sv);
  MyStr(const filesystem::path & st);

  ~MyStr();
  MyStr Left(unsigned);
  MyStr Right(unsigned);
  MyStr& InsertAt(unsigned, const MyStr &);
  MyStr& WriteAt(unsigned, const MyStr &);
  unsigned Length() const;
  int Find(const char);
  int Find(const char *);
  int Find(const MyStr &);
  MyStr& operator = (const MyStr &);
  DLL_HEADER friend MyStr operator + (const MyStr &, const MyStr &);
  void operator += (const MyStr &);
  char* c_str();
  string cpp_string(void) const;

  //change every ',' -> ';', '.' -> ','
  void ConvertTextToExcel();
  //change every ','->'.', ';'->','
  void ConvertExcelToText();

  MyStr operator () (unsigned, unsigned);
  operator int();
  operator double();
  operator long();
  operator char *();
  char& operator [] (unsigned int);
  char operator [] (unsigned int) const;

  DLL_HEADER friend int operator == (const MyStr &, const MyStr &);
  DLL_HEADER friend int operator < (const MyStr &, const MyStr &);
  DLL_HEADER friend int operator <= (const MyStr &, const MyStr &);
  DLL_HEADER friend int operator > (const MyStr &, const MyStr &);
  DLL_HEADER friend int operator >= (const MyStr &, const MyStr &);
  DLL_HEADER friend int operator != (const MyStr &, const MyStr &);
  DLL_HEADER friend ostream& operator << (ostream &, const MyStr &);
  DLL_HEADER friend istream& operator >> (istream &, MyStr &);
  static void SetToErrHandler(void (*)());
private:
  MyStr(unsigned, int);
  char *str;
  unsigned length;
  enum { SHORTLEN = 24 };
  char shortstr[SHORTLEN+1];
  static void(*ErrHandler)();
};


inline MyStr::MyStr()
{
  length = 0;
  str = shortstr;
  str[0] = 0;
}

inline MyStr::MyStr(char s)
{
  length = 1;
  str = shortstr;
  str[0] = s;
  str[1] = (char)0;
}

inline MyStr::~MyStr()
{
  if (length > SHORTLEN)
    delete [] str;
}

inline unsigned MyStr::Length() const
{
  return length;
}

inline int MyStr::Find(const char c)
{
  char *pos = strchr(str, int(c));
  return pos ? int(pos - str) : -1;
}

inline int MyStr::Find(const MyStr &s)
{
  char *pos = strstr(str, s.str);
  return pos ? int(pos - str) : -1;
}

inline int MyStr::Find(const char *s)
{
  char *pos = strstr(str, s);
  return pos ? int(pos - str) : -1;
}

inline MyStr::operator int()
{
  return atoi(str);
}

inline MyStr::operator double()
{
  return atof(str);
}

inline MyStr::operator long()
{
  return atol(str);
}

inline MyStr::operator char *()
{
  return str;
}

inline char* MyStr::c_str()
{
  return str;
}


inline int operator == (const MyStr &s1, const MyStr& s2)
{
  return strcmp(s1.str, s2.str) == 0;
}

inline int operator < (const MyStr &s1, const MyStr& s2)
{
  return strcmp(s1.str, s2.str) < 0;
}

inline int operator <= (const MyStr &s1, const MyStr& s2)
{
  return strcmp(s1.str, s2.str) <= 0;
}

inline int operator > (const MyStr &s1, const MyStr& s2)
{
  return strcmp(s1.str, s2.str) > 0;
}

inline int operator >= (const MyStr &s1, const MyStr& s2)
{
  return strcmp(s1.str, s2.str) >= 0;
}

inline int operator != (const MyStr &s1, const MyStr& s2)
{
  return !(s1 == s2);
}

inline ostream& operator << (ostream& os, const MyStr& s)
{
  return os << s.str;
}

inline void MyStr::SetToErrHandler(void (*Handler)())
{
  ErrHandler = Handler;
};

}
#endif