From 904533a75f202592f2f94bd975f3c9bcfb0ea85b Mon Sep 17 00:00:00 2001 From: Xnoe Date: Wed, 8 Jul 2020 17:52:01 +0100 Subject: [PATCH] Added comparison between char32s, added a replace function for string32s --- utf8.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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