Changed the replace function to now return a value instead of replacing content within itself.
This commit is contained in:
parent
388994122d
commit
b19378771b
23
utf8.h
23
utf8.h
@ -49,23 +49,32 @@ struct string32 {
|
|||||||
while (sd[0])
|
while (sd[0])
|
||||||
cs.push_back(char32(&sd));
|
cs.push_back(char32(&sd));
|
||||||
}
|
}
|
||||||
int size() const {return cs.size();}
|
string32(std::vector<char32> c32s) {
|
||||||
char32 operator[](int i) const {return cs[i];}
|
cs = c32s;
|
||||||
void replace(string32 find, string32 with) {
|
}
|
||||||
|
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 havematched(0);
|
||||||
int findsize = find.cs.size();
|
int findsize = find.cs.size();
|
||||||
for (int index(0); index < cs.size(); index++) {
|
for (int index(0); index < copyOfSelf.cs.size(); index++) {
|
||||||
if (cs.at(index) == find.cs.at(havematched))
|
if (copyOfSelf.cs.at(index) == find.cs.at(havematched))
|
||||||
havematched++;
|
havematched++;
|
||||||
else
|
else
|
||||||
havematched=0;
|
havematched=0;
|
||||||
if (havematched == findsize) {
|
if (havematched == findsize) {
|
||||||
index -= findsize-1;
|
index -= findsize-1;
|
||||||
cs.erase(cs.begin()+index, cs.begin()+index+findsize);
|
copyOfSelf.cs.erase(copyOfSelf.cs.begin()+index, copyOfSelf.cs.begin()+index+findsize);
|
||||||
cs.insert(cs.begin()+index, with.cs.begin(), with.cs.end());
|
copyOfSelf.cs.insert(copyOfSelf.cs.begin()+index, with.cs.begin(), with.cs.end());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return copyOfSelf;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user