Skip to content

Commit 70bcc39

Browse files
committed
Report orc names
1 parent 2ae196d commit 70bcc39

9 files changed

Lines changed: 78 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "StandardsValidator"
3-
version = "2.21.2"
3+
version = "2.22.0"
44
edition = "2021"
55

66
[dependencies]

src/handlers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub trait Handler<'a> {
3737
code: &str,
3838
comment: &str,
3939
topic: &Dialogue,
40+
code_original: &str,
4041
) {
4142
}
4243

@@ -144,9 +145,10 @@ impl<'a> Handler<'a> for Handlers<'a> {
144145
code: &str,
145146
comment: &str,
146147
topic: &Dialogue,
148+
code_original: &str,
147149
) {
148150
for handler in &mut self.handlers {
149-
handler.on_scriptline(context, record, code, comment, topic);
151+
handler.on_scriptline(context, record, code, comment, topic, code_original);
150152
}
151153
}
152154

src/validators.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl<'a> Validator<'a> {
163163
&code.to_ascii_lowercase(),
164164
comment,
165165
topic,
166+
code,
166167
);
167168
}
168169
}

src/validators/orphans.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,15 @@ impl Handler<'_> for OrphanValidator {
165165
self.used_objects.insert(entry.1.to_ascii_lowercase());
166166
}
167167

168-
fn on_scriptline(&mut self, _: &Context, _: &TES3Object, code: &str, _: &str, _: &Dialogue) {
168+
fn on_scriptline(
169+
&mut self,
170+
_: &Context,
171+
_: &TES3Object,
172+
code: &str,
173+
_: &str,
174+
_: &Dialogue,
175+
_: &str,
176+
) {
169177
if code.is_empty() {
170178
return;
171179
}

src/validators/scripts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl Handler<'_> for ScriptValidator {
147147
code: &str,
148148
comment: &str,
149149
topic: &Dialogue,
150+
_: &str,
150151
) {
151152
if !code.is_empty() && self.position.is_match(code) {
152153
if let TES3Object::DialogueInfo(info) = record {

src/validators/todo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl Handler<'_> for ToDoValidator {
1515
_: &str,
1616
comment: &str,
1717
topic: &Dialogue,
18+
_: &str,
1819
) {
1920
if self.todo.is_match(comment) {
2021
if let TES3Object::Script(script) = record {

src/validators/unicode.rs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use super::Context;
2-
use crate::handlers::Handler;
2+
use crate::{handlers::Handler, util::is_marker};
33
use regex::Regex;
44
use tes3::esp::{Dialogue, DialogueInfo, EditorId, TES3Object, TypeInfo};
55

66
pub struct UnicodeValidator {
77
invalid: Regex,
8+
orc_name: Regex,
9+
script_text: Regex,
810
}
911

1012
impl 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

116139
impl 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
}

src/validators/uniques.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl Handler<'_> for UniquesValidator {
9797
code: &str,
9898
_: &str,
9999
topic: &Dialogue,
100+
_: &str,
100101
) {
101102
if self.create_func.is_match(code) {
102103
for uni in &self.uniques {

0 commit comments

Comments
 (0)