mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Added a new path_get_prev_dir method to String.
This commit is contained in:
parent
8072497ef4
commit
a4e4df979d
@ -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("&", "&");
|
||||
replace("\"", """);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user