Add support for non-latin text
My brother in law is Chinese and he is currently learning how to touch-type on the computer. Even though he is used to writing English texts, I suggested him to practice writing Chinese, too.
When using typeracer…
typeracer -r 你好
…this is what happens:
thread 'main' panicked at 'byte index 2 is not a char boundary; it is inside '你' (bytes 0..3) of `你好 `', src/libcore/str/mod.rs:2154:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I had a quick look and believe given some tests using non-latin input, support could be added without big problems, but not without efforts. My default way to handle this is to use the unicode-segmentation crate and work with graphemes exclusively.
Making typeracer
more international would absolutely set it apart and make it a testament to the inclusiveness of Rust and its community :).
Full stacktrace - note how 'something' on my system is messing with unicode and I seem to be unable to copy it cleanly. I attached a file to show how it looks in the terminal.
thread 'main' panicked at 'byte index 2 is not a char boundary; it is inside '你' (bytes 0..3) of `你好 `', src/libcore/str/mod.rs:2154:5
stack backtrace:
0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
1: core::fmt::write
2: std::io::Write::write_fmt
3: std::panicking::default_hook::{{closure}}
4: std::panicking::rust_panic_with_hook
5: rust_begin_unwind
6: core::panicking::panic_fmt
7: core::str::slice_error_fail
8: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::{{closure}}
9: typeracer::main
10: std::rt::lang_start::{{closure}}
11: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.