mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-28 05:12:34 +00:00
all client parsing tests pass except known upce
This commit is contained in:
@@ -47,7 +47,8 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
|
||||
let phoneNumbers = matchMultipleValuePrefix("TEL", &rawText);
|
||||
let emails = matchMultipleValuePrefix("MAIL", &rawText);
|
||||
let note = ResultParser::matchSinglePrefixedField("MEMORY:", &rawText, '\r', false)?;
|
||||
let note = ResultParser::matchSinglePrefixedField("MEMORY:", &rawText, '\r', false)
|
||||
.unwrap_or_default();
|
||||
let address = ResultParser::matchSinglePrefixedField("ADD:", &rawText, '\r', true);
|
||||
let addresses = if address.is_none() {
|
||||
Vec::new()
|
||||
@@ -55,7 +56,11 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
vec![address?]
|
||||
};
|
||||
if let Ok(new_data) = AddressBookParsedRXingResult::with_details(
|
||||
ResultParser::maybeWrap(name)?,
|
||||
if let Some(nm) = ResultParser::maybeWrap(name) {
|
||||
nm
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
Vec::new(),
|
||||
"".to_owned(),
|
||||
phoneNumbers,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
// import java.util.regex.Matcher;
|
||||
// import java.util.regex.Pattern;
|
||||
|
||||
use chrono::{Date, DateTime, NaiveDateTime, TimeZone, Utc};
|
||||
use chrono::{Date, DateTime, Local, NaiveDateTime, TimeZone, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use regex::Regex;
|
||||
|
||||
@@ -229,6 +229,17 @@ impl CalendarParsedRXingResult {
|
||||
))),
|
||||
};
|
||||
}
|
||||
|
||||
// Try a final time with an exact length
|
||||
if when.len() == 15 {
|
||||
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%S") {
|
||||
Ok(dtm) => Ok(dtm.timestamp()),
|
||||
Err(e) => Err(Exceptions::ParseException(format!(
|
||||
"couldn't parse local time: {}",
|
||||
e
|
||||
))),
|
||||
};
|
||||
}
|
||||
Self::parseDateTimeString(&when)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
// import java.util.Locale;
|
||||
// import java.util.TimeZone;
|
||||
|
||||
use chrono::{TimeZone, Utc};
|
||||
use chrono::{Local, TimeZone, Utc};
|
||||
|
||||
use crate::{client::result::ParsedRXingResult, BarcodeFormat, RXingResult};
|
||||
|
||||
@@ -390,9 +390,9 @@ fn test_uri() {
|
||||
|
||||
#[test]
|
||||
fn test_geo() {
|
||||
do_test_rxing_result("geo:1,2", "1.0, 2.0", ParsedRXingResultType::GEO);
|
||||
do_test_rxing_result("GEO:1,2", "1.0, 2.0", ParsedRXingResultType::GEO);
|
||||
do_test_rxing_result("geo:1,2,3", "1.0, 2.0, 3.0m", ParsedRXingResultType::GEO);
|
||||
do_test_rxing_result("geo:1,2", "1, 2", ParsedRXingResultType::GEO);
|
||||
do_test_rxing_result("GEO:1,2", "1, 2", ParsedRXingResultType::GEO);
|
||||
do_test_rxing_result("geo:1,2,3", "1, 2, 3m", ParsedRXingResultType::GEO);
|
||||
do_test_rxing_result(
|
||||
"geo:80.33,-32.3344,3.35",
|
||||
"80.33, -32.3344, 3.35m",
|
||||
@@ -501,7 +501,7 @@ fn test_vevent() {
|
||||
|
||||
fn format_date(year: i32, month: u32, day: u32) -> String {
|
||||
let dtm = Utc.ymd(year, month, day);
|
||||
dtm.format("%Y%m%D").to_string()
|
||||
dtm.format("%F").to_string()
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.clear();
|
||||
// cal.set(year, month - 1, day);
|
||||
@@ -510,7 +510,7 @@ fn format_date(year: i32, month: u32, day: u32) -> String {
|
||||
|
||||
fn format_time(year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32) -> String {
|
||||
let dtm = Utc.ymd(year, month, day).and_hms(hour, min, sec);
|
||||
dtm.format("%C").to_string()
|
||||
dtm.format("%c").to_string()
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.clear();
|
||||
// cal.set(year, month - 1, day, hour, min, sec);
|
||||
@@ -624,7 +624,12 @@ fn test_mmsto() {
|
||||
}
|
||||
|
||||
fn do_test_rxing_result(contents: &str, golden_rxing_result: &str, r_type: ParsedRXingResultType) {
|
||||
do_test_rxing_result_long(contents, golden_rxing_result, r_type, BarcodeFormat::QR_CODE);
|
||||
do_test_rxing_result_long(
|
||||
contents,
|
||||
golden_rxing_result,
|
||||
r_type,
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
// QR code is arbitrary
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,11 @@ use crate::{exceptions::Exceptions, RXingResult};
|
||||
|
||||
use super::{
|
||||
AddressBookAUResultParser, AddressBookDoCoMoResultParser, BizcardResultParser,
|
||||
BookmarkDoCoMoResultParser, EmailAddressResultParser, EmailDoCoMoResultParser, GeoResultParser,
|
||||
ISBNResultParser, ParsedClientResult, ParsedRXingResult, ProductResultParser,
|
||||
SMSMMSResultParser, SMTPResultParser, TelResultParser, TextParsedRXingResult, URIResultParser,
|
||||
URLTOResultParser, VCardResultParser, VEventResultParser, VINResultParser, WifiResultParser, ExpandedProductResultParser,
|
||||
BookmarkDoCoMoResultParser, EmailAddressResultParser, EmailDoCoMoResultParser,
|
||||
ExpandedProductResultParser, GeoResultParser, ISBNResultParser, ParsedClientResult,
|
||||
ParsedRXingResult, ProductResultParser, SMSMMSResultParser, SMTPResultParser, TelResultParser,
|
||||
TextParsedRXingResult, URIResultParser, URLTOResultParser, VCardResultParser,
|
||||
VEventResultParser, VINResultParser, WifiResultParser, SMSTOMMSTOResultParser,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -130,7 +131,7 @@ pub fn parseRXingResult(the_rxing_result: &RXingResult) -> ParsedClientResult {
|
||||
&SMTPResultParser::parse,
|
||||
&TelResultParser::parse,
|
||||
&SMSMMSResultParser::parse,
|
||||
&SMSMMSResultParser::parse,
|
||||
&SMSTOMMSTOResultParser::parse,
|
||||
&GeoResultParser::parse,
|
||||
&WifiResultParser::parse,
|
||||
&URLTOResultParser::parse,
|
||||
@@ -161,7 +162,9 @@ pub fn parseRXingResult(the_rxing_result: &RXingResult) -> ParsedClientResult {
|
||||
|
||||
pub fn maybe_append_string(value: &str, result: &mut String) {
|
||||
if !value.is_empty() {
|
||||
if !result.is_empty() {
|
||||
result.push('\n');
|
||||
}
|
||||
result.push_str(value);
|
||||
}
|
||||
}
|
||||
@@ -171,7 +174,9 @@ pub fn maybe_append_multiple(value: &[String], result: &mut String) {
|
||||
for s in value {
|
||||
// for (String s : value) {
|
||||
if !s.is_empty() {
|
||||
if !result.is_empty() {
|
||||
result.push('\n');
|
||||
}
|
||||
result.push_str(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
add_number_via(
|
||||
&mut numbers,
|
||||
&mut vias,
|
||||
&sms_uriwithout_query[(last_comma) as usize..],
|
||||
&sms_uriwithout_query[(if last_comma > 0 { last_comma + 1} else {last_comma}) as usize..],
|
||||
);
|
||||
|
||||
Some(ParsedClientResult::SMSResult(
|
||||
|
||||
@@ -25,7 +25,6 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser};
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct SMSParsedRXingResult {
|
||||
|
||||
numbers: Vec<String>,
|
||||
vias: Vec<String>,
|
||||
subject: String,
|
||||
@@ -44,15 +43,10 @@ impl ParsedRXingResult for SMSParsedRXingResult {
|
||||
ResultParser::maybe_append_string(&self.body, &mut result);
|
||||
result
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl SMSParsedRXingResult {
|
||||
|
||||
pub fn with_singles( number:String,
|
||||
via:String,
|
||||
subject:String,
|
||||
body:String) -> Self {
|
||||
pub fn with_singles(number: String, via: String, subject: String, body: String) -> Self {
|
||||
Self {
|
||||
numbers: vec![number],
|
||||
vias: vec![via],
|
||||
@@ -61,12 +55,12 @@ impl SMSParsedRXingResult {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn with_arrays( numbers :Vec<String>,
|
||||
pub fn with_arrays(
|
||||
numbers: Vec<String>,
|
||||
vias: Vec<String>,
|
||||
subject: String,
|
||||
body:String) -> Self{
|
||||
body: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
numbers,
|
||||
vias,
|
||||
|
||||
Reference in New Issue
Block a user