Added a new path_get_prev_dir method to String.

This commit is contained in:
Relintai 2022-02-06 11:12:31 +01:00
parent 8072497ef4
commit a4e4df979d
2 changed files with 39 additions and 0 deletions

View File

@ -1112,6 +1112,44 @@ String String::path_get_last_segment() const {
return substr_index(ssind, seind);
}
String String::path_get_prev_dir() const {
if (_size == 0) {
return String();
}
int seind = _size - 1;
while (seind > 0 && (_data[seind] == '/' || _data[seind] == '\\')) {
--seind;
}
if (seind == 0) {
// /////////
// or
// a///////
// no prev dir
return String("/");
}
// fol/fol2/fol3//
// ^ (seind)
while (seind > 0 && (_data[seind] != '/' || _data[seind] != '\\')) {
--seind;
}
// fol/fol2/fol3//
// ^ (seind)
--seind;
if (seind <= 0) {
return String("/");
}
return substr_index(0, seind);
}
void String::to_html_special_chars() {
replace("&", "&amp;");
replace("\"", "&quot;");

View File

@ -113,6 +113,7 @@ public:
void path_ensure_end_slash();
String path_get_basename() const;
String path_get_last_segment() const;
String path_get_prev_dir() const;
void to_html_special_chars();
void from_html_special_chars();