aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexander Batischev <eual.jp@gmail.com> 2024-10-01 19:49:16 +0300
committerGravatar Alexander Batischev <eual.jp@gmail.com> 2024-11-22 20:48:31 +0300
commite1ff2e8457269429cf646b51881675ddc087e8ea (patch)
treeb93c7051618ec768c9a1c6691e362b5a91f52b2e
parent6ef25d77a530eafa3f78de6462ed07093e2e952e (diff)
downloadnewsboat-e1ff2e8457269429cf646b51881675ddc087e8ea.tar.gz
newsboat-e1ff2e8457269429cf646b51881675ddc087e8ea.tar.zst
newsboat-e1ff2e8457269429cf646b51881675ddc087e8ea.zip
Change `Filepath::starts_with()` to take Filepath as argument
This makes more sense, as the argument is a valid path.
-rw-r--r--include/filepath.h5
-rw-r--r--rust/libnewsboat-ffi/src/filepath.rs6
-rw-r--r--src/filepath.cpp4
3 files changed, 8 insertions, 7 deletions
diff --git a/include/filepath.h b/include/filepath.h
index 6308f2ae..be148b10 100644
--- a/include/filepath.h
+++ b/include/filepath.h
@@ -95,8 +95,9 @@ public:
// Return `true` if Filepath start with `base`, `false` otherwise.
//
- // \note `ext` is interpreted as bytes in locale encoding.
- bool starts_with(const std::string& base) const;
+ // Only considers whole path components to match, i.e. "/foo" is **not**
+ // a prefix of "/foobar/baz".
+ bool starts_with(const Filepath& base) const;
/// Returns the final component of the path, if there is one.
nonstd::optional<Filepath> file_name() const;
diff --git a/rust/libnewsboat-ffi/src/filepath.rs b/rust/libnewsboat-ffi/src/filepath.rs
index 778ed0de..65ed82b8 100644
--- a/rust/libnewsboat-ffi/src/filepath.rs
+++ b/rust/libnewsboat-ffi/src/filepath.rs
@@ -25,7 +25,7 @@ mod bridged {
fn clone(filepath: &PathBuf) -> Box<PathBuf>;
fn is_absolute(filepath: &PathBuf) -> bool;
fn set_extension(filepath: &mut PathBuf, extension: Vec<u8>) -> bool;
- fn starts_with(filepath: &PathBuf, str: Vec<u8>) -> bool;
+ fn starts_with(filepath: &PathBuf, base: &PathBuf) -> bool;
fn file_name(filepath: &PathBuf) -> Vec<u8>;
}
}
@@ -68,8 +68,8 @@ fn set_extension(filepath: &mut PathBuf, extension: Vec<u8>) -> bool {
filepath.0.set_extension(OsStr::from_bytes(&extension))
}
-fn starts_with(filepath: &PathBuf, base: Vec<u8>) -> bool {
- filepath.0.starts_with(OsStr::from_bytes(&base))
+fn starts_with(filepath: &PathBuf, base: &PathBuf) -> bool {
+ filepath.0.starts_with(&base.0)
}
fn file_name(filepath: &PathBuf) -> Vec<u8> {
diff --git a/src/filepath.cpp b/src/filepath.cpp
index b5ff097e..6ff48526 100644
--- a/src/filepath.cpp
+++ b/src/filepath.cpp
@@ -85,9 +85,9 @@ bool Filepath::set_extension(const std::string& ext)
return filepath::bridged::set_extension(*rs_object, string_to_vec(ext));
}
-bool Filepath::starts_with(const std::string& base) const
+bool Filepath::starts_with(const Filepath& base) const
{
- return filepath::bridged::starts_with(*rs_object, string_to_vec(base));
+ return filepath::bridged::starts_with(*rs_object, *base.rs_object);
}
nonstd::optional<Filepath> Filepath::file_name() const