Skip to content

Commit

Permalink
unicode: Fix conversion of green numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikpe committed May 9, 2024
1 parent 52d4ec6 commit 1574c08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Utils for Quake strings and characters."
keywords = ["quake", "quakeworld", "strings"]
repository = "https://github.com/vikpe/quake_text"
authors = ["Viktor Persson <viktor.persson@arcsin.se>"]
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "MIT"
include = [
Expand Down
9 changes: 9 additions & 0 deletions src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub fn to_utf8(ustr: &str) -> String {
.iter()
.map(|c| c & 127) // strip color
.map(|c| match c {
16 => '[',
17 => ']',
18..=27 => char::from(c + 30),
32..=126 => char::from(c),
0 | 5 | 14 | 15 | 28 => '•',
_ => ' ',
Expand Down Expand Up @@ -56,6 +59,12 @@ mod tests {

#[test]
fn test_to_utf8() {
let gold_brackets = (16..=17).map(char::from).collect::<String>();
assert_eq!(to_utf8(&gold_brackets), "[]");

let green_numbers = (18..=27).map(char::from).collect::<String>();
assert_eq!(to_utf8(&green_numbers), "0123456789");

let ascii_chars = (32..=126).map(char::from).collect::<String>();
assert_eq!(to_utf8(&ascii_chars), ascii_chars);

Expand Down

0 comments on commit 1574c08

Please sign in to comment.