rxing/client/result/BookmarkDoCoMoResultParser.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, URIResultParser};
24
25/**
26 * @author Sean Owen
27 */
28pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
29 let rawText = result.getText();
30 if !rawText.starts_with("MEBKM:") {
31 return None;
32 }
33 let title = ResultParser::match_single_docomo_prefixed_field("TITLE:", rawText, true);
34 let rawUri = ResultParser::match_docomo_prefixed_field("URL:", rawText)?;
35
36 let uri = &rawUri[0];
37 if URIResultParser::is_basically_valid_uri(uri) {
38 Some(ParsedClientResult::URIResult(URIParsedRXingResult::new(
39 uri.to_string(),
40 title.unwrap_or_default(),
41 )))
42 } else {
43 None
44 }
45}