aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukeflo2025-10-12 21:51:21 +0200
committerlukeflo2025-10-12 21:51:21 +0200
commitf112c4e13009e5ddfe3cf5c4cbe7f29f832b8553 (patch)
tree3dea01a84f2d1453a97e52af4ff8b305eca21419
parent49d9a57bd15565116a51380d3552201b4a2de57b (diff)
downloadbibiman-f112c4e13009e5ddfe3cf5c4cbe7f29f832b8553.tar.gz
bibiman-f112c4e13009e5ddfe3cf5c4cbe7f29f832b8553.zip
solve double delimiters with empty fields
-rw-r--r--src/bibiman/citekeys.rs36
-rw-r--r--tests/test-config.toml2
2 files changed, 31 insertions, 7 deletions
diff --git a/src/bibiman/citekeys.rs b/src/bibiman/citekeys.rs
index 065d57f..9d17403 100644
--- a/src/bibiman/citekeys.rs
+++ b/src/bibiman/citekeys.rs
@@ -317,13 +317,37 @@ fn build_citekey(entry: &Entry, pattern_fields: &[String], case: Option<&Citekey
// process the single slices and add correct delimiter
if let Some(field_slice) = split_field.next() {
- formatted_str = formatted_str + &format_word(field_slice, char_count);
- words_passed += 1;
- if word_count == words_passed {
- formatted_str = formatted_str + trailing_delimiter.unwrap_or("");
- break;
+ // Create word slice char by char. We need to loop over chars
+ // instead of a simple bytes index to also catch chars which
+ // consist of more than one byte (äöüøæ etc...)
+ let mut word_slice = String::new();
+ let word_chars = field_slice.chars();
+ let mut counter = 0;
+ for c in word_chars {
+ if let Some(len) = char_count
+ && counter == len
+ {
+ break;
+ }
+ // if a word slice contains a special char, skip it
+ if IGNORED_SPECIAL_CHARS.contains(&c) {
+ continue;
+ }
+ word_slice.push(c);
+ counter += 1;
+ }
+ // Don't count empty slices and don't add delimiter to those
+ if !word_slice.is_empty() {
+ formatted_str = formatted_str + &word_slice;
+ words_passed += 1;
+ if word_count == words_passed {
+ formatted_str = formatted_str + trailing_delimiter.unwrap_or("");
+ break;
+ } else {
+ formatted_str = formatted_str + inner_delimiter.unwrap_or("");
+ }
} else {
- formatted_str = formatted_str + inner_delimiter.unwrap_or("")
+ continue;
}
} else {
formatted_str = formatted_str + trailing_delimiter.unwrap_or("");
diff --git a/tests/test-config.toml b/tests/test-config.toml
index 558d216..2c5ac96 100644
--- a/tests/test-config.toml
+++ b/tests/test-config.toml
@@ -61,5 +61,5 @@ custom_column = "series"
# year_color = "135"
[citekey_formatter]
-fields = [ "author;2;;-;_", "title;3;6;_;_", "year" ]
+fields = [ "author;2;;-;_", "title;3;6;_;_", "year", "publisher;;5;#;" ]
case = "lowercase"