Extract contains_word function
This commit is contained in:
parent
5b94e67f0d
commit
6ea1ea4d6c
3 changed files with 13 additions and 5 deletions
|
@ -4,6 +4,7 @@ mod irc_handler;
|
|||
mod irc_message;
|
||||
mod message_log;
|
||||
mod ui_message;
|
||||
mod util;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use iced::{Application, Settings};
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use crate::irc_message::{IrcMessage, MessageDetail};
|
||||
use crate::{
|
||||
irc_message::{IrcMessage, MessageDetail},
|
||||
util,
|
||||
};
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use iced::{
|
||||
|
@ -7,7 +10,6 @@ use iced::{
|
|||
Background, Color, Length,
|
||||
};
|
||||
use irc::proto::BatchSubCommand;
|
||||
use regex::Regex;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub struct Channel {
|
||||
|
@ -321,9 +323,7 @@ impl<'a> MessageLog {
|
|||
}
|
||||
|
||||
if !is_active {
|
||||
let highlight_regex =
|
||||
Regex::new(&format!(r"\b{}\b", regex::escape(current_nickname))).unwrap();
|
||||
if highlight_regex.is_match(message) {
|
||||
if util::contains_word(current_nickname, message) {
|
||||
channel.unread_highlights += 1;
|
||||
} else {
|
||||
channel.unread_messages += 1;
|
||||
|
|
7
src/util.rs
Normal file
7
src/util.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use regex::Regex;
|
||||
|
||||
pub fn contains_word(needle: &str, haystack: &str) -> bool {
|
||||
let pattern = format!(r"\b{}\b", regex::escape(needle));
|
||||
let regex = Regex::new(&pattern).unwrap();
|
||||
regex.is_match(haystack)
|
||||
}
|
Loading…
Reference in a new issue