#include <iconv.h>
// Required for compatibility. TODO: test on Symbian
+#ifdef ZXING_ICONV_CONST
+#undef ICONV_CONST
+#define ICONV_CONST const
+#endif
+
#ifndef ICONV_CONST
#define ICONV_CONST /**/
#endif
}
iconv_t cd = iconv_open(UTF8, src);
- int maxOut = 4 * nIn + 1;
- unsigned char bufOut[maxOut];
+ const int maxOut = 4 * nIn + 1;
+ unsigned char* bufOut = new unsigned char[maxOut];
ICONV_CONST char *fromPtr = (ICONV_CONST char *)bufIn;
size_t nFrom = nIn;
size_t oneway = iconv(cd, &fromPtr, &nFrom, &toPtr, &nTo);
if (oneway == (size_t)(-1)) {
iconv_close(cd);
+ delete[] bufOut;
throw ReaderException("error converting characters");
}
}
bufOut[nResult] = '\0';
ost << bufOut;
+ delete[] bufOut;
}
void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, ostringstream &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;
- unsigned char buffer[nBytes];
+ unsigned char* buffer = new unsigned char[nBytes];
int offset = 0;
while (count > 0) {
// Each 13 bits encodes a 2-byte character
}
append(result, buffer, nBytes, SHIFT_JIS);
+ delete[] buffer;
}
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, ostringstream &result, int count) {
int nBytes = count;
- unsigned char readBytes[nBytes];
+ unsigned char* readBytes = new unsigned char[nBytes];
if (count << 3 > bits->available()) {
ostringstream s;
s << "Count too large: " << count;
+ delete[] readBytes;
throw ReaderException(s.str().c_str());
}
for (int i = 0; i < count; i++) {
// give a hint.
const char *encoding = guessEncoding(readBytes, nBytes);
append(result, readBytes, nBytes, encoding);
+ delete[] readBytes;
}
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringstream &result, int count) {
int nBytes = count;
- unsigned char bytes[nBytes];
+ unsigned char* bytes = new unsigned char[nBytes];
int i = 0;
// Read three digits at a time
while (count >= 3) {
if (threeDigitsBits >= 1000) {
ostringstream s;
s << "Illegal value for 3-digit unit: " << threeDigitsBits;
+ delete[] bytes;
throw ReaderException(s.str().c_str());
}
bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits / 100];
if (twoDigitsBits >= 100) {
ostringstream s;
s << "Illegal value for 2-digit unit: " << twoDigitsBits;
+ delete[] bytes;
throw ReaderException(s.str().c_str());
}
bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits / 10];
if (digitBits >= 10) {
ostringstream s;
s << "Illegal value for digit unit: " << digitBits;
+ delete[] bytes;
throw ReaderException(s.str().c_str());
}
bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
}
append(result, bytes, nBytes, ASCII);
+ delete[] bytes;
}
void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, ostringstream &result, int count) {
int nBytes = count;
- unsigned char bytes[nBytes];
+ unsigned char* bytes = new unsigned char[nBytes];
int i = 0;
// Read two characters at a time
while (count > 1) {
bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
}
append(result, bytes, nBytes, ASCII);
+ delete[] bytes;
}
const char *