mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04: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,14 +131,14 @@ pub fn parseRXingResult(the_rxing_result: &RXingResult) -> ParsedClientResult {
|
||||
&SMTPResultParser::parse,
|
||||
&TelResultParser::parse,
|
||||
&SMSMMSResultParser::parse,
|
||||
&SMSMMSResultParser::parse,
|
||||
&SMSTOMMSTOResultParser::parse,
|
||||
&GeoResultParser::parse,
|
||||
&WifiResultParser::parse,
|
||||
&URLTOResultParser::parse,
|
||||
&URIResultParser::parse,
|
||||
&ISBNResultParser::parse,
|
||||
&ProductResultParser::parse,
|
||||
& ExpandedProductResultParser::parse,
|
||||
&ExpandedProductResultParser::parse,
|
||||
&VINResultParser::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() {
|
||||
result.push('\n');
|
||||
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() {
|
||||
result.push('\n');
|
||||
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(
|
||||
|
||||
@@ -24,106 +24,100 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser};
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct SMSParsedRXingResult {
|
||||
|
||||
numbers: Vec<String>,
|
||||
vias: Vec<String>,
|
||||
subject:String,
|
||||
body:String,
|
||||
pub struct SMSParsedRXingResult {
|
||||
numbers: Vec<String>,
|
||||
vias: Vec<String>,
|
||||
subject: String,
|
||||
body: String,
|
||||
}
|
||||
|
||||
impl ParsedRXingResult for SMSParsedRXingResult {
|
||||
fn getType(&self) -> super::ParsedRXingResultType {
|
||||
ParsedRXingResultType::SMS
|
||||
ParsedRXingResultType::SMS
|
||||
}
|
||||
|
||||
fn getDisplayRXingResult(&self) -> String {
|
||||
let mut result = String::with_capacity(100);
|
||||
ResultParser::maybe_append_multiple(&self.numbers, &mut result);
|
||||
ResultParser::maybe_append_string(&self.subject, &mut result);
|
||||
ResultParser::maybe_append_string(&self.body, &mut result);
|
||||
result
|
||||
let mut result = String::with_capacity(100);
|
||||
ResultParser::maybe_append_multiple(&self.numbers, &mut result);
|
||||
ResultParser::maybe_append_string(&self.subject, &mut result);
|
||||
ResultParser::maybe_append_string(&self.body, &mut result);
|
||||
result
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl SMSParsedRXingResult {
|
||||
|
||||
pub fn with_singles( number:String,
|
||||
via:String,
|
||||
subject:String,
|
||||
body:String) -> Self {
|
||||
Self{
|
||||
numbers: vec![number],
|
||||
vias: vec![via],
|
||||
subject,
|
||||
body,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn with_arrays( numbers :Vec<String>,
|
||||
vias:Vec<String>,
|
||||
subject:String,
|
||||
body:String) -> Self{
|
||||
Self {
|
||||
numbers,
|
||||
vias,
|
||||
subject,
|
||||
body,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getSMSURI(&self) -> String {
|
||||
let mut result = String::new();
|
||||
result.push_str("sms:");
|
||||
let mut first = true;
|
||||
for i in 0..self.numbers.len() {
|
||||
// for (int i = 0; i < numbers.length; i++) {
|
||||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
result.push(',');
|
||||
}
|
||||
result.push_str(&self.numbers[i]);
|
||||
if !self.vias.is_empty() {
|
||||
result.push_str(";via=");
|
||||
result.push_str(&self.vias[i]);
|
||||
}
|
||||
}
|
||||
let has_body = !self.body.is_empty();
|
||||
let has_subject = !self.subject.is_empty();
|
||||
if has_body || has_subject {
|
||||
result.push('?');
|
||||
if has_body {
|
||||
result.push_str("body=");
|
||||
result.push_str(&self.body);
|
||||
}
|
||||
if has_subject {
|
||||
if has_body {
|
||||
result.push('&');
|
||||
pub fn with_singles(number: String, via: String, subject: String, body: String) -> Self {
|
||||
Self {
|
||||
numbers: vec![number],
|
||||
vias: vec![via],
|
||||
subject,
|
||||
body,
|
||||
}
|
||||
result.push_str("subject=");
|
||||
result.push_str(&self.subject);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn getNumbers(&self) -> &Vec<String> {
|
||||
&self.numbers
|
||||
}
|
||||
pub fn with_arrays(
|
||||
numbers: Vec<String>,
|
||||
vias: Vec<String>,
|
||||
subject: String,
|
||||
body: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
numbers,
|
||||
vias,
|
||||
subject,
|
||||
body,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getVias(&self) -> &Vec<String> {
|
||||
&self. vias
|
||||
}
|
||||
pub fn getSMSURI(&self) -> String {
|
||||
let mut result = String::new();
|
||||
result.push_str("sms:");
|
||||
let mut first = true;
|
||||
for i in 0..self.numbers.len() {
|
||||
// for (int i = 0; i < numbers.length; i++) {
|
||||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
result.push(',');
|
||||
}
|
||||
result.push_str(&self.numbers[i]);
|
||||
if !self.vias.is_empty() {
|
||||
result.push_str(";via=");
|
||||
result.push_str(&self.vias[i]);
|
||||
}
|
||||
}
|
||||
let has_body = !self.body.is_empty();
|
||||
let has_subject = !self.subject.is_empty();
|
||||
if has_body || has_subject {
|
||||
result.push('?');
|
||||
if has_body {
|
||||
result.push_str("body=");
|
||||
result.push_str(&self.body);
|
||||
}
|
||||
if has_subject {
|
||||
if has_body {
|
||||
result.push('&');
|
||||
}
|
||||
result.push_str("subject=");
|
||||
result.push_str(&self.subject);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn getSubject(&self) -> &str {
|
||||
&self. subject
|
||||
}
|
||||
pub fn getNumbers(&self) -> &Vec<String> {
|
||||
&self.numbers
|
||||
}
|
||||
|
||||
pub fn getBody(&self) -> &str {
|
||||
&self. body
|
||||
}
|
||||
}
|
||||
pub fn getVias(&self) -> &Vec<String> {
|
||||
&self.vias
|
||||
}
|
||||
|
||||
pub fn getSubject(&self) -> &str {
|
||||
&self.subject
|
||||
}
|
||||
|
||||
pub fn getBody(&self) -> &str {
|
||||
&self.body
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user