icydb_model/base/validator/text/
case.rs1use crate::{prelude::*, visitor::Validator};
8
9use convert_case::{Case, Casing};
10
11#[validator]
16pub struct Camel;
17
18impl Validator<str> for Camel {
19 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
20 if s.to_case(Case::Camel) != s {
21 ctx.issue(format!("'{s}' is not camelCase"));
22 }
23 }
24}
25
26#[validator]
31pub struct Kebab;
32
33impl Validator<str> for Kebab {
34 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
35 if s.to_case(Case::Kebab) != s {
36 ctx.issue(format!("'{s}' is not kebab-case"));
37 }
38 }
39}
40
41#[validator]
46pub struct Lower;
47
48impl Validator<str> for Lower {
49 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
50 if s.to_case(Case::Lower) != s {
51 ctx.issue(format!("'{s}' is not lower case"));
52 }
53 }
54}
55
56#[validator]
61pub struct LowerUscore;
62
63impl Validator<str> for LowerUscore {
64 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
65 if !s.chars().all(|c| c.is_lowercase() || c == '_') {
66 ctx.issue(format!("'{s}' is not lower case with underscores"));
67 }
68 }
69}
70
71#[validator]
76pub struct Sentence;
77
78impl Validator<str> for Sentence {
79 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
80 if s.to_case(Case::Sentence) != s {
81 ctx.issue(format!("'{s}' is not Sentence case"));
82 }
83 }
84}
85
86#[validator]
91pub struct Snake;
92
93impl Validator<str> for Snake {
94 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
95 if s.to_case(Case::Snake) != s {
96 ctx.issue(format!("'{s}' is not snake_case"));
97 }
98 }
99}
100
101#[validator]
106pub struct Title;
107
108impl Validator<str> for Title {
109 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
110 if s.to_case(Case::Title) != s {
111 ctx.issue(format!("'{s}' is not Title Case"));
112 }
113 }
114}
115
116#[validator]
121pub struct Upper;
122
123impl Validator<str> for Upper {
124 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
125 if s.to_case(Case::Upper) != s {
126 ctx.issue(format!("'{s}' is not UPPER CASE"));
127 }
128 }
129}
130
131#[validator]
136pub struct UpperCamel;
137
138impl Validator<str> for UpperCamel {
139 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
140 if s.to_case(Case::UpperCamel) != s {
141 ctx.issue(format!("'{s}' is not UpperCamelCase"));
142 }
143 }
144}
145
146#[validator]
151pub struct UpperKebab;
152
153impl Validator<str> for UpperKebab {
154 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
155 if s.to_case(Case::UpperKebab) != s {
156 ctx.issue(format!("'{s}' is not UPPER-KEBAB-CASE"));
157 }
158 }
159}
160
161#[validator]
166pub struct UpperSnake;
167
168impl Validator<str> for UpperSnake {
169 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
170 if s.to_case(Case::UpperSnake) != s {
171 ctx.issue(format!("'{s}' is not UPPER_SNAKE_CASE"));
172 }
173 }
174}