mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
formatting cleanup before trying to make the last failing C++ qr blackbox test pass
git-svn-id: https://zxing.googlecode.com/svn/trunk@1964 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
9558d83d71
commit
beeef242b2
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* BitMatrix.cpp
|
||||
* zxing
|
||||
|
@ -24,10 +25,16 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace zxing {
|
||||
using namespace std;
|
||||
using std::numeric_limits;
|
||||
using std::ostream;
|
||||
using std::ostringstream;
|
||||
|
||||
unsigned int logDigits(unsigned digits) {
|
||||
using zxing::BitMatrix;
|
||||
using zxing::BitArray;
|
||||
using zxing::Ref;
|
||||
|
||||
namespace {
|
||||
unsigned int logDigits(unsigned digits) {
|
||||
unsigned log = 0;
|
||||
unsigned val = 1;
|
||||
while (val < digits) {
|
||||
|
@ -35,19 +42,20 @@ unsigned int logDigits(unsigned digits) {
|
|||
val <<= 1;
|
||||
}
|
||||
return log;
|
||||
}
|
||||
}
|
||||
|
||||
const unsigned int bitsPerWord = numeric_limits<unsigned int>::digits;
|
||||
const unsigned int logBits = logDigits(bitsPerWord);
|
||||
const unsigned int bitsMask = (1 << logBits) - 1;
|
||||
const unsigned int bitsPerWord = numeric_limits<unsigned int>::digits;
|
||||
const unsigned int logBits = logDigits(bitsPerWord);
|
||||
const unsigned int bitsMask = (1 << logBits) - 1;
|
||||
|
||||
static size_t wordsForSize(size_t width, size_t height) {
|
||||
size_t wordsForSize(size_t width, size_t height) {
|
||||
size_t bits = width * height;
|
||||
int arraySize = bits >> logBits;
|
||||
if (bits - (arraySize << logBits) != 0) {
|
||||
arraySize++;
|
||||
}
|
||||
return arraySize;
|
||||
}
|
||||
}
|
||||
|
||||
BitMatrix::BitMatrix(size_t dimension) :
|
||||
|
@ -160,7 +168,8 @@ unsigned int* BitMatrix::getBits() const {
|
|||
return bits_;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &out, const BitMatrix &bm) {
|
||||
namespace zxing {
|
||||
ostream& operator<<(ostream &out, const BitMatrix &bm) {
|
||||
for (size_t y = 0; y < bm.height_; y++) {
|
||||
for (size_t x = 0; x < bm.width_; x++) {
|
||||
out << (bm.get(x, y) ? "X " : " ");
|
||||
|
@ -168,11 +177,11 @@ ostream& operator<<(ostream &out, const BitMatrix &bm) {
|
|||
out << "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
const char *BitMatrix::description() {
|
||||
|
||||
const char* BitMatrix::description() {
|
||||
ostringstream out;
|
||||
out << *this;
|
||||
return out.str().c_str();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
#ifndef __BIT_MATRIX_H__
|
||||
#define __BIT_MATRIX_H__
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* QRCodeReader.cpp
|
||||
* zxing
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
#ifndef __QR_CODE_READER_H__
|
||||
#define __QR_CODE_READER_H__
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* DecodedBitStreamParser.cpp
|
||||
* zxing
|
||||
*
|
||||
|
@ -35,25 +35,24 @@
|
|||
#define ICONV_CONST /**/
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace zxing;
|
||||
using namespace zxing::qrcode;
|
||||
|
||||
namespace zxing {
|
||||
namespace qrcode {
|
||||
|
||||
using namespace std;
|
||||
|
||||
const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] =
|
||||
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'
|
||||
};
|
||||
};
|
||||
|
||||
const char *DecodedBitStreamParser::ASCII = "ASCII";
|
||||
const char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1";
|
||||
const char *DecodedBitStreamParser::UTF8 = "UTF-8";
|
||||
const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
|
||||
const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
|
||||
const char *DecodedBitStreamParser::ASCII = "ASCII";
|
||||
const char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1";
|
||||
const char *DecodedBitStreamParser::UTF8 = "UTF-8";
|
||||
const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
|
||||
const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
|
||||
|
||||
void DecodedBitStreamParser::append(std::string &result, const unsigned char *bufIn, size_t nIn, const char *src) {
|
||||
void DecodedBitStreamParser::append(std::string &result, const unsigned char *bufIn, size_t nIn, const char *src) {
|
||||
#ifndef NO_ICONV
|
||||
if (nIn == 0) {
|
||||
return;
|
||||
|
@ -85,9 +84,9 @@ namespace zxing {
|
|||
#else
|
||||
result.append((const char *)bufIn, nIn);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
||||
// and decode as Shift_JIS afterwards
|
||||
size_t nBytes = 2 * count;
|
||||
|
@ -113,9 +112,9 @@ namespace zxing {
|
|||
|
||||
append(result, buffer, nBytes, SHIFT_JIS);
|
||||
delete[] buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
int nBytes = count;
|
||||
unsigned char* readBytes = new unsigned char[nBytes];
|
||||
if (count << 3 > bits->available()) {
|
||||
|
@ -135,9 +134,9 @@ namespace zxing {
|
|||
const char *encoding = guessEncoding(readBytes, nBytes);
|
||||
append(result, readBytes, nBytes, encoding);
|
||||
delete[] readBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
int nBytes = count;
|
||||
unsigned char* bytes = new unsigned char[nBytes];
|
||||
int i = 0;
|
||||
|
@ -189,9 +188,9 @@ namespace zxing {
|
|||
}
|
||||
append(result, bytes, nBytes, ASCII);
|
||||
delete[] bytes;
|
||||
}
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
int nBytes = count;
|
||||
unsigned char* bytes = new unsigned char[nBytes];
|
||||
int i = 0;
|
||||
|
@ -207,10 +206,10 @@ namespace zxing {
|
|||
}
|
||||
append(result, bytes, nBytes, ASCII);
|
||||
delete[] bytes;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) {
|
||||
const char *
|
||||
DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) {
|
||||
const bool ASSUME_SHIFT_JIS = false;
|
||||
char const* const PLATFORM_DEFAULT_ENCODING="UTF-8";
|
||||
|
||||
|
@ -326,9 +325,9 @@ namespace zxing {
|
|||
}
|
||||
// Otherwise, we take a wild guess with platform encoding
|
||||
return PLATFORM_DEFAULT_ENCODING;
|
||||
}
|
||||
}
|
||||
|
||||
string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
|
||||
string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
|
||||
string result;
|
||||
Ref<BitSource> bits(new BitSource(bytes));
|
||||
Mode *mode = &Mode::TERMINATOR;
|
||||
|
@ -357,7 +356,4 @@ namespace zxing {
|
|||
}
|
||||
} while (mode != &Mode::TERMINATOR);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue