rxing/client/result/
URLTOResultParser.rs

1/*
2 * Copyright 2007 ZXing authors
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17// package com.google.zxing.client.result;
18
19// import com.google.zxing.RXingResult;
20
21use crate::RXingResult;
22
23use super::{ParsedClientResult, ResultParser, URIParsedRXingResult};
24
25/**
26 * Parses the "URLTO" result format, which is of the form "URLTO:[title]:[url]".
27 * This seems to be used sometimes, but I am not able to find documentation
28 * on its origin or official format?
29 *
30 * @author Sean Owen
31 */
32pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
33    let rawText = ResultParser::getMassagedText(result);
34    if !rawText.starts_with("urlto:") && !rawText.starts_with("URLTO:") {
35        return None;
36    }
37    let titleEnd = if let Some(pos) = rawText[6..].find(':') {
38        pos + 6
39    } else {
40        return None;
41    };
42    let title = if titleEnd <= 6 {
43        ""
44    } else {
45        &rawText[6..titleEnd]
46    };
47    let uri = &rawText[titleEnd + 1..];
48
49    Some(ParsedClientResult::URIResult(URIParsedRXingResult::new(
50        uri.to_owned(),
51        title.to_owned(),
52    )))
53}
54
55// }