mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Added more path related helpers to String.
This commit is contained in:
parent
aee3bd76c8
commit
1476a89304
@ -196,6 +196,10 @@ 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) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
ERR_FAIL_INDEX_V(start_index, _size, String());
|
ERR_FAIL_INDEX_V(start_index, _size, String());
|
||||||
ERR_FAIL_INDEX_V(end_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());
|
||||||
@ -1055,7 +1059,7 @@ void String::path_clean_end_slash() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void String::path_ensure_end_slash() {
|
void String::path_ensure_end_slash() {
|
||||||
//Don't add if empty string, as it would make it root on linux, which can easily become a serious bug
|
// Don't add if empty string, as it would make it root on linux, which can easily become a serious bug
|
||||||
if (_size == 0) {
|
if (_size == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1065,6 +1069,49 @@ void String::path_ensure_end_slash() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String String::path_get_basename() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ssind = _size - 1;
|
||||||
|
while (ssind > 0 && (_data[ssind] != '/' || _data[ssind] != '\\')) {
|
||||||
|
--ssind;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ssind == _size - 1) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
|
++ssind;
|
||||||
|
|
||||||
|
return substr_index(ssind, _size - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String String::path_get_last_segment() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
|
int seind = _size - 1;
|
||||||
|
while (seind > 0 && (_data[seind] == '/' || _data[seind] == '\\')) {
|
||||||
|
--seind;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seind == 0) {
|
||||||
|
return _data[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int ssind = seind - 1;
|
||||||
|
while (ssind > 0 && (_data[ssind] != '/' || _data[ssind] != '\\')) {
|
||||||
|
--ssind;
|
||||||
|
}
|
||||||
|
|
||||||
|
++ssind;
|
||||||
|
|
||||||
|
return substr_index(ssind, seind);
|
||||||
|
}
|
||||||
|
|
||||||
void String::to_html_special_chars() {
|
void String::to_html_special_chars() {
|
||||||
replace("&", "&");
|
replace("&", "&");
|
||||||
replace("\"", """);
|
replace("\"", """);
|
||||||
|
@ -111,6 +111,8 @@ public:
|
|||||||
void append_path(const String &path);
|
void append_path(const String &path);
|
||||||
void path_clean_end_slash();
|
void path_clean_end_slash();
|
||||||
void path_ensure_end_slash();
|
void path_ensure_end_slash();
|
||||||
|
String path_get_basename() const;
|
||||||
|
String path_get_last_segment() const;
|
||||||
|
|
||||||
void to_html_special_chars();
|
void to_html_special_chars();
|
||||||
void from_html_special_chars();
|
void from_html_special_chars();
|
||||||
|
Loading…
Reference in New Issue
Block a user