Add ENCODING=QUOTED-PRINTABLE support
[zxing.git] / core / src / com / google / zxing / client / result / ParsedResult.java
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.Result;
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 ResultParser#parseResult(Result)} 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  */
32 public abstract class ParsedResult {
33
34   private final ParsedResultType type;
35
36   protected ParsedResult(ParsedResultType type) {
37     this.type = type;
38   }
39
40   public ParsedResultType getType() {
41     return type;
42   }
43
44   public abstract String getDisplayResult();
45
46   public String toString() {
47     return getDisplayResult();
48   }
49
50   public static void maybeAppend(String value, StringBuffer result) {
51     if (value != null && value.length() > 0) {
52       // Don't add a newline before the first value
53       if (result.length() > 0) {
54         result.append('\n');
55       }
56       result.append(value);
57     }
58   }
59
60   public static void maybeAppend(String[] value, StringBuffer result) {
61     if (value != null) {
62       for (int i = 0; i < value.length; i++) {
63         if (value[i] != null && value[i].length() > 0) {
64           if (result.length() > 0) {
65             result.append('\n');
66           }
67           result.append(value[i]);
68         }
69       }
70     }
71   }
72
73 }