WifiParsetest pass

This commit is contained in:
Henry Schimke
2022-09-03 19:15:50 -05:00
parent 65029818c7
commit 659c17af8d

View File

@@ -33,7 +33,10 @@ use urlencoding::decode;
use crate::{exceptions::Exceptions, RXingResult}; use crate::{exceptions::Exceptions, RXingResult};
use super::{ParsedClientResult, ParsedRXingResult, TextParsedRXingResult, TelRXingResultParser, ISBNRXingResultParser, WifiRXingResultParser}; use super::{
ISBNRXingResultParser, ParsedClientResult, ParsedRXingResult, TelRXingResultParser,
TextParsedRXingResult, WifiRXingResultParser,
};
/** /**
* <p>Abstract class representing the result of decoding a barcode, as more than * <p>Abstract class representing the result of decoding a barcode, as more than
@@ -47,7 +50,6 @@ use super::{ParsedClientResult, ParsedRXingResult, TextParsedRXingResult, TelRXi
* @author Sean Owen * @author Sean Owen
*/ */
pub trait RXingResultParser { pub trait RXingResultParser {
// const PARSERS: [&'static str; 20] = [ // const PARSERS: [&'static str; 20] = [
// "BookmarkDoCoMoRXingResultParser", // "BookmarkDoCoMoRXingResultParser",
// "AddressBookDoCoMoRXingResultParser", // "AddressBookDoCoMoRXingResultParser",
@@ -276,55 +278,81 @@ pub fn matchPrefixedField(
endChar: char, endChar: char,
trim: bool, trim: bool,
) -> Option<Vec<String>> { ) -> Option<Vec<String>> {
let mut matches: Vec<String> = Vec::new(); let mut matches = Vec::new();
let mut i = 0; let mut i = 0;
let max = rawText.len(); let max = rawText.len();
while i < max { while i < max {
i = if let Some(loc) = rawText[i..].find(prefix) { i = if let Some(loc) = rawText[i..].find(prefix) {
loc //rawText.indexOf(prefix, i); loc+i
} else { } else {
break; break;
}; };
// if i < 0 { // i = rawText.indexOf(prefix, i);
// if (i < 0) {
// break; // break;
// } // }
i += prefix.len(); // Skip past this prefix we found to start i += prefix.len(); // Skip past this prefix we found to start
let start = i; // Found the start of a match here let start = i; // Found the start of a match here
let mut more = true; let mut more = true;
while more { while more {
i = if let Some(loc) = rawText[i..].find(endChar) { let next_index = rawText[i..].find(endChar);
if next_index.is_none() {
// No terminating end character? uh, done. Set i such that loop terminates and break
i = rawText.len();
more = false;
continue;
} else {
i += next_index.unwrap();
}
if countPrecedingBackslashes(rawText, i) % 2 != 0 { if countPrecedingBackslashes(rawText, i) % 2 != 0 {
// semicolon was escaped (odd count of preceding backslashes) so continue // semicolon was escaped (odd count of preceding backslashes) so continue
i + 1 i += 1;
} else { } else {
// found a match // found a match
let mut element = unescapeBackslash(&rawText[start..loc+i]); let mut element = unescapeBackslash(&rawText[start..i]);
if trim { if trim {
element = element.to_string().trim().to_owned(); element = element.trim().to_owned();
} }
if !element.is_empty() { if !element.is_empty() {
matches.push(element); matches.push(element);
} }
i += 1;
more = false; more = false;
i + 1
} }
} else {
// No terminating end character? uh, done. Set i such that loop terminates and break // i = rawText.indexOf(endChar, i);
// if i < 0 {
// // No terminating end character? uh, done. Set i such that loop terminates and break
// i = rawText.len(); // i = rawText.len();
more = false; // more = false;
rawText.len() // } else if countPrecedingBackslashes(rawText, i) % 2 != 0 {
}; // // semicolon was escaped (odd count of preceding backslashes) so continue
// i+=1;
// } else {
// // found a match
// let element = unescapeBackslash(&rawText[start..start+i]);
// if (trim) {
// element = element.trim();
// }
// if (!element.isEmpty()) {
// matches.add(element);
// }
// i+=1;
// more = false;
// }
} }
} }
if matches.is_empty() { if matches.is_empty() {
return None; return None;
} }
Some(matches) Some(matches)
} }
pub fn countPrecedingBackslashes(s: &str, pos: usize) -> u32 { pub fn countPrecedingBackslashes(s: &str, pos: usize) -> u32 {
let mut count = 0; let mut count = 0;
for i in (0..pos - 1).rev() { for i in (0..pos).rev() {
// for (int i = pos - 1; i >= 0; i--) { // for (int i = pos - 1; i >= 0; i--) {
if s.chars().nth(i).unwrap() == '\\' { if s.chars().nth(i).unwrap() == '\\' {
count += 1; count += 1;