icydb/base/validator/text/
case.rs1use crate::{design::prelude::*, traits::Validator};
2use icydb_utils::{Case, Casing};
3
4#[validator]
9pub struct Kebab;
10
11impl Validator<str> for Kebab {
12 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
13 if !s.is_case(Case::Kebab) {
14 ctx.issue(format!("'{s}' is not kebab-case"));
15 }
16 }
17}
18
19#[validator]
24pub struct Lower;
25
26impl Validator<str> for Lower {
27 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
28 if !s.is_case(Case::Lower) {
29 ctx.issue(format!("'{s}' is not lower case"));
30 }
31 }
32}
33
34#[validator]
39pub struct LowerUscore;
40
41impl Validator<str> for LowerUscore {
42 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
43 if !s.chars().all(|c| c.is_lowercase() || c == '_') {
44 ctx.issue(format!("'{s}' is not lower case with underscores"));
45 }
46 }
47}
48
49#[validator]
54pub struct Snake;
55
56impl Validator<str> for Snake {
57 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
58 if !s.is_case(Case::Snake) {
59 ctx.issue(format!("'{s}' is not snake_case"));
60 }
61 }
62}
63
64#[validator]
69pub struct Title;
70
71impl Validator<str> for Title {
72 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
73 if !s.is_case(Case::Title) {
74 ctx.issue(format!("'{s}' is not Title Case"));
75 }
76 }
77}
78
79#[validator]
84pub struct Upper;
85
86impl Validator<str> for Upper {
87 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
88 if !s.is_case(Case::Upper) {
89 ctx.issue(format!("'{s}' is not UPPER CASE"));
90 }
91 }
92}
93
94#[validator]
99pub struct UpperCamel;
100
101impl Validator<str> for UpperCamel {
102 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
103 if !s.is_case(Case::UpperCamel) {
104 ctx.issue(format!("'{s}' is not UpperCamelCase"));
105 }
106 }
107}
108
109#[validator]
114pub struct UpperSnake;
115
116impl Validator<str> for UpperSnake {
117 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
118 if !s.is_case(Case::UpperSnake) {
119 ctx.issue(format!("'{s}' is not UPPER_SNAKE_CASE"));
120 }
121 }
122}