Bsoft  2.1.0
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:
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  Bstring common(const Bstring& s);
77  void fill(const char c);
78  void place(long i, const Bstring& s);
79  Bstring lower();
80  Bstring upper();
81  Bstring substr(long start, long len);
82  Bstring no_space();
83  Bstring no_lead_space();
84  Bstring alnum();
85  Bstring left(long len);
86  Bstring right(long len);
87  Bstring pre(char c);
88  Bstring post(char c);
89  Bstring pre_rev(char c);
90  Bstring post_rev(char c);
91  Bstring within(char c1, char c2);
92  Bstring replace(char cold, char cnew);
93  Bstring remove(const char c);
94  Bstring swap(const long i, const long j);
95  Bstring erase(const long i);
96  Bstring truncate(const long n);
97  Bstring base();
99  Bstring canonical(int n);
100  long integer();
101  double real();
102  long index(const char c) { return index(c, 0); }
103  long index(const char c, long start);
104  long find(const Bstring& s) { return find(s, 0); }
105  long find(const Bstring& s, long start);
106  long rfind(const Bstring& s) { return rfind(s, 0); }
107  long rfind(const Bstring& s, long start);
108  bool contains(const Bstring& s);
109  Bstring insert(long pos, const Bstring& s);
110  Bstring* split();
111  Bstring* split(const Bstring& delim);
112  vector<long> split_into_integers(const Bstring& delim);
113  vector<double> split_into_doubles(const Bstring& delim);
114  friend Bstring operator+(const char* c, const Bstring& s);
115 };
116 
117 //template Bstring::Bstring(long, const char*);
118 
119 #endif
120 
121 istream& operator>>(istream& input, Bstring& s);
122 ostream& operator<<(ostream& output, Bstring& s);
123 
124 // Function prototypes
125 Bstring* string_add(Bstring** list, const char* string);
126 Bstring* string_add(Bstring** list, Bstring& string);
128 int string_kill(Bstring* list);
130 int string_sort(Bstring* slist, int descending, int value);
131 
Bstring::Bstring
Bstring(T value, const char *format)
Definition: Bstring.h:44
operator<<
ostream & operator<<(ostream &output, Bstring &s)
Definition: Bstring.cpp:702
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
replace
int replace(fstream *fin, char *rstring1, char *rstring2)
Definition: bfile.cpp:409
Bstring::index
long index(const char c)
Definition: Bstring.h:102
Bstring
Definition: Bstring.h:29
base
string base(string &filename)
Definition: string_util.cpp:28
Bstring::~Bstring
~Bstring()
Definition: Bstring.h:52
parameter_file_path
Bstring parameter_file_path(Bstring filename)
Finds the parameter file path.
Definition: Bstring.cpp:795
Bstring::empty
bool empty()
Definition: Bstring.h:71
length
double length(vector< T > v)
Definition: Vector3.h:530
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
operator+=
void operator+=(vector< T1 > &v1, vector< T2 > v2)
Definition: Vector3.h:387
string_catenate
Bstring string_catenate(Bstring *list)
Catenates a string linked list into one string.
Definition: Bstring.cpp:747
Bstring::str
string str()
Definition: Bstring.h:42
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
Bstring::rfind
long rfind(const Bstring &s)
Definition: Bstring.h:106
Bstring::find
long find(const Bstring &s)
Definition: Bstring.h:104
MAX_FORMAT_SIZE
#define MAX_FORMAT_SIZE
Definition: Bstring.h:18
split
vector< string > split(const string &s)
Splits a string on whitespace.
Definition: string_util.cpp:92
Bstring::next
Bstring * next
Definition: Bstring.h:31
operator>>
istream & operator>>(istream &input, Bstring &s)
Definition: Bstring.cpp:695
extension
string extension(string filename)
Definition: string_util.cpp:32
operator+
vector< T1 > operator+(vector< T1 > v1, vector< T2 > v2)
Definition: Vector3.h:365
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:883
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
Bstring::Bstring
Bstring()
Definition: Bstring.h:35