-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmstring.cpp
70 lines (58 loc) · 1.41 KB
/
mstring.cpp
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
#include <iostream>
#include <string>
#include "mstring.hpp"
#include "mutil.h"
MString::MString()
{}
MString::MString(const char *s)
{
std::string in(s);
m_string = in;
}
MString::MString(std::string s) : m_string(s)
{}
MString::MString(MString &source)
{
m_string = source.str();
}
MString& MString::operator=(const MString& source)
{
m_string = source.m_string;
return *this;
}
MString::~MString()
{}
std::string MString::str(void)
{
return m_string;
}
std::vector<std::string> MString::split(std::string on)
{
std::vector<std::string> splitlist;
std::string::size_type current_pos = 0;
while (1) {
std::string::size_type pos = m_string.find(on, current_pos);
if (pos == std::string::npos) {
// Didn't find it
splitlist.push_back(m_string.substr(current_pos));
break;
} else if (pos == 0) {
splitlist.push_back(std::string(""));
} else {
splitlist.push_back(m_string.substr(current_pos, pos-current_pos));
}
current_pos = pos + on.size();
}
return splitlist;
}
std::string MString::tohex(void) {
char *c_hex = ::tohex((unsigned char*)m_string.c_str(),
m_string.length());
std::string hex(c_hex);
free(c_hex);
return hex;
}
std::ostream& operator<<(std::ostream& os, const MString& me) {
os << me.m_string;
return os;
}