Update to first pleasable version #13

Merged
hodasemi merged 6 commits from dev into master 2023-01-23 20:38:53 +00:00
Showing only changes of commit eac4f60acf - Show all commits

View file

@ -108,7 +108,26 @@ impl LeaderBoardEntry {
pub fn change_name(&mut self, name: String) -> Result<()> {
self.name = name;
self.name_label.set_text(&self.name)
self.name_label.set_text(Self::check_string(&self.name))
}
fn check_string(s: &str) -> String {
std::str::from_utf8(
&s.as_bytes()
.iter()
.filter(|&&b| {
(b > 96 && b < 123) // small letters
|| (b > 64 && b < 91) // big letters
|| (b > 47 && b < 58) // numbers
|| b == 45 // dash
|| b == 95 // underscore
|| b == 32 // whitespace
})
.map(|&b| b)
.collect::<Vec<u8>>(),
)
.unwrap()
.to_string()
}
pub fn snippet(&self) -> Arc<GuiSnippet> {
@ -253,3 +272,28 @@ impl LeaderBoardEntry {
self.place_updated = false;
}
}
#[cfg(test)]
mod test {
#[test]
fn test_string_replacement() {
let s_orig = "blaü";
let s = super::LeaderBoardEntry::check_string(s_orig);
println!("{} {:?}", s_orig, s);
for b in s.as_bytes() {
println!("{}", b)
}
println!();
let s2_orig = "az AZ 09 # - _";
let s2 = super::LeaderBoardEntry::check_string(s2_orig);
println!("{} {:?}", s2_orig, s2);
for b in s2.as_bytes() {
println!("{}", *b);
}
}
}