Skip to main content

icydb_model/base/validator/text/
mod.rs

1//! Module: base::validator::text
2//!
3//! Responsibility: base validator definitions.
4//! Does not own: normalization policy, persistence, or schema mutation semantics.
5//! Boundary: reports typed visitor issues for facade schema values.
6
7pub mod case;
8pub mod color;
9
10use crate::{prelude::*, visitor::Validator};
11
12///
13/// AlphaUscore
14/// this doesn't force ASCII; it uses Unicode `is_alphabetic`
15/// ASCII is handled by a separate validator
16///
17
18#[validator]
19pub struct AlphaUscore;
20
21impl Validator<str> for AlphaUscore {
22    fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
23        if !s.chars().all(|c| c.is_alphabetic() || c == '_') {
24            ctx.issue("text must be alphabetic or underscore");
25        }
26    }
27}
28
29///
30/// AlphanumUscore
31///
32
33#[validator]
34pub struct AlphanumUscore;
35
36impl Validator<str> for AlphanumUscore {
37    fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
38        if !s.chars().all(|c| c.is_alphanumeric() || c == '_') {
39            ctx.issue("text must be alphanumeric or underscore");
40        }
41    }
42}
43
44///
45/// Ascii
46///
47
48#[validator]
49pub struct Ascii;
50
51impl Validator<str> for Ascii {
52    fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
53        if !s.is_ascii() {
54            ctx.issue("text must be ASCII");
55        }
56    }
57}