mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
strip nuls from tags as well
https://forums.ankiweb.net/t/unable-to-sync-between-macbook-and-my-iphone/2405
This commit is contained in:
parent
56431872fb
commit
529deff82a
1 changed files with 14 additions and 4 deletions
|
|
@ -13,8 +13,7 @@ use std::{borrow::Cow, collections::HashSet};
|
||||||
use unicase::UniCase;
|
use unicase::UniCase;
|
||||||
|
|
||||||
pub(crate) fn split_tags(tags: &str) -> impl Iterator<Item = &str> {
|
pub(crate) fn split_tags(tags: &str) -> impl Iterator<Item = &str> {
|
||||||
tags.split(|c| c == ' ' || c == '\u{3000}')
|
tags.split(is_tag_separator).filter(|tag| !tag.is_empty())
|
||||||
.filter(|tag| !tag.is_empty())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn join_tags(tags: &[String]) -> String {
|
pub(crate) fn join_tags(tags: &[String]) -> String {
|
||||||
|
|
@ -25,6 +24,14 @@ pub(crate) fn join_tags(tags: &[String]) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_tag_separator(c: char) -> bool {
|
||||||
|
c == ' ' || c == '\u{3000}'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invalid_char_for_tag(c: char) -> bool {
|
||||||
|
c.is_ascii_control() || is_tag_separator(c)
|
||||||
|
}
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
/// Given a list of tags, fix case, ordering and duplicates.
|
/// Given a list of tags, fix case, ordering and duplicates.
|
||||||
/// Returns true if any new tags were added.
|
/// Returns true if any new tags were added.
|
||||||
|
|
@ -32,13 +39,16 @@ impl Collection {
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
let mut added = false;
|
let mut added = false;
|
||||||
|
|
||||||
let tags: Vec<_> = tags
|
let mut tags: Vec<_> = tags
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|t| split_tags(t))
|
.flat_map(|t| split_tags(t))
|
||||||
.map(|s| normalize_to_nfc(&s))
|
.map(|s| normalize_to_nfc(&s))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for tag in &tags {
|
for tag in &mut tags {
|
||||||
|
if tag.contains(invalid_char_for_tag) {
|
||||||
|
*tag = tag.replace(invalid_char_for_tag, "").into();
|
||||||
|
}
|
||||||
if tag.trim().is_empty() {
|
if tag.trim().is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue