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

@@ -34,9 +34,9 @@ use urlencoding::decode;
use crate::{exceptions::Exceptions, RXingResult};
use super::{
GeoResultParser, ISBNResultParser, ParsedClientResult, ParsedRXingResult, ProductResultParser,
SMSMMSResultParser, TelResultParser, TextParsedRXingResult, URIResultParser, URLTOResultParser,
WifiResultParser, BookmarkDoCoMoResultParser,
BookmarkDoCoMoResultParser, GeoResultParser, ISBNResultParser, ParsedClientResult,
ParsedRXingResult, ProductResultParser, SMSMMSResultParser, TelResultParser,
TextParsedRXingResult, URIResultParser, URLTOResultParser, WifiResultParser,
};
/**
@@ -103,7 +103,7 @@ pub fn getMassagedText(result: &RXingResult) -> String {
}
pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
let PARSERS: [&ParserFunction; 9] = [
let PARSERS: [&ParserFunction; 10] = [
&BookmarkDoCoMoResultParser::parse,
// new AddressBookDoCoMoRXingResultParser(),
// new EmailDoCoMoRXingResultParser(),
@@ -115,7 +115,7 @@ pub fn parseRXingResult(theRXingResult: &RXingResult) -> ParsedClientResult {
// new SMTPRXingResultParser(),
&TelResultParser::parse,
&SMSMMSResultParser::parse,
// new SMSTOMMSTORXingResultParser(),
&SMSMMSResultParser::parse,
&GeoResultParser::parse,
&WifiResultParser::parse,
&URLTOResultParser::parse,
@@ -222,13 +222,13 @@ pub fn isSubstringOfDigits(value: &str, offset: usize, length: usize) -> bool {
let matcher = Regex::new(DIGITS).unwrap();
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() {
true
}else {
} else {
false
}
}else{
} else {
false
};
@@ -393,10 +393,14 @@ pub fn matchSinglePrefixedField(
// 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)
}
}
pub fn match_single_do_co_mo_prefixed_field( prefix:&str, raw_text:&str, trim:bool) -> Option<String>{
matchSinglePrefixedField(prefix, raw_text, ';', trim)
}
pub fn match_single_do_co_mo_prefixed_field(
prefix: &str,
raw_text: &str,
trim: bool,
) -> Option<String> {
matchSinglePrefixedField(prefix, raw_text, ';', trim)
}

View File

@@ -14,9 +14,13 @@
* 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:
@@ -28,25 +32,25 @@ import com.google.zxing.RXingResult;
*
* @author Sean Owen
*/
public final class SMSTOMMSTORXingResultParser extends RXingResultParser {
@Override
public SMSParsedRXingResult parse(RXingResult result) {
String rawText = getMassagedText(result);
if (!(rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:"))) {
return null;
pub fn parse(result:&RXingResult) -> Option<ParsedClientResult> {
let rawText = ResultParser::getMassagedText(result);
if !(rawText.starts_with("smsto:") || rawText.starts_with("SMSTO:") ||
rawText.starts_with("mmsto:") || rawText.starts_with("MMSTO:")) {
return None;
}
// Thanks to dominik.wild for suggesting this enhancement to support
// smsto:number:body URIs
String number = rawText.substring(6);
String body = null;
int bodyStart = number.indexOf(':');
if (bodyStart >= 0) {
body = number.substring(bodyStart + 1);
number = number.substring(0, bodyStart);
let mut number = &rawText[6..];
let mut body = "";
if let Some(body_start) = number.find(':') {
body = &number[body_start + 1..];
number = &number[..body_start];
}
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 AbstractDoCoMoResultParser;
mod BookmarkDoCoMoResultParser;
mod SMSTOMMSTOResultParser;
use std::fmt;