Added comparison between char32s, added a replace function for string32s
This commit is contained in:
parent
ebc8c895c4
commit
904533a75f
15
utf8.h
15
utf8.h
@ -24,6 +24,7 @@ public:
|
||||
char32(const char* s) {c = fetch32((char**)&s);}
|
||||
char32(char** s) {c = fetch32(s);}
|
||||
bool operator==(char* cs) {return c==fetch32(&cs);}
|
||||
bool operator==(char32 cs) {return c==cs.c;}
|
||||
unsigned int operator>>(int a) const {return c>>a;}
|
||||
};
|
||||
|
||||
@ -40,6 +41,20 @@ struct string32 {
|
||||
}
|
||||
int size() const {return cs.size();}
|
||||
char32 operator[](int i) const {return cs[i];}
|
||||
void replace(string32 find, string32 with) {
|
||||
int havematched(0);
|
||||
int findsize = find.cs.size();
|
||||
for (int index(0); index < cs.size(); index++) {
|
||||
if (cs.at(index) == find.cs.at(havematched))
|
||||
havematched++;
|
||||
if (havematched == findsize) {
|
||||
index -= findsize-1;
|
||||
cs.erase(cs.begin()+index, cs.begin()+index+findsize);
|
||||
cs.insert(cs.begin()+index, with.cs.begin(), with.cs.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const string32& s32) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user