From b19378771b7252064baf85b0856bab1d5c79fa95 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Fri, 10 Jul 2020 04:51:18 +0100 Subject: [PATCH] Changed the replace function to now return a value instead of replacing content within itself. --- utf8.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/utf8.h b/utf8.h index 94268b7..7e582d7 100644 --- a/utf8.h +++ b/utf8.h @@ -49,23 +49,32 @@ struct string32 { while (sd[0]) 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) { + string32(std::vector c32s) { + cs = c32s; + } + int size() const { + return cs.size(); + } + char32 operator[](int i) const { + return cs[i]; + } + string32 replace(string32 find, string32 with) { + string32 copyOfSelf (cs); int havematched(0); int findsize = find.cs.size(); - for (int index(0); index < cs.size(); index++) { - if (cs.at(index) == find.cs.at(havematched)) + for (int index(0); index < copyOfSelf.cs.size(); index++) { + if (copyOfSelf.cs.at(index) == find.cs.at(havematched)) havematched++; else havematched=0; 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()); + copyOfSelf.cs.erase(copyOfSelf.cs.begin()+index, copyOfSelf.cs.begin()+index+findsize); + copyOfSelf.cs.insert(copyOfSelf.cs.begin()+index, with.cs.begin(), with.cs.end()); break; } } + return copyOfSelf; } };