|
@@ -153,10 +153,7 @@ void CharString::clear() {
|
|
}
|
|
}
|
|
|
|
|
|
Error CharString::print() const {
|
|
Error CharString::print() const {
|
|
- for(int i = 0; i < length; i++) {
|
|
+ return Core::putChars(data);
|
|
- CORE_RETURN_ERROR(Core::putChar(data[i]));
|
|
|
|
- }
|
|
|
|
- return ErrorCode::NONE;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
Error CharString::printLine() const {
|
|
Error CharString::printLine() const {
|
|
@@ -164,25 +161,18 @@ Error CharString::printLine() const {
|
|
return Core::putChar('\n');
|
|
return Core::putChar('\n');
|
|
}
|
|
}
|
|
|
|
|
|
-bool CharString::startsWidth(const CharString& other, int from) const {
|
|
+bool CharString::startsWith(const CharString& other, int from) const {
|
|
- if(from > length - other.getLength()) {
|
|
+ return from >= 0 && length - from >= other.getLength() &&
|
|
- return false;
|
|
+ strncmp(data + from, other.data,
|
|
- }
|
|
+ static_cast<size_t>(other.getLength())) == 0;
|
|
- for(int i = 0; i < other.getLength(); i++) {
|
|
|
|
- if(data[from + i] != other[i]) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
int CharString::search(const CharString& other, int from) const {
|
|
int CharString::search(const CharString& other, int from) const {
|
|
- for(int i = from; i < length; i++) {
|
|
+ if(from < 0) {
|
|
- if(startsWidth(other, i)) {
|
|
+ return false;
|
|
- return i;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- return -1;
|
|
+ char* f = strstr(data + from, other.data);
|
|
|
|
+ return f == nullptr ? -1 : static_cast<int>(f - data);
|
|
}
|
|
}
|
|
|
|
|
|
bool CharString::contains(const CharString& other, int from) const {
|
|
bool CharString::contains(const CharString& other, int from) const {
|
|
@@ -190,12 +180,11 @@ bool CharString::contains(const CharString& other, int from) const {
|
|
}
|
|
}
|
|
|
|
|
|
int CharString::search(char u, int from) const {
|
|
int CharString::search(char u, int from) const {
|
|
- for(int i = from; i < length; i++) {
|
|
+ if(from < 0) {
|
|
- if(data[i] == u) {
|
|
+ return false;
|
|
- return i;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- return -1;
|
|
+ char* f = strchr(data + from, u);
|
|
|
|
+ return f == nullptr ? -1 : static_cast<int>(f - data);
|
|
}
|
|
}
|
|
|
|
|
|
bool CharString::contains(char u, int from) const {
|
|
bool CharString::contains(char u, int from) const {
|
|
@@ -220,7 +209,7 @@ Error CharString::replace(CharString& s, const CharString& search,
|
|
const CharString& replace) {
|
|
const CharString& replace) {
|
|
int i = 0;
|
|
int i = 0;
|
|
while(i < length) {
|
|
while(i < length) {
|
|
- if(startsWidth(search, i)) {
|
|
+ if(startsWith(search, i)) {
|
|
CORE_RETURN_ERROR(s.append(replace));
|
|
CORE_RETURN_ERROR(s.append(replace));
|
|
i += search.getLength();
|
|
i += search.getLength();
|
|
} else {
|
|
} else {
|
|
@@ -386,7 +375,7 @@ Error Char32String::printLine() const {
|
|
return ErrorCode::NONE;
|
|
return ErrorCode::NONE;
|
|
}
|
|
}
|
|
|
|
|
|
-bool Char32String::startsWidth(const Char32String& other, int from) const {
|
|
+bool Char32String::startsWith(const Char32String& other, int from) const {
|
|
if(from > length - other.getLength()) {
|
|
if(from > length - other.getLength()) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -400,7 +389,7 @@ bool Char32String::startsWidth(const Char32String& other, int from) const {
|
|
|
|
|
|
int Char32String::search(const Char32String& other, int from) const {
|
|
int Char32String::search(const Char32String& other, int from) const {
|
|
for(int i = from; i < length; i++) {
|
|
for(int i = from; i < length; i++) {
|
|
- if(startsWidth(other, i)) {
|
|
+ if(startsWith(other, i)) {
|
|
return i;
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -442,7 +431,7 @@ Error Char32String::replace(Char32String& s, const Char32String& search,
|
|
const Char32String& replace) {
|
|
const Char32String& replace) {
|
|
int i = 0;
|
|
int i = 0;
|
|
while(i < length) {
|
|
while(i < length) {
|
|
- if(startsWidth(search, i)) {
|
|
+ if(startsWith(search, i)) {
|
|
CORE_RETURN_ERROR(s.append(replace));
|
|
CORE_RETURN_ERROR(s.append(replace));
|
|
i += search.getLength();
|
|
i += search.getLength();
|
|
} else {
|
|
} else {
|