refactor to use common result type

This commit is contained in:
Vukašin Stepanović
2023-02-14 22:56:03 +00:00
parent 145cf704fe
commit 8ee616d96b
160 changed files with 829 additions and 901 deletions

View File

@@ -16,6 +16,7 @@
// package com.google.zxing.client.result;
use crate::common::Result;
use crate::exceptions::Exceptions;
use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser};
@@ -79,7 +80,7 @@ impl AddressBookParsedRXingResult {
email_types: Vec<String>,
addresses: Vec<String>,
address_types: Vec<String>,
) -> Result<Self, Exceptions> {
) -> Result<Self> {
Self::with_details(
names,
Vec::new(),
@@ -118,7 +119,7 @@ impl AddressBookParsedRXingResult {
title: String,
urls: Vec<String>,
geo: Vec<String>,
) -> Result<Self, Exceptions> {
) -> Result<Self> {
if phone_numbers.len() != phone_types.len() && !phone_types.is_empty() {
return Err(Exceptions::IllegalArgumentException(Some(
"Phone numbers and types lengths differ".to_owned(),

View File

@@ -32,6 +32,7 @@ use chrono_tz::Tz;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::common::Result;
use crate::exceptions::Exceptions;
use super::{maybe_append_multiple, maybe_append_string, ParsedRXingResult, ParsedRXingResultType};
@@ -109,7 +110,7 @@ impl CalendarParsedRXingResult {
description: String,
latitude: f64,
longitude: f64,
) -> Result<Self, Exceptions> {
) -> Result<Self> {
let start = Self::parseDate(startString.clone())?;
let end = if endString.is_empty() {
let durationMS = Self::parseDurationMS(&durationString)?;
@@ -164,7 +165,7 @@ impl CalendarParsedRXingResult {
* @param when The string to parse
* @throws ParseException if not able to parse as a date
*/
fn parseDate(when: String) -> Result<i64, Exceptions> {
fn parseDate(when: String) -> Result<i64> {
if !DATE_TIME.is_match(&when) {
return Err(Exceptions::ParseException(Some(when)));
}
@@ -243,7 +244,7 @@ impl CalendarParsedRXingResult {
}
}
fn parseDurationMS(durationString: &str) -> Result<i64, Exceptions> {
fn parseDurationMS(durationString: &str) -> Result<i64> {
if durationString.is_empty() {
return Ok(-1);
}
@@ -279,7 +280,7 @@ impl CalendarParsedRXingResult {
// return durationMS;
}
fn parseDateTimeString(dateTimeString: &str) -> Result<i64, Exceptions> {
fn parseDateTimeString(dateTimeString: &str) -> Result<i64> {
if let Ok(dtm) = DateTime::parse_from_str(dateTimeString, "%Y%m%dT%H%M%S") {
Ok(dtm.timestamp())
} else {

View File

@@ -33,7 +33,7 @@ use urlencoding::decode;
use once_cell::sync::Lazy;
use crate::{exceptions::Exceptions, RXingResult};
use crate::{common::Result, exceptions::Exceptions, RXingResult};
use super::{
AddressBookAUResultParser, AddressBookDoCoMoResultParser, BizcardResultParser,
@@ -296,7 +296,7 @@ pub fn appendKeyValue(keyValue: &str, result: &mut HashMap<String, String>) {
// }
}
pub fn urlDecode(encoded: &str) -> Result<String, Exceptions> {
pub fn urlDecode(encoded: &str) -> Result<String> {
if let Ok(decoded) = decode(encoded) {
Ok(decoded.to_string())
} else {

View File

@@ -17,7 +17,8 @@
use regex::Regex;
use crate::{
client::result::VINParsedRXingResult, exceptions::Exceptions, BarcodeFormat, RXingResult,
client::result::VINParsedRXingResult, common::Result, exceptions::Exceptions, BarcodeFormat,
RXingResult,
};
use super::ParsedClientResult;
@@ -67,7 +68,7 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
const IOQ: &str = "[IOQ]";
const AZ09: &str = "[A-Z0-9]{17}";
fn check_checksum(vin: &str) -> Result<bool, Exceptions> {
fn check_checksum(vin: &str) -> Result<bool> {
let mut sum = 0;
for i in 0..vin.len() {
sum += vin_position_weight(i + 1)? as u32
@@ -85,7 +86,7 @@ fn check_checksum(vin: &str) -> Result<bool, Exceptions> {
Ok(check_to_char == expected_check_char)
}
fn vin_char_value(c: char) -> Result<u32, Exceptions> {
fn vin_char_value(c: char) -> Result<u32> {
match c {
'A'..='I' => Ok((c as u8 as u32 - b'A' as u32) + 1),
'J'..='R' => Ok((c as u8 as u32 - b'J' as u32) + 1),
@@ -97,7 +98,7 @@ fn vin_char_value(c: char) -> Result<u32, Exceptions> {
}
}
fn vin_position_weight(position: usize) -> Result<usize, Exceptions> {
fn vin_position_weight(position: usize) -> Result<usize> {
match position {
1..=7 => Ok(9 - position),
8 => Ok(10),
@@ -109,7 +110,7 @@ fn vin_position_weight(position: usize) -> Result<usize, Exceptions> {
}
}
fn check_char(remainder: u8) -> Result<char, Exceptions> {
fn check_char(remainder: u8) -> Result<char> {
match remainder {
0..=9 => Ok((b'0' + remainder) as char),
10 => Ok('X'),
@@ -119,7 +120,7 @@ fn check_char(remainder: u8) -> Result<char, Exceptions> {
}
}
fn model_year(c: char) -> Result<u32, Exceptions> {
fn model_year(c: char) -> Result<u32> {
match c {
'E'..='H' => Ok((c as u8 as u32 - b'E' as u32) + 1984),
'J'..='N' => Ok((c as u8 as u32 - b'J' as u32) + 1988),