2 * Copyright 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
19 import com.google.zxing.Result;
22 * <p>Parses an "smsto:" URI result, whose format is not standardized but appears to be like:
23 * <code>smsto:number(:body)</code>.</p>
25 * <p>This actually also parses URIs starting with "smsto:", "mmsto:", "SMSTO:", and
26 * "MMSTO:", and treats them all the same way, and effectively converts them to an "sms:" URI
27 * for purposes of forwarding to the platform.</p>
31 final class SMSTOMMSTOResultParser extends ResultParser {
33 private SMSTOMMSTOResultParser() {
36 public static SMSParsedResult parse(Result result) {
37 String rawText = result.getText();
38 if (rawText == null) {
41 if (!(rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
42 rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:"))) {
45 // Thanks to dominik.wild for suggesting this enhancement to support
46 // smsto:number:body URIs
47 String number = rawText.substring(6);
49 int bodyStart = number.indexOf(':');
51 body = number.substring(bodyStart + 1);
52 number = number.substring(0, bodyStart);
54 return new SMSParsedResult(number, null, null, body);