diff --git a/utf8.h b/utf8.h index e1049b1..0df67b8 100644 --- a/utf8.h +++ b/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;} }; @@ -36,14 +37,28 @@ struct string32 { std::vector cs; string32(char* sd) { while (sd[0]) - cs.push_back(char32(&sd)); + cs.push_back(char32(&sd)); } 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