| Bsoft 2.0.5 Bernard's software package

Bstring.h
Go to the documentation of this file.
1
9 #include <iostream>
10 #include <cstdio>
11 #include <vector>
12
13 using namespace std;
14
15 #ifndef _Bstring_
16 #define _Bstring_
17
18 #define MAX_FORMAT_SIZE 64
19
20 /************************************************************************
21 @Object: class Bstring
22 @Description:
23 Bsoft linkable string class.
24 @Features:
25 The variables are a public pointer to the next string and a private
26 pointer to a character string.
27 The string data are allocated internally.
28 *************************************************************************/
29 class Bstring {
30 public:
31 Bstring* next;
32 private:
33 char* data;
34 public:
35 Bstring() { data = NULL; next = NULL; }
36 Bstring(const Bstring& s);
37 Bstring(const string& s);
38 Bstring(const Bstring& s, long start, long len);
39 Bstring(const char* c);
40 Bstring(const char* c, long start, long len);
41 Bstring(const char c, long size);
42 string str() { return string(data); }
43 template <typename T>
44 Bstring(T value, const char* format) {
45 data = NULL;
46 char* temp = new char[MAX_FORMAT_SIZE];
47 ::snprintf(temp, MAX_FORMAT_SIZE, format, value);
48 *this = temp;
49 delete[] temp;
50 next = NULL;
51 }
52 ~Bstring() { delete[] data; data = NULL; }
53 Bstring& operator=(const Bstring& s);
54 Bstring& operator=(const string& s);
55 Bstring& operator=(const char* c);
56 Bstring& operator+=(const Bstring& s);
57 Bstring operator+(const Bstring& s);
58 Bstring operator+(const Bstring& s) const;
59 Bstring& operator+=(const char c);
60 Bstring operator+(const char c);
61 bool operator==(const Bstring& s);
62 bool operator!=(const Bstring& s);
63 bool operator>(const Bstring& s);
64 bool operator<(const Bstring& s);
65 bool operator>=(const Bstring& s);
66 bool operator<=(const Bstring& s);
67 Bstring operator<<(int n);
68 Bstring operator>>(int n);
69 char& operator[](long i);
70 const char* c_str() { return (const char*)data; }
71 bool empty() { return data == NULL; }
72 long length() const;
73 long count(const char c);
74 long compare(const Bstring& s);
75 long compare_value(const Bstring& s);
76 void fill(const char c);
77 void place(long i, const Bstring& s);
78 Bstring lower();
79 Bstring upper();
80 Bstring substr(long start, long len);
81 Bstring no_space();
82 Bstring no_lead_space();
83 Bstring alnum();
84 Bstring left(long len);
85 Bstring right(long len);
86 Bstring pre(char c);
87 Bstring post(char c);
88 Bstring pre_rev(char c);
89 Bstring post_rev(char c);
90 Bstring within(char c1, char c2);
91 Bstring replace(char cold, char cnew);
92 Bstring remove(const char c);
93 Bstring swap(const long i, const long j);
94 Bstring erase(const long i);
95 Bstring truncate(const long n);
96 Bstring base();
97 Bstring extension();
98 Bstring canonical(int n);
99 long integer();
100 double real();
101 long index(const char c) { return index(c, 0); }
102 long index(const char c, long start);
103 long find(const Bstring& s) { return find(s, 0); }
104 long find(const Bstring& s, long start);
105 long rfind(const Bstring& s) { return rfind(s, 0); }
106 long rfind(const Bstring& s, long start);
107 bool contains(const Bstring& s);
108 Bstring insert(long pos, const Bstring& s);
109 Bstring* split();
110 Bstring* split(const Bstring& delim);
111 vector<long> split_into_integers(const Bstring& delim);
112 vector<double> split_into_doubles(const Bstring& delim);
113 friend Bstring operator+(const char* c, const Bstring& s);
114 };
115
116 //template Bstring::Bstring(long, const char*);
117
118 #endif
119
120 istream& operator>>(istream& input, Bstring& s);
121 ostream& operator<<(ostream& output, Bstring& s);
122
123 // Function prototypes
124 Bstring* string_add(Bstring** list, const char* string);
125 Bstring* string_add(Bstring** list, Bstring& string);
126 Bstring string_catenate(Bstring* list);
127 int string_kill(Bstring* list);
128 Bstring parameter_file_path(Bstring filename);
129 int string_sort(Bstring* slist, int descending, int value);
130
extension
string extension(string filename)
Definition: string_util.cpp:32
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
replace
int replace(fstream *fin, char *rstring1, char *rstring2)
Definition: bfile.cpp:409
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
Bstring::find
long find(const Bstring &s)
Definition: Bstring.h:103
Bstring::rfind
long rfind(const Bstring &s)
Definition: Bstring.h:105
operator+
vector< T1 > operator+(vector< T1 > v1, vector< T2 > v2)
Definition: Vector3.h:363
parameter_file_path
Bstring parameter_file_path(Bstring filename)
Finds the parameter file path.
Definition: Bstring.cpp:787
base
string base(string &filename)
Definition: string_util.cpp:28
Bstring::next
Bstring * next
Definition: Bstring.h:31
length
double length(vector< T > v)
Definition: Vector3.h:528
operator+=
void operator+=(vector< T1 > &v1, vector< T2 > v2)
Definition: Vector3.h:385
string_catenate
Bstring string_catenate(Bstring *list)
Catenates a string linked list into one string.
Definition: Bstring.cpp:739
MAX_FORMAT_SIZE
#define MAX_FORMAT_SIZE
Definition: Bstring.h:18
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bstring::Bstring
Bstring()
Definition: Bstring.h:35
Bstring::Bstring
Bstring(T value, const char *format)
Definition: Bstring.h:44
operator>>
istream & operator>>(istream &input, Bstring &s)
Definition: Bstring.cpp:687
Bstring
Definition: Bstring.h:29
operator<<
ostream & operator<<(ostream &output, Bstring &s)
Definition: Bstring.cpp:694
split
vector< string > split(const string &s)
Splits a string on whitespace.
Definition: string_util.cpp:92
Bstring::index
long index(const char c)
Definition: Bstring.h:101
Bstring::empty
bool empty()
Definition: Bstring.h:71
Bstring::~Bstring
~Bstring()
Definition: Bstring.h:52
Bstring::str
string str()
Definition: Bstring.h:42
string_sort
int string_sort(Bstring *slist, int descending, int value)
Sorts a list of strings in ascending (descending) lexical or value order.
Definition: Bstring.cpp:875
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760