From c6fcc212d14ebd60620e2e06428fc309e87836ca Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Thu, 4 Nov 2021 15:34:49 +0000 Subject: [PATCH] Simplified a bit of internal Rust code. --- rust/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index cb87c37..a2ee375 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1010,7 +1010,7 @@ impl QrSegment { let mut accumdata: u32 = 0; let mut accumcount: u32 = 0; for c in text.chars() { - let i: usize = ALPHANUMERIC_CHARSET.iter().position(|&x| x == c) + let i: usize = ALPHANUMERIC_CHARSET.find(c) .expect("String contains unencodable characters in alphanumeric mode"); accumdata = accumdata * 45 + (i as u32); accumcount += 1; @@ -1133,7 +1133,7 @@ impl QrSegment { /// A string is encodable iff each character is in the following set: 0 to 9, A to Z /// (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. pub fn is_alphanumeric(text: &str) -> bool { - text.chars().all(|c| ALPHANUMERIC_CHARSET.contains(&c)) + text.chars().all(|c| ALPHANUMERIC_CHARSET.contains(c)) } } @@ -1141,9 +1141,7 @@ impl QrSegment { // The set of all legal characters in alphanumeric mode, // where each character value maps to the index in the string. -static ALPHANUMERIC_CHARSET: [char; 45] = ['0','1','2','3','4','5','6','7','8','9', - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', - ' ','$','%','*','+','-','.','/',':']; +static ALPHANUMERIC_CHARSET: &str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";