50 lines
903 B
C++
50 lines
903 B
C++
#ifndef __ParseString_h__
|
|
#define __ParseString_h__
|
|
|
|
#include "includes"
|
|
|
|
namespace core {
|
|
|
|
class ParseString : std::string {
|
|
|
|
public:
|
|
ParseString() {}
|
|
ParseString(std::string value) : std::string(value) {}
|
|
ParseString(std::string value, char delimiter) : std::string(value) {
|
|
|
|
}
|
|
|
|
void setDelimiter(char delimiter) {
|
|
this->delimiter = delimiter;
|
|
parse();
|
|
}
|
|
|
|
private:
|
|
char delimiter;
|
|
|
|
void parse() {
|
|
|
|
std::stringstream sstring((std::string)*this);
|
|
|
|
sstring.imbue(std::locale(sstring.getloc(), new isDelimiter(':')));
|
|
|
|
|
|
}
|
|
|
|
struct isDelimiter : std::ctype<char> {
|
|
char chr;
|
|
isDelimiter(char chr) : std::ctype<char>(get_table()) {
|
|
this->chr = chr;
|
|
}
|
|
static mask const* get_table() {
|
|
static mask rc[table_size];
|
|
rc[*chr] = std::ctype_base::space;
|
|
rc['\n'] = std::ctype_base::space;
|
|
return &rc[0];
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|