mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
not passing SMS
This commit is contained in:
@@ -34,8 +34,6 @@ use crate::{
|
||||
BarcodeFormat, RXingResult,
|
||||
};
|
||||
|
||||
use super::RXingResultParser;
|
||||
|
||||
const EPSILON: f64 = 1.0E-10;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// import java.util.regex.Matcher;
|
||||
// import java.util.regex.Pattern;
|
||||
|
||||
use super::{GeoParsedRXingResult, ParsedClientResult, RXingResultParser, ResultParser};
|
||||
use super::{GeoParsedRXingResult, ParsedClientResult, ResultParser};
|
||||
|
||||
const GEO_URL_PATTERN: &'static str = "geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?";
|
||||
|
||||
@@ -33,10 +33,10 @@ const GEO_URL_PATTERN: &'static str = "geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct GeoRXingResultParser {}
|
||||
// pub struct GeoRXingResultParser {}
|
||||
|
||||
impl RXingResultParser for GeoRXingResultParser {
|
||||
fn parse(&self, theRXingResult: &crate::RXingResult) -> Option<super::ParsedClientResult> {
|
||||
// impl RXingResultParser for GeoRXingResultParser {
|
||||
pub fn parse(theRXingResult: &crate::RXingResult) -> Option<super::ParsedClientResult> {
|
||||
let rawText = ResultParser::getMassagedText(theRXingResult);
|
||||
|
||||
let matcher = regex::Regex::new(GEO_URL_PATTERN).unwrap();
|
||||
@@ -123,4 +123,4 @@ impl RXingResultParser for GeoRXingResultParser {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
@@ -23,20 +23,20 @@ use std::result;
|
||||
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::{RXingResultParser, ResultParser, ISBNParsedRXingResult, ParsedClientResult};
|
||||
use super::{ ResultParser, ISBNParsedRXingResult, ParsedClientResult};
|
||||
|
||||
/**
|
||||
* Parses strings of digits that represent a ISBN.
|
||||
*
|
||||
* @author jbreiden@google.com (Jeff Breidenbach)
|
||||
*/
|
||||
pub struct ISBNRXingResultParser {}
|
||||
// pub struct ISBNRXingResultParser {}
|
||||
|
||||
impl RXingResultParser for ISBNRXingResultParser {
|
||||
// impl RXingResultParser for ISBNRXingResultParser {
|
||||
/**
|
||||
* See <a href="http://www.bisg.org/isbn-13/for.dummies.html">ISBN-13 For Dummies</a>
|
||||
*/
|
||||
fn parse(&self, theRXingResult: &crate::RXingResult) -> Option<super::ParsedClientResult> {
|
||||
pub fn parse(theRXingResult: &crate::RXingResult) -> Option<super::ParsedClientResult> {
|
||||
let format = theRXingResult.getBarcodeFormat();
|
||||
if *format != BarcodeFormat::EAN_13 {
|
||||
return None;
|
||||
@@ -52,4 +52,4 @@ impl RXingResultParser for ISBNRXingResultParser {
|
||||
|
||||
Some(ParsedClientResult::ISBNResult(ISBNParsedRXingResult::new(rawText)))
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
@@ -34,8 +34,8 @@ use urlencoding::decode;
|
||||
use crate::{exceptions::Exceptions, RXingResult};
|
||||
|
||||
use super::{
|
||||
ISBNRXingResultParser, ParsedClientResult, ParsedRXingResult, TelRXingResultParser,
|
||||
TextParsedRXingResult, WifiRXingResultParser, GeoRXingResultParser,
|
||||
ISBNResultParser, ParsedClientResult, ParsedRXingResult, TelResultParser,
|
||||
TextParsedRXingResult, WifiResultParser, GeoResultParser, SMSMMSResultParser
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -49,40 +49,42 @@ use super::{
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub trait RXingResultParser {
|
||||
// const PARSERS: [&'static str; 20] = [
|
||||
// "BookmarkDoCoMoRXingResultParser",
|
||||
// "AddressBookDoCoMoRXingResultParser",
|
||||
// "EmailDoCoMoRXingResultParser",
|
||||
// "AddressBookAURXingResultParser",
|
||||
// "VCardRXingResultParser",
|
||||
// "BizcardRXingResultParser",
|
||||
// "VEventRXingResultParser",
|
||||
// "EmailAddressRXingResultParser",
|
||||
// "SMTPRXingResultParser",
|
||||
// "TelRXingResultParser",
|
||||
// "SMSMMSRXingResultParser",
|
||||
// "SMSTOMMSTORXingResultParser",
|
||||
// "GeoRXingResultParser",
|
||||
// "WifiRXingResultParser",
|
||||
// "URLTORXingResultParser",
|
||||
// "URIRXingResultParser",
|
||||
// "ISBNRXingResultParser",
|
||||
// "ProductRXingResultParser",
|
||||
// "ExpandedProductRXingResultParser",
|
||||
// "VINRXingResultParser",
|
||||
// ];
|
||||
// pub trait RXingResultParser {
|
||||
// // const PARSERS: [&'static str; 20] = [
|
||||
// // "BookmarkDoCoMoRXingResultParser",
|
||||
// // "AddressBookDoCoMoRXingResultParser",
|
||||
// // "EmailDoCoMoRXingResultParser",
|
||||
// // "AddressBookAURXingResultParser",
|
||||
// // "VCardRXingResultParser",
|
||||
// // "BizcardRXingResultParser",
|
||||
// // "VEventRXingResultParser",
|
||||
// // "EmailAddressRXingResultParser",
|
||||
// // "SMTPRXingResultParser",
|
||||
// // "TelRXingResultParser",
|
||||
// // "SMSMMSRXingResultParser",
|
||||
// // "SMSTOMMSTORXingResultParser",
|
||||
// // "GeoRXingResultParser",
|
||||
// // "WifiRXingResultParser",
|
||||
// // "URLTORXingResultParser",
|
||||
// // "URIRXingResultParser",
|
||||
// // "ISBNRXingResultParser",
|
||||
// // "ProductRXingResultParser",
|
||||
// // "ExpandedProductRXingResultParser",
|
||||
// // "VINRXingResultParser",
|
||||
// // ];
|
||||
|
||||
/**
|
||||
* Attempts to parse the raw {@link RXingResult}'s contents as a particular type
|
||||
* of information (email, URL, etc.) and return a {@link ParsedRXingResult} encapsulating
|
||||
* the result of parsing.
|
||||
*
|
||||
* @param theRXingResult the raw {@link RXingResult} to parse
|
||||
* @return {@link ParsedRXingResult} encapsulating the parsing result
|
||||
*/
|
||||
fn parse(&self, theRXingResult: &RXingResult) -> Option<ParsedClientResult>;
|
||||
}
|
||||
// /**
|
||||
// * Attempts to parse the raw {@link RXingResult}'s contents as a particular type
|
||||
// * of information (email, URL, etc.) and return a {@link ParsedRXingResult} encapsulating
|
||||
// * the result of parsing.
|
||||
// *
|
||||
// * @param theRXingResult the raw {@link RXingResult} to parse
|
||||
// * @return {@link ParsedRXingResult} encapsulating the parsing result
|
||||
// */
|
||||
// fn parse(&self, theRXingResult: &RXingResult) -> Option<ParsedClientResult>;
|
||||
// }
|
||||
|
||||
type ParserFunction = dyn Fn(&RXingResult) -> Option<ParsedClientResult>;
|
||||
|
||||
const DIGITS: &'static str = "\\d+"; //= Pattern.compile("\\d+");
|
||||
const AMPERSAND: &'static str = "&"; // private static final Pattern AMPERSAND = Pattern.compile("&");
|
||||
@@ -100,7 +102,7 @@ pub fn getMassagedText(result: &RXingResult) -> String {
|
||||
}
|
||||
|
||||
pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
|
||||
let PARSERS: [&dyn RXingResultParser; 4] = [
|
||||
let PARSERS: [&ParserFunction; 5] = [
|
||||
// new BookmarkDoCoMoRXingResultParser(),
|
||||
// new AddressBookDoCoMoRXingResultParser(),
|
||||
// new EmailDoCoMoRXingResultParser(),
|
||||
@@ -110,21 +112,21 @@ pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
|
||||
// new VEventRXingResultParser(),
|
||||
// new EmailAddressRXingResultParser(),
|
||||
// new SMTPRXingResultParser(),
|
||||
&TelRXingResultParser {},
|
||||
// new SMSMMSRXingResultParser(),
|
||||
&TelResultParser::parse,
|
||||
&SMSMMSResultParser::parse,
|
||||
// new SMSTOMMSTORXingResultParser(),
|
||||
&GeoRXingResultParser{},
|
||||
&WifiRXingResultParser {},
|
||||
&GeoResultParser::parse,
|
||||
&WifiResultParser::parse,
|
||||
// new URLTORXingResultParser(),
|
||||
// new URIRXingResultParser(),
|
||||
&ISBNRXingResultParser {},
|
||||
&ISBNResultParser::parse,
|
||||
// new ProductRXingResultParser(),
|
||||
// new ExpandedProductRXingResultParser(),
|
||||
// new VINRXingResultParser(),
|
||||
];
|
||||
|
||||
for parser in PARSERS {
|
||||
let result = parser.parse(theRXingResult);
|
||||
let result = parser(theRXingResult);
|
||||
if result.is_some() {
|
||||
return result.unwrap();
|
||||
}
|
||||
@@ -148,7 +150,7 @@ pub fn maybe_append_string(value: &str, result: &mut String) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_append_multiple(value: &[&str], result: &mut String) {
|
||||
pub fn maybe_append_multiple(value: &[String], result: &mut String) {
|
||||
if !value.is_empty() {
|
||||
for s in value {
|
||||
// for (String s : value) {
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link SMSParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSMMSParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
doTest("sms:+15551212", "+15551212", null, null, null, "sms:+15551212");
|
||||
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
|
||||
"sms:+15551212?body=bar&subject=foo");
|
||||
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333",
|
||||
"sms:+15551212;via=999333");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMS() {
|
||||
doTest("mms:+15551212", "+15551212", null, null, null, "sms:+15551212");
|
||||
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
|
||||
"sms:+15551212?body=bar&subject=foo");
|
||||
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333",
|
||||
"sms:+15551212;via=999333");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String number,
|
||||
String subject,
|
||||
String body,
|
||||
String via,
|
||||
String parsedURI) {
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.SMS, result.getType());
|
||||
SMSParsedRXingResult smsRXingResult = (SMSParsedRXingResult) result;
|
||||
assertArrayEquals(new String[] { number }, smsRXingResult.getNumbers());
|
||||
assertEquals(subject, smsRXingResult.getSubject());
|
||||
assertEquals(body, smsRXingResult.getBody());
|
||||
assertArrayEquals(new String[] { via }, smsRXingResult.getVias());
|
||||
assertEquals(parsedURI, smsRXingResult.getSMSURI());
|
||||
}
|
||||
|
||||
}
|
||||
94
src/client/result/SMSMMSParsedResultTestCase.rs
Normal file
94
src/client/result/SMSMMSParsedResultTestCase.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2007 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// package com.google.zxing.client.result;
|
||||
|
||||
// import com.google.zxing.BarcodeFormat;
|
||||
// import com.google.zxing.RXingResult;
|
||||
// import org.junit.Assert;
|
||||
// import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link SMSParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
// public final class SMSMMSParsedRXingResultTestCase extends Assert {
|
||||
use crate::{
|
||||
client::result::{ParsedClientResult, ParsedRXingResult, ParsedRXingResultType, ResultParser},
|
||||
BarcodeFormat, RXingResult,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_sms() {
|
||||
do_test("sms:+15551212", "+15551212", "", "", "", "sms:+15551212");
|
||||
do_test(
|
||||
"sms:+15551212?subject=foo&body=bar",
|
||||
"+15551212",
|
||||
"foo",
|
||||
"bar",
|
||||
"",
|
||||
"sms:+15551212?body=bar&subject=foo",
|
||||
);
|
||||
do_test(
|
||||
"sms:+15551212;via=999333",
|
||||
"+15551212",
|
||||
"",
|
||||
"",
|
||||
"999333",
|
||||
"sms:+15551212;via=999333",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mms() {
|
||||
do_test("mms:+15551212", "+15551212", "", "", "", "sms:+15551212");
|
||||
do_test(
|
||||
"mms:+15551212?subject=foo&body=bar",
|
||||
"+15551212",
|
||||
"foo",
|
||||
"bar",
|
||||
"",
|
||||
"sms:+15551212?body=bar&subject=foo",
|
||||
);
|
||||
do_test(
|
||||
"mms:+15551212;via=999333",
|
||||
"+15551212",
|
||||
"",
|
||||
"",
|
||||
"999333",
|
||||
"sms:+15551212;via=999333",
|
||||
);
|
||||
}
|
||||
|
||||
fn do_test(contents: &str, number: &str, subject: &str, body: &str, via: &str, parsedURI: &str) {
|
||||
let fake_rxing_result =
|
||||
RXingResult::new(contents, Vec::new(), Vec::new(), BarcodeFormat::QR_CODE);
|
||||
let result = ResultParser::parseRXingResult(&fake_rxing_result);
|
||||
assert_eq!(ParsedRXingResultType::SMS, result.getType());
|
||||
|
||||
if let ParsedClientResult::SMSResult(smsRXingResult) = result {
|
||||
assert_eq!(&vec![number], smsRXingResult.getNumbers());
|
||||
assert_eq!(subject, smsRXingResult.getSubject());
|
||||
assert_eq!(body, smsRXingResult.getBody());
|
||||
assert_eq!(&vec![via], smsRXingResult.getVias());
|
||||
assert_eq!(parsedURI, smsRXingResult.getSMSURI());
|
||||
} else {
|
||||
panic!("Expected ParsedClientResult::SMSResult");
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>Parses an "sms:" URI result, which specifies a number to SMS.
|
||||
* See <a href="http://tools.ietf.org/html/rfc5724"> RFC 5724</a> on this.</p>
|
||||
*
|
||||
* <p>This class supports "via" syntax for numbers, which is not part of the spec.
|
||||
* For example "+12125551212;via=+12124440101" may appear as a number.
|
||||
* It also supports a "subject" query parameter, which is not mentioned in the spec.
|
||||
* These are included since they were mentioned in earlier IETF drafts and might be
|
||||
* used.</p>
|
||||
*
|
||||
* <p>This actually also parses URIs starting with "mms:" and treats them all the same way,
|
||||
* and effectively converts them to an "sms:" URI for purposes of forwarding to the platform.</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSMMSRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public SMSParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("sms:") || rawText.startsWith("SMS:") ||
|
||||
rawText.startsWith("mms:") || rawText.startsWith("MMS:"))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check up front if this is a URI syntax string with query arguments
|
||||
Map<String,String> nameValuePairs = parseNameValuePairs(rawText);
|
||||
String subject = null;
|
||||
String body = null;
|
||||
boolean querySyntax = false;
|
||||
if (nameValuePairs != null && !nameValuePairs.isEmpty()) {
|
||||
subject = nameValuePairs.get("subject");
|
||||
body = nameValuePairs.get("body");
|
||||
querySyntax = true;
|
||||
}
|
||||
|
||||
// Drop sms, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String smsURIWithoutQuery;
|
||||
// If it's not query syntax, the question mark is part of the subject or message
|
||||
if (queryStart < 0 || !querySyntax) {
|
||||
smsURIWithoutQuery = rawText.substring(4);
|
||||
} else {
|
||||
smsURIWithoutQuery = rawText.substring(4, queryStart);
|
||||
}
|
||||
|
||||
int lastComma = -1;
|
||||
int comma;
|
||||
List<String> numbers = new ArrayList<>(1);
|
||||
List<String> vias = new ArrayList<>(1);
|
||||
while ((comma = smsURIWithoutQuery.indexOf(',', lastComma + 1)) > lastComma) {
|
||||
String numberPart = smsURIWithoutQuery.substring(lastComma + 1, comma);
|
||||
addNumberVia(numbers, vias, numberPart);
|
||||
lastComma = comma;
|
||||
}
|
||||
addNumberVia(numbers, vias, smsURIWithoutQuery.substring(lastComma + 1));
|
||||
|
||||
return new SMSParsedRXingResult(numbers.toArray(EMPTY_STR_ARRAY),
|
||||
vias.toArray(EMPTY_STR_ARRAY),
|
||||
subject,
|
||||
body);
|
||||
}
|
||||
|
||||
private static void addNumberVia(Collection<String> numbers,
|
||||
Collection<String> vias,
|
||||
String numberPart) {
|
||||
int numberEnd = numberPart.indexOf(';');
|
||||
if (numberEnd < 0) {
|
||||
numbers.add(numberPart);
|
||||
vias.add(null);
|
||||
} else {
|
||||
numbers.add(numberPart.substring(0, numberEnd));
|
||||
String maybeVia = numberPart.substring(numberEnd + 1);
|
||||
String via;
|
||||
if (maybeVia.startsWith("via=")) {
|
||||
via = maybeVia.substring(4);
|
||||
} else {
|
||||
via = null;
|
||||
}
|
||||
vias.add(via);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
128
src/client/result/SMSMMSResultParser.rs
Normal file
128
src/client/result/SMSMMSResultParser.rs
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// package com.google.zxing.client.result;
|
||||
|
||||
// import com.google.zxing.RXingResult;
|
||||
|
||||
// import java.util.ArrayList;
|
||||
// import java.util.Collection;
|
||||
// import java.util.List;
|
||||
// import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>Parses an "sms:" URI result, which specifies a number to SMS.
|
||||
* See <a href="http://tools.ietf.org/html/rfc5724"> RFC 5724</a> on this.</p>
|
||||
*
|
||||
* <p>This class supports "via" syntax for numbers, which is not part of the spec.
|
||||
* For example "+12125551212;via=+12124440101" may appear as a number.
|
||||
* It also supports a "subject" query parameter, which is not mentioned in the spec.
|
||||
* These are included since they were mentioned in earlier IETF drafts and might be
|
||||
* used.</p>
|
||||
*
|
||||
* <p>This actually also parses URIs starting with "mms:" and treats them all the same way,
|
||||
* and effectively converts them to an "sms:" URI for purposes of forwarding to the platform.</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
// public final class SMSMMSRXingResultParser extends RXingResultParser {
|
||||
use crate::RXingResult;
|
||||
|
||||
use super::{ParsedClientResult, ResultParser, SMSParsedRXingResult};
|
||||
|
||||
// @Override
|
||||
pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
let rawText = ResultParser::getMassagedText(result);
|
||||
if !(rawText.starts_with("sms:")
|
||||
|| rawText.starts_with("SMS:")
|
||||
|| rawText.starts_with("mms:")
|
||||
|| rawText.starts_with("MMS:"))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut subject = "".to_owned();
|
||||
let mut body = "".to_owned();
|
||||
let mut querySyntax = false;
|
||||
|
||||
// Check up front if this is a URI syntax string with query arguments
|
||||
if let Some(nameValuePairs) = ResultParser::parseNameValuePairs(&rawText) {
|
||||
if !nameValuePairs.is_empty() {
|
||||
subject = String::from(nameValuePairs.get("subject").unwrap_or(&"".to_owned()));
|
||||
body = String::from(nameValuePairs.get("body").unwrap_or(&"".to_owned()));
|
||||
querySyntax = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Drop sms, query portion
|
||||
let queryStart = rawText[4..].find('?');
|
||||
let sms_uriwithout_query;
|
||||
// If it's not query syntax, the question mark is part of the subject or message
|
||||
if queryStart.is_none() || !querySyntax {
|
||||
sms_uriwithout_query = &rawText[4..];
|
||||
} else {
|
||||
sms_uriwithout_query = &rawText[4..4 + queryStart.unwrap_or(0)];
|
||||
}
|
||||
|
||||
let mut lastComma: i32 = -1;
|
||||
let mut comma: i32 = sms_uriwithout_query[(lastComma + 1) as usize..]
|
||||
.find(',')
|
||||
.unwrap_or(0) as i32;
|
||||
let mut numbers = Vec::with_capacity(1);
|
||||
let mut vias = Vec::with_capacity(1);
|
||||
while comma > lastComma {
|
||||
comma = sms_uriwithout_query[(lastComma + 1) as usize..]
|
||||
.find(',')
|
||||
.unwrap_or(0) as i32; //sms_uriwithout_query.indexOf(',', lastComma + 1);
|
||||
let numberPart =
|
||||
&sms_uriwithout_query[(lastComma + 1) as usize..(lastComma + 1 + comma) as usize];
|
||||
addNumberVia(&mut numbers, &mut vias, numberPart);
|
||||
lastComma = comma;
|
||||
}
|
||||
addNumberVia(
|
||||
&mut numbers,
|
||||
&mut vias,
|
||||
&sms_uriwithout_query[(lastComma + 1) as usize..],
|
||||
);
|
||||
|
||||
Some(ParsedClientResult::SMSResult(
|
||||
SMSParsedRXingResult::with_arrays(numbers, vias, subject.to_owned(), body.to_owned()),
|
||||
))
|
||||
|
||||
// return new SMSParsedRXingResult(numbers.toArray(EMPTY_STR_ARRAY),
|
||||
// vias.toArray(EMPTY_STR_ARRAY),
|
||||
// subject,
|
||||
// body);
|
||||
}
|
||||
|
||||
fn addNumberVia(numbers: &mut Vec<String>, vias: &mut Vec<String>, numberPart: &str) {
|
||||
if let Some(numberEnd) = numberPart.find(';') {
|
||||
// if numberEnd < 0 {
|
||||
numbers.push(numberPart[..numberEnd].to_string());
|
||||
let maybeVia = &numberPart[numberEnd + 1..];
|
||||
let via = if maybeVia.starts_with("via=") {
|
||||
&maybeVia[..4]
|
||||
} else {
|
||||
""
|
||||
};
|
||||
vias.push(via.to_owned());
|
||||
} else {
|
||||
numbers.push(numberPart.to_owned());
|
||||
vias.push("".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
/**
|
||||
* Represents a parsed result that encodes an SMS message, including recipients, subject
|
||||
* and body text.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String[] numbers;
|
||||
private final String[] vias;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
|
||||
public SMSParsedRXingResult(String number,
|
||||
String via,
|
||||
String subject,
|
||||
String body) {
|
||||
super(ParsedRXingResultType.SMS);
|
||||
this.numbers = new String[] {number};
|
||||
this.vias = new String[] {via};
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public SMSParsedRXingResult(String[] numbers,
|
||||
String[] vias,
|
||||
String subject,
|
||||
String body) {
|
||||
super(ParsedRXingResultType.SMS);
|
||||
this.numbers = numbers;
|
||||
this.vias = vias;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getSMSURI() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("sms:");
|
||||
boolean first = true;
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(',');
|
||||
}
|
||||
result.append(numbers[i]);
|
||||
if (vias != null && vias[i] != null) {
|
||||
result.append(";via=");
|
||||
result.append(vias[i]);
|
||||
}
|
||||
}
|
||||
boolean hasBody = body != null;
|
||||
boolean hasSubject = subject != null;
|
||||
if (hasBody || hasSubject) {
|
||||
result.append('?');
|
||||
if (hasBody) {
|
||||
result.append("body=");
|
||||
result.append(body);
|
||||
}
|
||||
if (hasSubject) {
|
||||
if (hasBody) {
|
||||
result.append('&');
|
||||
}
|
||||
result.append("subject=");
|
||||
result.append(subject);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String[] getNumbers() {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
public String[] getVias() {
|
||||
return vias;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(100);
|
||||
maybeAppend(numbers, result);
|
||||
maybeAppend(subject, result);
|
||||
maybeAppend(body, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
129
src/client/result/SMSParsedResult.rs
Normal file
129
src/client/result/SMSParsedResult.rs
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// package com.google.zxing.client.result;
|
||||
|
||||
use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser};
|
||||
|
||||
/**
|
||||
* Represents a parsed result that encodes an SMS message, including recipients, subject
|
||||
* and body text.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct SMSParsedRXingResult {
|
||||
|
||||
numbers: Vec<String>,
|
||||
vias: Vec<String>,
|
||||
subject:String,
|
||||
body:String,
|
||||
}
|
||||
|
||||
impl ParsedRXingResult for SMSParsedRXingResult {
|
||||
fn getType(&self) -> super::ParsedRXingResultType {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 hasBody = !self.body.is_empty();
|
||||
let hasSubject = !self.subject.is_empty();
|
||||
if hasBody || hasSubject {
|
||||
result.push('?');
|
||||
if hasBody {
|
||||
result.push_str("body=");
|
||||
result.push_str(&self.body);
|
||||
}
|
||||
if hasSubject {
|
||||
if hasBody {
|
||||
result.push('&');
|
||||
}
|
||||
result.push_str("subject=");
|
||||
result.push_str(&self.subject);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn getNumbers(&self) -> &Vec<String> {
|
||||
&self.numbers
|
||||
}
|
||||
|
||||
pub fn getVias(&self) -> &Vec<String> {
|
||||
&self. vias
|
||||
}
|
||||
|
||||
pub fn getSubject(&self) -> &str {
|
||||
&self. subject
|
||||
}
|
||||
|
||||
pub fn getBody(&self) -> &str {
|
||||
&self. body
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ use std::any::Any;
|
||||
|
||||
use crate::{
|
||||
client::result::{
|
||||
ParsedClientResult, ParsedRXingResult, ParsedRXingResultType, RXingResultParser,
|
||||
ParsedClientResult, ParsedRXingResult, ParsedRXingResultType,
|
||||
TelParsedRXingResult,
|
||||
},
|
||||
BarcodeFormat, RXingResult,
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
|
||||
// import com.google.zxing.RXingResult;
|
||||
|
||||
use super::{RXingResultParser, TelParsedRXingResult, ParsedRXingResult, ParsedClientResult, ResultParser};
|
||||
use super::{TelParsedRXingResult, ParsedRXingResult, ParsedClientResult, ResultParser};
|
||||
|
||||
/**
|
||||
* Parses a "tel:" URI result, which specifies a phone number.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
pub struct TelRXingResultParser {}
|
||||
// pub struct TelRXingResultParser {}
|
||||
|
||||
impl RXingResultParser for TelRXingResultParser {
|
||||
// impl RXingResultParser for TelRXingResultParser {
|
||||
|
||||
fn parse(&self, theRXingResult: &crate::RXingResult) -> Option<ParsedClientResult> {
|
||||
pub fn parse(theRXingResult: &crate::RXingResult) -> Option<ParsedClientResult> {
|
||||
let rawText = ResultParser::getMassagedText(theRXingResult);
|
||||
if !rawText.starts_with("tel:") && !rawText.starts_with("TEL:") {
|
||||
return None;
|
||||
@@ -46,4 +46,4 @@ impl RXingResultParser for TelRXingResultParser {
|
||||
// let number = queryStart < 0 ? : ;
|
||||
Some(ParsedClientResult::TelResult(TelParsedRXingResult::new(number.to_owned(), telURI.to_owned(), "".to_owned())))
|
||||
}
|
||||
}
|
||||
// }
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use crate::client::result::{WifiParsedRXingResult, ParsedClientResult};
|
||||
|
||||
use super::{RXingResultParser, ResultParser};
|
||||
use super::{ResultParser};
|
||||
|
||||
// @SuppressWarnings("checkstyle:lineLength")
|
||||
/**
|
||||
@@ -40,10 +40,10 @@ use super::{RXingResultParser, ResultParser};
|
||||
* @author Sean Owen
|
||||
* @author Steffen Kieß
|
||||
*/
|
||||
pub struct WifiRXingResultParser {}
|
||||
// pub struct WifiRXingResultParser {}
|
||||
|
||||
impl RXingResultParser for WifiRXingResultParser {
|
||||
fn parse(&self, theRXingResult: &crate::RXingResult) -> Option<super::ParsedClientResult> {
|
||||
// impl RXingResultParser for WifiRXingResultParser {
|
||||
pub fn parse(theRXingResult: &crate::RXingResult) -> Option<super::ParsedClientResult> {
|
||||
const WIFI_TEST : &'static str = "WIFI:";
|
||||
|
||||
let rawText_unstripped = ResultParser::getMassagedText(theRXingResult);
|
||||
@@ -85,4 +85,4 @@ impl RXingResultParser for WifiRXingResultParser {
|
||||
|
||||
Some(ParsedClientResult::WiFiResult(WifiParsedRXingResult::with_details(n_type, ssid, pass, hidden, identity, anonymousIdentity, eapMethod, phase2Method.unwrap_or(String::from("")))))
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
@@ -10,6 +10,8 @@ mod WifiParsedResult;
|
||||
mod WifiResultParser;
|
||||
mod GeoResultParser;
|
||||
mod GeoParsedResult;
|
||||
mod SMSParsedResult;
|
||||
mod SMSMMSResultParser;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@@ -18,13 +20,14 @@ pub use ResultParser::*;
|
||||
pub use TelParsedResult::*;
|
||||
pub use TextParsedResult::*;
|
||||
pub use ParsedResult::*;
|
||||
pub use TelResultParser::*;
|
||||
// pub use TelResultParser::*;
|
||||
pub use ISBNParsedResult::*;
|
||||
pub use ISBNResultParser::*;
|
||||
// pub use ISBNResultParser::*;
|
||||
pub use WifiParsedResult::*;
|
||||
pub use WifiResultParser::*;
|
||||
// pub use WifiResultParser::*;
|
||||
pub use GeoParsedResult::*;
|
||||
pub use GeoResultParser::*;
|
||||
// pub use GeoResultParser::*;
|
||||
pub use SMSParsedResult::*;
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -35,6 +38,8 @@ mod ISBNParsedResultTestCase;
|
||||
mod WifiParsedResultTestCase;
|
||||
#[cfg(test)]
|
||||
mod GeoParsedResultTestCase;
|
||||
#[cfg(test)]
|
||||
mod SMSMMSParsedResultTestCase;
|
||||
|
||||
pub enum ParsedClientResult {
|
||||
TextResult(TextParsedRXingResult),
|
||||
@@ -42,6 +47,7 @@ pub enum ParsedClientResult {
|
||||
ISBNResult(ISBNParsedRXingResult),
|
||||
WiFiResult(WifiParsedRXingResult),
|
||||
GeoResult(GeoParsedRXingResult),
|
||||
SMSResult(SMSParsedRXingResult),
|
||||
}
|
||||
|
||||
impl ParsedRXingResult for ParsedClientResult {
|
||||
@@ -52,6 +58,7 @@ impl ParsedRXingResult for ParsedClientResult {
|
||||
ParsedClientResult::ISBNResult(a) => a.getType(),
|
||||
ParsedClientResult::WiFiResult(a) => a.getType(),
|
||||
ParsedClientResult::GeoResult(a) => a.getType(),
|
||||
ParsedClientResult::SMSResult(a) => a.getType(),
|
||||
|
||||
|
||||
}
|
||||
@@ -64,6 +71,7 @@ impl ParsedRXingResult for ParsedClientResult {
|
||||
ParsedClientResult::ISBNResult(a) => a.getDisplayRXingResult(),
|
||||
ParsedClientResult::WiFiResult(a) => a.getDisplayRXingResult(),
|
||||
ParsedClientResult::GeoResult(a) => a.getDisplayRXingResult(),
|
||||
ParsedClientResult::SMSResult(a) => a.getDisplayRXingResult(),
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user