mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
smsmms pass
This commit is contained in:
@@ -34,8 +34,8 @@ use urlencoding::decode;
|
|||||||
use crate::{exceptions::Exceptions, RXingResult};
|
use crate::{exceptions::Exceptions, RXingResult};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ISBNResultParser, ParsedClientResult, ParsedRXingResult, TelResultParser,
|
GeoResultParser, ISBNResultParser, ParsedClientResult, ParsedRXingResult, SMSMMSResultParser,
|
||||||
TextParsedRXingResult, WifiResultParser, GeoResultParser, SMSMMSResultParser
|
TelResultParser, TextParsedRXingResult, WifiResultParser,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,7 +115,7 @@ pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
|
|||||||
&TelResultParser::parse,
|
&TelResultParser::parse,
|
||||||
&SMSMMSResultParser::parse,
|
&SMSMMSResultParser::parse,
|
||||||
// new SMSTOMMSTORXingResultParser(),
|
// new SMSTOMMSTORXingResultParser(),
|
||||||
&GeoResultParser::parse,
|
&GeoResultParser::parse,
|
||||||
&WifiResultParser::parse,
|
&WifiResultParser::parse,
|
||||||
// new URLTORXingResultParser(),
|
// new URLTORXingResultParser(),
|
||||||
// new URIRXingResultParser(),
|
// new URIRXingResultParser(),
|
||||||
@@ -154,8 +154,10 @@ pub fn maybe_append_multiple(value: &[String], result: &mut String) {
|
|||||||
if !value.is_empty() {
|
if !value.is_empty() {
|
||||||
for s in value {
|
for s in value {
|
||||||
// for (String s : value) {
|
// for (String s : value) {
|
||||||
result.push('\n');
|
if !s.is_empty() {
|
||||||
result.push_str(s);
|
result.push('\n');
|
||||||
|
result.push_str(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,7 +287,7 @@ pub fn matchPrefixedField(
|
|||||||
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+i
|
loc + i
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,7 +84,12 @@ fn do_test(contents: &str, number: &str, subject: &str, body: &str, via: &str, p
|
|||||||
assert_eq!(&vec![number], smsRXingResult.getNumbers());
|
assert_eq!(&vec![number], smsRXingResult.getNumbers());
|
||||||
assert_eq!(subject, smsRXingResult.getSubject());
|
assert_eq!(subject, smsRXingResult.getSubject());
|
||||||
assert_eq!(body, smsRXingResult.getBody());
|
assert_eq!(body, smsRXingResult.getBody());
|
||||||
assert_eq!(&vec![via], smsRXingResult.getVias());
|
let vec_via = if via.is_empty() {
|
||||||
|
vec![]
|
||||||
|
}else {
|
||||||
|
vec![via]
|
||||||
|
};
|
||||||
|
assert_eq!(&vec_via, smsRXingResult.getVias());
|
||||||
assert_eq!(parsedURI, smsRXingResult.getSMSURI());
|
assert_eq!(parsedURI, smsRXingResult.getSMSURI());
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected ParsedClientResult::SMSResult");
|
panic!("Expected ParsedClientResult::SMSResult");
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ use super::{ParsedClientResult, ResultParser, SMSParsedRXingResult};
|
|||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||||
let rawText = ResultParser::getMassagedText(result);
|
let raw_text = ResultParser::getMassagedText(result);
|
||||||
if !(rawText.starts_with("sms:")
|
if !(raw_text.starts_with("sms:")
|
||||||
|| rawText.starts_with("SMS:")
|
|| raw_text.starts_with("SMS:")
|
||||||
|| rawText.starts_with("mms:")
|
|| raw_text.starts_with("mms:")
|
||||||
|| rawText.starts_with("MMS:"))
|
|| raw_text.starts_with("MMS:"))
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
|||||||
let mut querySyntax = false;
|
let mut querySyntax = false;
|
||||||
|
|
||||||
// Check up front if this is a URI syntax string with query arguments
|
// Check up front if this is a URI syntax string with query arguments
|
||||||
if let Some(name_value_pairs) = ResultParser::parseNameValuePairs(&rawText) {
|
if let Some(name_value_pairs) = ResultParser::parseNameValuePairs(&raw_text) {
|
||||||
if !name_value_pairs.is_empty() {
|
if !name_value_pairs.is_empty() {
|
||||||
subject = String::from(name_value_pairs.get("subject").unwrap_or(&"".to_owned()));
|
subject = String::from(name_value_pairs.get("subject").unwrap_or(&"".to_owned()));
|
||||||
body = String::from(name_value_pairs.get("body").unwrap_or(&"".to_owned()));
|
body = String::from(name_value_pairs.get("body").unwrap_or(&"".to_owned()));
|
||||||
@@ -68,34 +68,34 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drop sms, query portion
|
// Drop sms, query portion
|
||||||
let query_start = rawText[4..].find('?');
|
let query_start = raw_text[4..].find('?');
|
||||||
let sms_uriwithout_query;
|
let sms_uriwithout_query;
|
||||||
// If it's not query syntax, the question mark is part of the subject or message
|
// If it's not query syntax, the question mark is part of the subject or message
|
||||||
if query_start.is_none() || !querySyntax {
|
if query_start.is_none() || !querySyntax {
|
||||||
sms_uriwithout_query = &rawText[4..];
|
sms_uriwithout_query = &raw_text[4..];
|
||||||
} else {
|
} else {
|
||||||
sms_uriwithout_query = &rawText[4..4 + query_start.unwrap_or(0)];
|
sms_uriwithout_query = &raw_text[4..4 + query_start.unwrap_or(0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut lastComma: i32 = -1;
|
let mut last_comma: i32 = -1;
|
||||||
let mut comma: i32 = sms_uriwithout_query[(lastComma + 1) as usize..]
|
let mut comma: i32 = sms_uriwithout_query[(last_comma + 1) as usize..]
|
||||||
.find(',')
|
.find(',')
|
||||||
.unwrap_or(0) as i32;
|
.unwrap_or(0) as i32;
|
||||||
let mut numbers = Vec::with_capacity(1);
|
let mut numbers = Vec::with_capacity(1);
|
||||||
let mut vias = Vec::with_capacity(1);
|
let mut vias = Vec::with_capacity(1);
|
||||||
while comma > lastComma {
|
while comma > last_comma {
|
||||||
comma = sms_uriwithout_query[(lastComma + 1) as usize..]
|
comma = sms_uriwithout_query[(last_comma + 1) as usize..]
|
||||||
.find(',')
|
.find(',')
|
||||||
.unwrap_or(0) as i32; //sms_uriwithout_query.indexOf(',', lastComma + 1);
|
.unwrap_or(0) as i32; //sms_uriwithout_query.indexOf(',', lastComma + 1);
|
||||||
let numberPart =
|
let number_part =
|
||||||
&sms_uriwithout_query[(lastComma + 1) as usize..(lastComma + 1 + comma) as usize];
|
&sms_uriwithout_query[(last_comma + 1) as usize..(last_comma + 1 + comma) as usize];
|
||||||
addNumberVia(&mut numbers, &mut vias, numberPart);
|
add_number_via(&mut numbers, &mut vias, number_part);
|
||||||
lastComma = comma;
|
last_comma = comma;
|
||||||
}
|
}
|
||||||
addNumberVia(
|
add_number_via(
|
||||||
&mut numbers,
|
&mut numbers,
|
||||||
&mut vias,
|
&mut vias,
|
||||||
&sms_uriwithout_query[(lastComma + 1) as usize..],
|
&sms_uriwithout_query[(last_comma) as usize..],
|
||||||
);
|
);
|
||||||
|
|
||||||
Some(ParsedClientResult::SMSResult(
|
Some(ParsedClientResult::SMSResult(
|
||||||
@@ -108,20 +108,25 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
|||||||
// body);
|
// body);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addNumberVia(numbers: &mut Vec<String>, vias: &mut Vec<String>, numberPart: &str) {
|
fn add_number_via(numbers: &mut Vec<String>, vias: &mut Vec<String>, number_part: &str) {
|
||||||
if let Some(numberEnd) = numberPart.find(';') {
|
if number_part.is_empty() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if let Some(number_end) = number_part.find(';') {
|
||||||
// if numberEnd < 0 {
|
// if numberEnd < 0 {
|
||||||
numbers.push(numberPart[..numberEnd].to_string());
|
numbers.push(number_part[..number_end].to_string());
|
||||||
let maybeVia = &numberPart[numberEnd + 1..];
|
let maybe_via = &number_part[number_end + 1..];
|
||||||
let via = if maybeVia.starts_with("via=") {
|
let via = if maybe_via.starts_with("via=") {
|
||||||
&maybeVia[..4]
|
&maybe_via[4..]
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
vias.push(via.to_owned());
|
if !via.is_empty() {
|
||||||
|
vias.push(via.to_owned());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
numbers.push(numberPart.to_owned());
|
numbers.push(number_part.to_owned());
|
||||||
vias.push("".to_owned());
|
//vias.push("".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,16 +92,16 @@ impl SMSParsedRXingResult {
|
|||||||
result.push_str(&self.vias[i]);
|
result.push_str(&self.vias[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let hasBody = !self.body.is_empty();
|
let has_body = !self.body.is_empty();
|
||||||
let hasSubject = !self.subject.is_empty();
|
let has_subject = !self.subject.is_empty();
|
||||||
if hasBody || hasSubject {
|
if has_body || has_subject {
|
||||||
result.push('?');
|
result.push('?');
|
||||||
if hasBody {
|
if has_body {
|
||||||
result.push_str("body=");
|
result.push_str("body=");
|
||||||
result.push_str(&self.body);
|
result.push_str(&self.body);
|
||||||
}
|
}
|
||||||
if hasSubject {
|
if has_subject {
|
||||||
if hasBody {
|
if has_body {
|
||||||
result.push('&');
|
result.push('&');
|
||||||
}
|
}
|
||||||
result.push_str("subject=");
|
result.push_str("subject=");
|
||||||
|
|||||||
Reference in New Issue
Block a user