Просмотр исходного кода

app: in custom emojis, allow comments to occur anywhere

darkfi 1 год назад
Родитель
Сommit
d2e3b70946
1 измененных файлов с 7 добавлено и 2 удалено
  1. 7 2
      bin/app/src/ui/emoji_picker/emoji.rs

+ 7 - 2
bin/app/src/ui/emoji_picker/emoji.rs

@@ -135,10 +135,11 @@ fn load_custom_emoji_list(path: &Path) -> Option<Vec<String>> {
     let mut emojis = vec![];
     for mut line in reader.lines().map_while(Result::ok) {
         remove_whitespace(&mut line);
-        if line.starts_with('#') {
+        let line = strip_comment(&line);
+        if line.is_empty() {
             continue
         }
-        let emoji = unescape_unicode(&line)?;
+        let emoji = unescape_unicode(line)?;
         emojis.push(emoji);
     }
     Some(emojis)
@@ -173,3 +174,7 @@ fn unescape_unicode(input: &str) -> Option<String> {
 fn remove_whitespace(s: &mut String) {
     s.retain(|c| !c.is_whitespace());
 }
+
+fn strip_comment(s: &str) -> &str {
+    s.split('#').next().unwrap_or(s)
+}