rxing/client/result/ParsedResult.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
19use super::ParsedRXingResultType;
20
21/**
22 * <p>Abstract class representing the result of decoding a barcode, as more than
23 * a String -- as some type of structured data. This might be a subclass which represents
24 * a URL, or an e-mail address. {@link RXingResultParser#parseRXingResult(com.google.zxing.RXingResult)} will turn a raw
25 * decoded string into the most appropriate type of structured representation.</p>
26 *
27 * <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
28 * on exception-based mechanisms during parsing.</p>
29 *
30 * @author Sean Owen
31 */
32pub trait ParsedRXingResult {
33 // private final ParsedRXingResultType type;
34
35 // protected ParsedRXingResult(ParsedRXingResultType type) {
36 // this.type = type;
37 // }
38
39 fn getType(&self) -> ParsedRXingResultType;
40 // fn as_any(&self) -> &dyn Any;
41
42 fn getDisplayRXingResult(&self) -> String;
43
44 fn maybe_append(&self, value: &str, result: &mut String) {
45 if !value.is_empty() {
46 // Don't add a newline before the first value
47 if !result.is_empty() {
48 result.push('\n');
49 }
50 result.push_str(value);
51 }
52 }
53
54 fn maybe_append_multiple(&self, values: &[&str], result: &mut String) {
55 if !values.is_empty() {
56 for value in values {
57 // for (String value : values) {
58 self.maybe_append(value, result);
59 }
60 }
61 }
62}