Added comparison between char32s, added a replace function for string32s
This commit is contained in:
parent
ebc8c895c4
commit
904533a75f
19
utf8.h
19
utf8.h
@ -24,6 +24,7 @@ public:
|
|||||||
char32(const char* s) {c = fetch32((char**)&s);}
|
char32(const char* s) {c = fetch32((char**)&s);}
|
||||||
char32(char** s) {c = fetch32(s);}
|
char32(char** s) {c = fetch32(s);}
|
||||||
bool operator==(char* cs) {return c==fetch32(&cs);}
|
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;}
|
unsigned int operator>>(int a) const {return c>>a;}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,14 +37,28 @@ struct string32 {
|
|||||||
std::vector<char32> cs;
|
std::vector<char32> cs;
|
||||||
string32(char* sd) {
|
string32(char* sd) {
|
||||||
while (sd[0])
|
while (sd[0])
|
||||||
cs.push_back(char32(&sd));
|
cs.push_back(char32(&sd));
|
||||||
}
|
}
|
||||||
int size() const {return cs.size();}
|
int size() const {return cs.size();}
|
||||||
char32 operator[](int i) const {return cs[i];}
|
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) {
|
std::ostream& operator<<(std::ostream& stream, const string32& s32) {
|
||||||
for (int i=0;i<s32.size();i++)
|
for (int i=0;i<s32.size();i++)
|
||||||
stream << s32[i];
|
stream << s32[i];
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user