Small style stuff
[zxing.git] / cpp / core / src / zxing / oned / UPCAReader.cpp
1 /*
2  *  UPCAReader.cpp
3  *  ZXing
4  *
5  *  Copyright 2010 ZXing authors All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include "UPCAReader.h"
21 #include <zxing/ReaderException.h>
22
23 namespace zxing {
24   namespace oned {
25     UPCAReader::UPCAReader() : ean13Reader() {
26     }
27
28     Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row) {
29       return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row));
30     }
31
32     Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardBegin,
33         int startGuardEnd) {
34       return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardBegin,
35           startGuardEnd));
36     }
37
38     Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
39       return maybeReturnResult(ean13Reader.decode(image, hints));
40     }
41
42     int UPCAReader::decodeMiddle(Ref<BitArray> row, int startGuardBegin, int startGuardEnd,
43         std::string& resultString) {
44       return ean13Reader.decodeMiddle(row, startGuardBegin, startGuardEnd, resultString);
45     }
46
47     Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result) {
48       if (result.empty()) {
49         return result;
50       }
51       const std::string& text = (result->getText())->getText();
52       if (text[0] == '0') {
53         Ref<String> resultString(new String(text.substr(1)));
54         Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(),
55             BarcodeFormat_UPC_A));
56         return res;
57       }
58       return Ref<Result>();
59     }
60
61     BarcodeFormat UPCAReader::getBarcodeFormat(){
62       return BarcodeFormat_UPC_A;
63     }
64   }
65 }