2 * Copyright 2008 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using Result = com.google.zxing.Result;
\r
18 namespace com.google.zxing.client.result
\r
21 /// <summary> <p>Parses an "sms:" URI result, which specifies a number to SMS and optional
\r
22 /// "via" number. See <a href="http://gbiv.com/protocols/uri/drafts/draft-antti-gsm-sms-url-04.txt">
\r
23 /// the IETF draft</a> on this.</p>
\r
25 /// <p>This actually also parses URIs starting with "mms:", "smsto:", "mmsto:", "SMSTO:", and
\r
26 /// "MMSTO:", and treats them all the same way, and effectively converts them to an "sms:" URI
\r
27 /// for purposes of forwarding to the platform.</p>
\r
30 /// <author> Sean Owen
\r
32 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
34 sealed class SMSMMSResultParser:ResultParser
\r
37 private SMSMMSResultParser()
\r
41 public static SMSParsedResult parse(Result result)
\r
43 System.String rawText = result.Text;
\r
44 if (rawText == null)
\r
49 if (rawText.StartsWith("sms:") || rawText.StartsWith("SMS:") || rawText.StartsWith("mms:") || rawText.StartsWith("MMS:"))
\r
53 else if (rawText.StartsWith("smsto:") || rawText.StartsWith("SMSTO:") || rawText.StartsWith("mmsto:") || rawText.StartsWith("MMSTO:"))
\r
62 // Check up front if this is a URI syntax string with query arguments
\r
63 System.Collections.Hashtable nameValuePairs = parseNameValuePairs(rawText);
\r
64 System.String subject = null;
\r
65 System.String body = null;
\r
66 bool querySyntax = false;
\r
67 if (nameValuePairs != null && !(nameValuePairs.Count == 0))
\r
69 subject = ((System.String) nameValuePairs["subject"]);
\r
70 body = ((System.String) nameValuePairs["body"]);
\r
74 // Drop sms, query portion
\r
75 //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
\r
76 int queryStart = rawText.IndexOf('?', prefixLength);
\r
77 System.String smsURIWithoutQuery;
\r
78 // If it's not query syntax, the question mark is part of the subject or message
\r
79 if (queryStart < 0 || !querySyntax)
\r
81 smsURIWithoutQuery = rawText.Substring(prefixLength);
\r
85 smsURIWithoutQuery = rawText.Substring(prefixLength, (queryStart) - (prefixLength));
\r
87 int numberEnd = smsURIWithoutQuery.IndexOf(';');
\r
88 System.String number;
\r
92 number = smsURIWithoutQuery;
\r
97 number = smsURIWithoutQuery.Substring(0, (numberEnd) - (0));
\r
98 System.String maybeVia = smsURIWithoutQuery.Substring(numberEnd + 1);
\r
99 if (maybeVia.StartsWith("via="))
\r
101 via = maybeVia.Substring(4);
\r
109 // Thanks to dominik.wild for suggesting this enhancement to support
\r
110 // smsto:number:body URIs
\r
113 int bodyStart = number.IndexOf(':');
\r
114 if (bodyStart >= 0)
\r
116 body = number.Substring(bodyStart + 1);
\r
117 number = number.Substring(0, (bodyStart) - (0));
\r
120 return new SMSParsedResult("sms:" + number, number, via, subject, body, null);
\r