Added comparison between char32s, added a replace function for string32s

This commit is contained in:
Xnoe 2020-07-08 17:52:01 +01:00 committed by Elsie
parent ebc8c895c4
commit 904533a75f

17
utf8.h
View File

@ -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,10 +41,24 @@ 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) {
for (int i=0;i<s32.size();i++)
stream << s32[i];
return stream;
return stream;
}