text_mel/compare/
mod.rs

1pub mod char;
2
3use melodium_core::*;
4use melodium_macro::{check, mel_function, mel_treatment};
5
6/// Tells if strings exactly matches a pattern.
7#[mel_treatment(
8    input text Stream<string>
9    output matches Stream<bool>
10)]
11pub async fn exact(pattern: string) {
12    while let Ok(text) = text.recv_string().await {
13        check!(
14            matches
15                .send_bool(text.into_iter().map(|txt| txt == pattern).collect())
16                .await
17        );
18    }
19}
20
21/// Tells if string exactly matches a pattern.
22#[mel_function]
23pub fn exact(text: string, pattern: string) -> bool {
24    text == pattern
25}
26
27/// Tells if strings starts with a pattern.
28#[mel_treatment(
29    input text Stream<string>
30    output matches Stream<bool>
31)]
32pub async fn starts_with(pattern: string) {
33    while let Ok(text) = text.recv_string().await {
34        check!(
35            matches
36                .send_bool(
37                    text.into_iter()
38                        .map(|txt| txt.starts_with(&pattern))
39                        .collect()
40                )
41                .await
42        );
43    }
44}
45
46/// Tells if string starts with a pattern.
47#[mel_function]
48pub fn starts_with(text: string, pattern: string) -> bool {
49    text.starts_with(&pattern)
50}
51
52/// Tells if strings ends with a pattern.
53#[mel_treatment(
54    input text Stream<string>
55    output matches Stream<bool>
56)]
57pub async fn ends_with(pattern: string) {
58    while let Ok(text) = text.recv_string().await {
59        check!(
60            matches
61                .send_bool(
62                    text.into_iter()
63                        .map(|txt| txt.ends_with(&pattern))
64                        .collect()
65                )
66                .await
67        );
68    }
69}
70
71/// Tells if string ends with a pattern.
72#[mel_function]
73pub fn ends_with(text: string, pattern: string) -> bool {
74    text.ends_with(&pattern)
75}