SMSTOMMSTO parser

This commit is contained in:
Henry Schimke
2022-09-08 14:18:18 -05:00
parent 336f7dfdea
commit fb98e6b460
4 changed files with 43 additions and 34 deletions

View File

@@ -1 +1 @@
mod result; pub mod result;

View File

@@ -34,9 +34,9 @@ use urlencoding::decode;
use crate::{exceptions::Exceptions, RXingResult}; use crate::{exceptions::Exceptions, RXingResult};
use super::{ use super::{
GeoResultParser, ISBNResultParser, ParsedClientResult, ParsedRXingResult, ProductResultParser, BookmarkDoCoMoResultParser, GeoResultParser, ISBNResultParser, ParsedClientResult,
SMSMMSResultParser, TelResultParser, TextParsedRXingResult, URIResultParser, URLTOResultParser, ParsedRXingResult, ProductResultParser, SMSMMSResultParser, TelResultParser,
WifiResultParser, BookmarkDoCoMoResultParser, TextParsedRXingResult, URIResultParser, URLTOResultParser, WifiResultParser,
}; };
/** /**
@@ -103,7 +103,7 @@ pub fn getMassagedText(result: &RXingResult) -> String {
} }
pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult { pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
let PARSERS: [&ParserFunction; 9] = [ let PARSERS: [&ParserFunction; 10] = [
&BookmarkDoCoMoResultParser::parse, &BookmarkDoCoMoResultParser::parse,
// new AddressBookDoCoMoRXingResultParser(), // new AddressBookDoCoMoRXingResultParser(),
// new EmailDoCoMoRXingResultParser(), // new EmailDoCoMoRXingResultParser(),
@@ -115,7 +115,7 @@ pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
// new SMTPRXingResultParser(), // new SMTPRXingResultParser(),
&TelResultParser::parse, &TelResultParser::parse,
&SMSMMSResultParser::parse, &SMSMMSResultParser::parse,
// new SMSTOMMSTORXingResultParser(), &SMSMMSResultParser::parse,
&GeoResultParser::parse, &GeoResultParser::parse,
&WifiResultParser::parse, &WifiResultParser::parse,
&URLTOResultParser::parse, &URLTOResultParser::parse,
@@ -222,13 +222,13 @@ pub fn isSubstringOfDigits(value: &str, offset: usize, length: usize) -> bool {
let matcher = Regex::new(DIGITS).unwrap(); let matcher = Regex::new(DIGITS).unwrap();
let sub_seq = &value[offset as usize..max]; let sub_seq = &value[offset as usize..max];
let is_a_match = if let Some(mtch) = matcher.find(sub_seq){ let is_a_match = if let Some(mtch) = matcher.find(sub_seq) {
if mtch.start() == 0 && mtch.end() == sub_seq.len() { if mtch.start() == 0 && mtch.end() == sub_seq.len() {
true true
}else { } else {
false false
} }
}else{ } else {
false false
}; };
@@ -393,10 +393,14 @@ pub fn matchSinglePrefixedField(
// return matches == null ? null : matches[0]; // return matches == null ? null : matches[0];
} }
pub fn match_do_co_mo_prefixed_field( prefix:&str, raw_text:&str) -> Option<Vec<String>> { pub fn match_do_co_mo_prefixed_field(prefix: &str, raw_text: &str) -> Option<Vec<String>> {
matchPrefixedField(prefix, raw_text, ';', true) matchPrefixedField(prefix, raw_text, ';', true)
} }
pub fn match_single_do_co_mo_prefixed_field( prefix:&str, raw_text:&str, trim:bool) -> Option<String>{ pub fn match_single_do_co_mo_prefixed_field(
prefix: &str,
raw_text: &str,
trim: bool,
) -> Option<String> {
matchSinglePrefixedField(prefix, raw_text, ';', trim) matchSinglePrefixedField(prefix, raw_text, ';', trim)
} }

View File

@@ -14,9 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.client.result; // package com.google.zxing.client.result;
import com.google.zxing.RXingResult; // import com.google.zxing.RXingResult;
use crate::RXingResult;
use super::{ParsedClientResult, ResultParser, SMSParsedRXingResult};
/** /**
* <p>Parses an "smsto:" URI result, whose format is not standardized but appears to be like: * <p>Parses an "smsto:" URI result, whose format is not standardized but appears to be like:
@@ -28,25 +32,25 @@ import com.google.zxing.RXingResult;
* *
* @author Sean Owen * @author Sean Owen
*/ */
public final class SMSTOMMSTORXingResultParser extends RXingResultParser { pub fn parse(result:&RXingResult) -> Option<ParsedClientResult> {
let rawText = ResultParser::getMassagedText(result);
@Override if !(rawText.starts_with("smsto:") || rawText.starts_with("SMSTO:") ||
public SMSParsedRXingResult parse(RXingResult result) { rawText.starts_with("mmsto:") || rawText.starts_with("MMSTO:")) {
String rawText = getMassagedText(result); return None;
if (!(rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:"))) {
return null;
} }
// Thanks to dominik.wild for suggesting this enhancement to support // Thanks to dominik.wild for suggesting this enhancement to support
// smsto:number:body URIs // smsto:number:body URIs
String number = rawText.substring(6); let mut number = &rawText[6..];
String body = null; let mut body = "";
int bodyStart = number.indexOf(':'); if let Some(body_start) = number.find(':') {
if (bodyStart >= 0) { body = &number[body_start + 1..];
body = number.substring(bodyStart + 1); number = &number[..body_start];
number = number.substring(0, bodyStart);
} }
return new SMSParsedRXingResult(number, null, null, body); // let bodyStart = number.indexOf(':');
// if (bodyStart >= 0) {
// body = number.substring(bodyStart + 1);
// number = number.substring(0, bodyStart);
// }
Some(ParsedClientResult::SMSResult(SMSParsedRXingResult::with_singles(number.to_owned(), String::from(""), String::from(""), body.to_owned())))
// return new SMSParsedRXingResult(number, null, null, body);
} }
}

View File

@@ -19,6 +19,7 @@ mod URIResultParser;
mod URLTOResultParser; mod URLTOResultParser;
mod AbstractDoCoMoResultParser; mod AbstractDoCoMoResultParser;
mod BookmarkDoCoMoResultParser; mod BookmarkDoCoMoResultParser;
mod SMSTOMMSTOResultParser;
use std::fmt; use std::fmt;