11use super :: Context ;
2- use crate :: handlers:: Handler ;
2+ use crate :: { handlers:: Handler , util :: is_marker } ;
33use regex:: Regex ;
44use tes3:: esp:: { Dialogue , DialogueInfo , EditorId , TES3Object , TypeInfo } ;
55
66pub struct UnicodeValidator {
77 invalid : Regex ,
8+ orc_name : Regex ,
9+ script_text : Regex ,
810}
911
1012impl Handler < ' _ > for UnicodeValidator {
@@ -27,6 +29,9 @@ impl Handler<'_> for UnicodeValidator {
2729 self . test ( record, "name" , & r. name , None ) ;
2830 }
2931 TES3Object :: Book ( r) => {
32+ if is_marker ( r) {
33+ return ;
34+ }
3035 self . test ( record, "name" , & r. name , None ) ;
3136 self . test ( record, "text" , & r. text , None ) ;
3237 }
@@ -111,12 +116,36 @@ impl Handler<'_> for UnicodeValidator {
111116 self . test ( record, "text" , & record. text , Some ( topic) ) ;
112117 self . test ( record, "script_text" , & record. script_text , Some ( topic) ) ;
113118 }
119+
120+ fn on_scriptline (
121+ & mut self ,
122+ _: & Context ,
123+ record : & TES3Object ,
124+ code : & str ,
125+ _: & str ,
126+ topic : & Dialogue ,
127+ code_original : & str ,
128+ ) {
129+ if let Some ( m) = self . script_text . find ( code) {
130+ let mut t = Some ( topic) ;
131+ if topic. id . is_empty ( ) {
132+ t = None ;
133+ }
134+ self . check_orc_name ( record, "script_text" , & code_original[ m. end ( ) ..] , t) ;
135+ }
136+ }
114137}
115138
116139impl UnicodeValidator {
117140 pub fn new ( ) -> Result < Self , regex:: Error > {
118141 let invalid = Regex :: new ( r"[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\uffff]" ) ?;
119- Ok ( Self { invalid } )
142+ let orc_name = Regex :: new ( " (Gr[oa]-[A-Za-z]|gr[oa]-[a-z])[a-z'-]+" ) ?;
143+ let script_text = Regex :: new ( "(say|messagebox)[, ]" ) ?;
144+ Ok ( Self {
145+ invalid,
146+ orc_name,
147+ script_text,
148+ } )
120149 }
121150
122151 fn test < T > ( & self , record : & T , field : & str , value : & str , topic : Option < & Dialogue > )
@@ -143,5 +172,34 @@ impl UnicodeValidator {
143172 ) ;
144173 }
145174 }
175+ if field != "id" && field != "script_text" {
176+ self . check_orc_name ( record, field, value, topic) ;
177+ }
178+ }
179+
180+ fn check_orc_name < T > ( & self , record : & T , field : & str , value : & str , topic : Option < & Dialogue > )
181+ where
182+ T : EditorId + TypeInfo ,
183+ {
184+ if let Some ( m) = self . orc_name . find ( value) {
185+ if let Some ( dial) = topic {
186+ println ! (
187+ "{} {} in topic {} contains odd orc name{} in field {}" ,
188+ record. type_name( ) ,
189+ record. editor_id( ) ,
190+ dial. id,
191+ m. as_str( ) ,
192+ field
193+ ) ;
194+ } else {
195+ println ! (
196+ "{} {} contains contains odd orc name{} in field {}" ,
197+ record. type_name( ) ,
198+ record. editor_id( ) ,
199+ m. as_str( ) ,
200+ field
201+ ) ;
202+ }
203+ }
146204 }
147205}
0 commit comments