ASCII Case Insensitive Comparison
Compare tokens with eq_ignore_ascii_case to skip allocations, and know when to fall back to full Unicode to_lowercase for non-ASCII text.
Code
fn main() {
// eq_ignore_ascii_case:零分配的大小写不敏感比较
let token = "BEARER abc.def";
println!("ascii eq: {}", token[..6].eq_ignore_ascii_case("bearer"));
// 非 ASCII 文本必须走 to_lowercase:ASCII 方法只覆盖 A-Z
let unicode = "ÄPFEL";
println!("ascii miss: {}", unicode.eq_ignore_ascii_case("äpfel"));
println!("unicode ok: {}", unicode.to_lowercase() == "äpfel");
// make_ascii_lowercase 就地转换:已有 String 时避免新分配
let mut command = String::from("GET");
command.make_ascii_lowercase();
println!("command: {command}");
}How the snippet works
ASCII Case Insensitive Comparison is built around the function main.
Applying it
Running the file prints labeled results such as ascii eq:, ascii miss:, unicode ok: — each operation’s effect is visible in the output.
Statements that matter
let mut command = String::from("GET");
command.make_ascii_lowercase();
let token = "BEARER abc.def";
Interactive Tools for This Topic
Basic & Bearer Auth Header ToolEncode and decode HTTP Authorization Basic and Bearer headers locally with UTF-8 Base64 validation and automatic JWT claim and expiry inspection.JWT Expiry CalculatorDecode a JWT payload and convert its exp, iat, and nbf claims into UTC ISO timestamps, with an expired-or-valid verdict.ASCII Table ReferenceLook up any ASCII code point 0-127 by decimal, hex, or character and see the binary, octal, and control-name view.Case ConverterConvert text between lowercase, uppercase, title, sentence, camelCase, snake_case, and kebab-case while preserving Unicode letters and numbers.
FAQ
- What does ASCII Case Insensitive Comparison print when run?
- Invoke the file as-is — the `ascii eq:`, `ascii miss:`, `unicode ok:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.