netgen/libsrc/general/mystring.hpp

227 lines
4.8 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
//**************************************************************
//
// filename: mystring.h
//
// project: doctoral thesis, program smart
//
2017-12-05 02:32:47 +05:00
// author: Dipl.-Ing. Gerstmayr Johannes
2009-01-13 04:40:13 +05:00
//
// 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
2022-02-17 20:52:07 +05:00
#include <filesystem>
2009-07-20 14:36:36 +06:00
namespace netgen
{
2009-01-13 04:40:13 +05:00
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;
2012-10-29 23:45:15 +06:00
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
2009-01-13 04:40:13 +05:00
{
public:
2012-10-29 23:45:15 +06:00
MyStr();
MyStr(const char *);
MyStr(char);
MyStr(const MyStr &);
MyStr(int);
2018-03-15 23:19:48 +05:00
MyStr(size_t);
2012-10-29 23:45:15 +06:00
MyStr(void *);
2018-03-15 23:19:48 +05:00
// MyStr(long);
// MyStr(unsigned long);
2012-10-29 23:45:15 +06:00
MyStr(double);
MyStr(const Point3d& p);
MyStr(const Vec3d& p);
MyStr(const string & st);
MyStr(string_view sv);
2022-02-17 20:52:07 +05:00
MyStr(const filesystem::path & st);
2009-01-13 04:40:13 +05:00
~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 &);
2013-04-05 19:08:07 +06:00
DLL_HEADER friend MyStr operator + (const MyStr &, const MyStr &);
2009-01-13 04:40:13 +05:00
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;
2013-04-05 19:08:07 +06:00
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 &);
2009-01-13 04:40:13 +05:00
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;
};
2009-07-20 14:36:36 +06:00
}
2009-01-13 04:40:13 +05:00
#endif