mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-06 17:51:36 +02:00
In String::substr_index the end_index now isn't inclusive.
This commit is contained in:
parent
cd548cc83d
commit
131d4b49cc
@ -253,17 +253,13 @@ String String::substr(const int start_index, const int len) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String String::substr_index(const int start_index, const int end_index) const {
|
String String::substr_index(const int start_index, const int end_index) const {
|
||||||
if (start_index == end_index) {
|
ERR_FAIL_INDEX_V(start_index, _size + 1, String());
|
||||||
return String();
|
ERR_FAIL_INDEX_V(end_index, _size + 1, String());
|
||||||
}
|
|
||||||
|
|
||||||
ERR_FAIL_INDEX_V(start_index, _size, String());
|
|
||||||
ERR_FAIL_INDEX_V(end_index, _size, String());
|
|
||||||
ERR_FAIL_COND_V(start_index > end_index, String());
|
ERR_FAIL_COND_V(start_index > end_index, String());
|
||||||
|
|
||||||
String str;
|
String str;
|
||||||
str.ensure_capacity(end_index - start_index + 1);
|
str.ensure_capacity(end_index - start_index + 1);
|
||||||
for (int i = start_index; i <= end_index; ++i) {
|
for (int i = start_index; i < end_index; ++i) {
|
||||||
str._data[str._size++] = _data[i];
|
str._data[str._size++] = _data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,12 +596,12 @@ String String::get_slice(const char splitter, int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count == index + 1) {
|
if (count == index + 1) {
|
||||||
return substr_index(start_index, i - 1);
|
return substr_index(start_index, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr_index(start_index, _size - 1);
|
return substr_index(start_index, _size);
|
||||||
}
|
}
|
||||||
String String::get_slice(const String &splitter, int index) {
|
String String::get_slice(const String &splitter, int index) {
|
||||||
if (_size == 0) {
|
if (_size == 0) {
|
||||||
@ -626,11 +622,11 @@ String String::get_slice(const String &splitter, int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count == index + 1) {
|
if (count == index + 1) {
|
||||||
return substr_index(start_index, n - 1);
|
return substr_index(start_index, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr_index(start_index, _size - 1);
|
return substr_index(start_index, _size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String> String::split(const char splitter) const {
|
Vector<String> String::split(const char splitter) const {
|
||||||
@ -648,7 +644,7 @@ Vector<String> String::split(const char splitter) const {
|
|||||||
if (start_index == i) {
|
if (start_index == i) {
|
||||||
v.push_back(String());
|
v.push_back(String());
|
||||||
} else {
|
} else {
|
||||||
v.push_back(substr_index(start_index, i - 1));
|
v.push_back(substr_index(start_index, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
start_index = i + 1;
|
start_index = i + 1;
|
||||||
@ -656,7 +652,7 @@ Vector<String> String::split(const char splitter) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (start_index < _size - 1) {
|
if (start_index < _size - 1) {
|
||||||
v.push_back(substr_index(start_index, _size - 1));
|
v.push_back(substr_index(start_index, _size));
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
@ -674,13 +670,13 @@ Vector<String> String::split(const String &splitter) const {
|
|||||||
while (n != -1) {
|
while (n != -1) {
|
||||||
n = find(splitter, n);
|
n = find(splitter, n);
|
||||||
|
|
||||||
v.push_back(substr_index(start_index, n - 1));
|
v.push_back(substr_index(start_index, n));
|
||||||
|
|
||||||
start_index = n + splitter.size();
|
start_index = n + splitter.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_index < _size - 1) {
|
if (start_index < _size - 1) {
|
||||||
v.push_back(substr_index(start_index, _size - 1));
|
v.push_back(substr_index(start_index, _size));
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
@ -1142,7 +1138,7 @@ String String::path_get_basename() const {
|
|||||||
|
|
||||||
++ssind;
|
++ssind;
|
||||||
|
|
||||||
return substr_index(ssind, _size - 1);
|
return substr_index(ssind, _size);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::path_get_last_segment() const {
|
String String::path_get_last_segment() const {
|
||||||
@ -1214,7 +1210,7 @@ String String::file_get_extension() const {
|
|||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr_index(dind + 1, _size - 1);
|
return substr_index(dind + 1, _size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::to_html_special_chars() {
|
void String::to_html_special_chars() {
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
void get_substr(char *into_buf, const int start_index, const int len);
|
void get_substr(char *into_buf, const int start_index, const int len);
|
||||||
void get_substr_nt(char *into_buf, const int start_index, const int len);
|
void get_substr_nt(char *into_buf, const int start_index, const int len);
|
||||||
String substr(const int start_index, const int len) const;
|
String substr(const int start_index, const int len) const;
|
||||||
String substr_index(const int start_index, const int end_index) const;
|
String substr_index(const int start_index, const int end_index) const; //end_index is not included
|
||||||
bool contains(const char val) const;
|
bool contains(const char val) const;
|
||||||
bool contains(const String &val) const;
|
bool contains(const String &val) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user