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
|
/* Headers
#include <vector>
#include <string>
#include <sstream>
*/
#ifndef VSTRING_HPP
#define VSTRING_HPP
class vstring;
typedef std::vector<vstring> vstringlist;
class vstring
{
std::vector<char> vstr;
void number(std::stringstream &vstream);
public:
typedef std::vector<char>::iterator iterator;
typedef std::vector<char>::const_iterator const_iterator;
typedef std::vector<char>::reverse_iterator reverse_iterator;
typedef std::vector<char>::const_reverse_iterator const_reverse_iterator;
std::vector<char>::iterator begin() { return vstr.begin(); }
std::vector<char>::const_iterator begin() const { return vstr.begin(); }
std::vector<char>::iterator end() { return vstr.end(); }
std::vector<char>::const_iterator end() const { return vstr.end(); }
std::vector<char>::reverse_iterator rbegin() { return vstr.rbegin(); }
std::vector<char>::const_reverse_iterator rbegin() const { return vstr.rbegin(); }
std::vector<char>::reverse_iterator rend() { return vstr.rend(); }
std::vector<char>::const_reverse_iterator rend() const { return vstr.rend(); }
vstring() { }
vstring(const std::string &str);
vstring(const char c);
vstring(const char* c);
vstring(const short n);
vstring(const unsigned short n);
vstring(const int n);
vstring(const unsigned int n);
vstring(const long n);
vstring(const unsigned long n);
vstring(const float n);
vstring(const double n);
vstring& append(const std::string &str);
vstring& append(const char c);
vstring& append(const char* c);
vstring& append(const short n);
vstring& append(const unsigned short n);
vstring& append(const int n);
vstring& append(const unsigned int n);
vstring& append(const long n);
vstring& append(const unsigned long n);
vstring& append(const float n);
vstring& append(const double n);
// operator[]
vstringlist split(const vstring &sept=' ', unsigned int limit=0) const;
vstringlist split_around(const vstring &sept=' ', unsigned int limit=0) const;
vstringlist split_before(const vstring &sept=' ', unsigned int limit=0) const;
vstringlist split_after(const vstring &sept=' ', unsigned int limit=0) const;
vstringlist split_by(const unsigned &by=1, unsigned int limit=0) const;
vstring& join(const vstring &sept, const vstringlist &other, bool aclear=false);
// find return 0 on failure , return pos + 1
unsigned int find(const vstring &other, unsigned int npos=0) const;
unsigned int find(const char c, unsigned int npos=0) const;
unsigned int rfind(const vstring &other, unsigned int npos=0) const;
unsigned int rfind(const char c, unsigned int npos=0) const;
const char* c_str() const;
std::string String() const;
vstring slice(unsigned int pos) const;
vstring slice(unsigned int pos,unsigned int npos) const;
unsigned int count(const vstring &str) const;
void clear() { vstr.clear(); }
unsigned int size() const { return vstr.size(); }
// compare
vstring& replace(const vstring &delim, const vstring &with="");
vstring& insert(unsigned int pos, const vstring &sert);
vstring& insert(unsigned int pos, const char c);
void erase(unsigned int pos);
void erase(unsigned int pos,unsigned int npos);
vstring& lower(unsigned int pos=0); // from pos to end
vstring& lower(unsigned int pos,unsigned int npos);
vstring& upper(unsigned int pos=0);
vstring& upper(unsigned int pos,unsigned int npos);
bool islower() const;
bool isupper() const;
bool isint() const;
bool isfloat() const;
bool isalpha() const;
};
#endif
| |