pub trait NotePath {
    fn append_copy_counter(stem: &str, n: usize) -> String;
    fn disassemble(&self) -> (&str, &str, &str, &str, &str);
    fn exclude_copy_counter_eq(&self, p2: &Path) -> bool;
    fn has_wellformed_filename(&self) -> bool;
    fn remove_copy_counter(tag: &str) -> &str;
    fn has_tpnote_extension(&self) -> bool;
}
Expand description

Extents Path with methods dealing with paths to Tp-Note files.

Required Methods

Append the copy counter n at the end to the filestem.

Helper function that decomposes a fully qualified path name into (sort_tag, stem_copy_counter_ext, stem, copy_counter, ext).

Compares with another Path to a Tp-Note file. They are considered equal even when the copy counter is different.

Check if a Path points to a “wellformed” filename.

Removes the copy counter from the file stem.

Compare to all file extensions Tp-Note can open.

Implementations on Foreign Types

Check if 2 filenames are equal. Compare all parts, except the copy counter. Consider 2 file identical even when they have a different copy counter.

Check if a path is a “well formed” filename. We consider it well formed,

  • if path has no directory components, only a filename, and
  • if the filename is not empty, and
    • if the filename is a dot file (len >1 and without whitespace), or
    • if the filename has an extension. A valid extension must not contain whitespace.
use std::path::Path;
use tpnote_lib::filename::NotePath;

let f = Path::new("tpnote.toml");
assert!(f.has_wellformed_filename());

let f = Path::new("dir/tpnote.toml");
assert!(f.has_wellformed_filename());

let f = Path::new("tpnote.to ml");
assert!(!f.has_wellformed_filename());

Helper function that trims the copy counter at the end of string. If there is none, return the same.

True if the filename extension is considered as a Tp-Note file. Checks if the filename extension is one of the following list taken from the configuration file: FILENAME_EXTENSIONS_MD, FILENAME_EXTENSIONS_RST, FILENAME_EXTENSIONS_HTML, FILENAME_EXTENSIONS_TXT, FILENAME_EXTENSIONS_NO_VIEWER

Implementors