summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
committerNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
commit9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch)
treec97037f398d714665aefccb6eb54d0969ad7030c /xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
parent780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff)
downloadpdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz
XFA: clang-format all pdfium code.
No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \ xargs ../../buildtools/mac/clang-format -i Then manually merged https://codereview.chromium.org/1269223002/ See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none
Diffstat (limited to 'xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp')
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp672
1 files changed, 304 insertions, 368 deletions
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
index d1f453345b..4cffe9d78f 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
@@ -25,117 +25,46 @@
#include "../common/BC_CommonBitArray.h"
#include "BC_OneDReader.h"
#include "BC_OnedCode128Reader.h"
-const int32_t CBC_OnedCode128Reader::CODE_PATTERNS[107][7] = {
- {2, 1, 2, 2, 2, 2, 0},
- {2, 2, 2, 1, 2, 2, 0},
- {2, 2, 2, 2, 2, 1, 0},
- {1, 2, 1, 2, 2, 3, 0},
- {1, 2, 1, 3, 2, 2, 0},
- {1, 3, 1, 2, 2, 2, 0},
- {1, 2, 2, 2, 1, 3, 0},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- {1, 1, 4, 3, 1, 1, 0},
- {4, 1, 1, 1, 1, 3, 0},
- {4, 1, 1, 3, 1, 1, 0},
- {1, 1, 3, 1, 4, 1, 0},
- {1, 1, 4, 1, 3, 1, 0},
- {3, 1, 1, 1, 4, 1, 0},
- {4, 1, 1, 1, 3, 1, 0},
- {2, 1, 1, 4, 1, 2, 0},
- {2, 1, 1, 2, 1, 4, 0},
- {2, 1, 1, 2, 3, 2, 0},
- {2, 3, 3, 1, 1, 1, 2}
-};
-const int32_t CBC_OnedCode128Reader::MAX_AVG_VARIANCE = (int32_t) (256 * 0.25f);
-const int32_t CBC_OnedCode128Reader::MAX_INDIVIDUAL_VARIANCE = (int32_t) (256 * 0.7f);
+const int32_t CBC_OnedCode128Reader::CODE_PATTERNS[107][7] = {
+ {2, 1, 2, 2, 2, 2, 0}, {2, 2, 2, 1, 2, 2, 0}, {2, 2, 2, 2, 2, 1, 0},
+ {1, 2, 1, 2, 2, 3, 0}, {1, 2, 1, 3, 2, 2, 0}, {1, 3, 1, 2, 2, 2, 0},
+ {1, 2, 2, 2, 1, 3, 0}, {1, 2, 2, 3, 1, 2, 0}, {1, 3, 2, 2, 1, 2, 0},
+ {2, 2, 1, 2, 1, 3, 0}, {2, 2, 1, 3, 1, 2, 0}, {2, 3, 1, 2, 1, 2, 0},
+ {1, 1, 2, 2, 3, 2, 0}, {1, 2, 2, 1, 3, 2, 0}, {1, 2, 2, 2, 3, 1, 0},
+ {1, 1, 3, 2, 2, 2, 0}, {1, 2, 3, 1, 2, 2, 0}, {1, 2, 3, 2, 2, 1, 0},
+ {2, 2, 3, 2, 1, 1, 0}, {2, 2, 1, 1, 3, 2, 0}, {2, 2, 1, 2, 3, 1, 0},
+ {2, 1, 3, 2, 1, 2, 0}, {2, 2, 3, 1, 1, 2, 0}, {3, 1, 2, 1, 3, 1, 0},
+ {3, 1, 1, 2, 2, 2, 0}, {3, 2, 1, 1, 2, 2, 0}, {3, 2, 1, 2, 2, 1, 0},
+ {3, 1,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4, 1, 1, 0}, {1, 4, 2, 1, 1, 2, 0}, {1, 4, 2, 2, 1, 1, 0},
+ {2, 4, 1, 2, 1, 1, 0}, {2, 2, 1, 1, 1, 4, 0}, {4, 1, 3, 1, 1, 1, 0},
+ {2, 4, 1, 1, 1, 2, 0}, {1, 3, 4, 1, 1, 1, 0}, {1, 1, 1, 2, 4, 2, 0},
+ {1, 2, 1, 1, 4, 2, 0}, {1, 2, 1, 2, 4, 1, 0}, {1, 1, 4, 2, 1, 2, 0},
+ {1, 2, 4, 1, 1, 2, 0}, {1, 2, 4, 2, 1, 1, 0}, {4, 1, 1, 2, 1, 2, 0},
+ {4, 2, 1, 1, 1, 2, 0}, {4, 2, 1, 2, 1, 1, 0}, {2, 1, 2, 1, 4, 1, 0},
+ {2, 1, 4, 1, 2, 1, 0}, {4, 1, 2, 1, 2, 1, 0}, {1, 1, 1, 1, 4, 3, 0},
+ {1, 1, 1, 3, 4, 1, 0}, {1, 3, 1, 1, 4, 1, 0}, {1, 1, 4, 1, 1, 3, 0},
+ {1, 1, 4, 3, 1, 1, 0}, {4, 1, 1, 1, 1, 3, 0}, {4, 1, 1, 3, 1, 1, 0},
+ {1, 1, 3, 1, 4, 1, 0}, {1, 1, 4, 1, 3, 1, 0}, {3, 1, 1, 1, 4, 1, 0},
+ {4, 1, 1, 1, 3, 1, 0}, {2, 1, 1, 4, 1, 2, 0}, {2, 1, 1, 2, 1, 4, 0},
+ {2, 1, 1, 2, 3, 2, 0}, {2, 3, 3, 1, 1, 1, 2}};
+const int32_t CBC_OnedCode128Reader::MAX_AVG_VARIANCE = (int32_t)(256 * 0.25f);
+const int32_t CBC_OnedCode128Reader::MAX_INDIVIDUAL_VARIANCE =
+ (int32_t)(256 * 0.7f);
const int32_t CBC_OnedCode128Reader::CODE_SHIFT = 98;
const int32_t CBC_OnedCode128Reader::CODE_CODE_C = 99;
const int32_t CBC_OnedCode128Reader::CODE_CODE_B = 100;
@@ -149,282 +78,289 @@ const int32_t CBC_OnedCode128Reader::CODE_START_A = 103;
const int32_t CBC_OnedCode128Reader::CODE_START_B = 104;
const int32_t CBC_OnedCode128Reader::CODE_START_C = 105;
const int32_t CBC_OnedCode128Reader::CODE_STOP = 106;
-CBC_OnedCode128Reader::CBC_OnedCode128Reader()
-{
-}
-CBC_OnedCode128Reader::~CBC_OnedCode128Reader()
-{
-}
-CFX_Int32Array *CBC_OnedCode128Reader::FindStartPattern(CBC_CommonBitArray *row, int32_t &e)
-{
- int32_t width = row->GetSize();
- int32_t rowOffset = 0;
- while (rowOffset < width) {
- if (row->Get(rowOffset)) {
- break;
- }
- rowOffset++;
+CBC_OnedCode128Reader::CBC_OnedCode128Reader() {}
+CBC_OnedCode128Reader::~CBC_OnedCode128Reader() {}
+CFX_Int32Array* CBC_OnedCode128Reader::FindStartPattern(CBC_CommonBitArray* row,
+ int32_t& e) {
+ int32_t width = row->GetSize();
+ int32_t rowOffset = 0;
+ while (rowOffset < width) {
+ if (row->Get(rowOffset)) {
+ break;
}
- int32_t counterPosition = 0;
- CFX_Int32Array counters;
- counters.SetSize(6);
- int32_t patternStart = rowOffset;
- FX_BOOL isWhite = FALSE;
- int32_t patternLength = counters.GetSize();
- for (int32_t i = rowOffset; i < width; i++) {
- FX_BOOL pixel = row->Get(i);
- if (pixel ^ isWhite) {
- counters[counterPosition]++;
- } else {
- if (counterPosition == patternLength - 1) {
- int32_t bestVariance = MAX_AVG_VARIANCE;
- int32_t bestMatch = -1;
- for (int32_t startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) {
- int32_t variance = PatternMatchVariance(&counters, &CODE_PATTERNS[startCode][0], MAX_INDIVIDUAL_VARIANCE);
- if (variance < bestVariance) {
- bestVariance = variance;
- bestMatch = startCode;
- }
- }
- if (bestMatch >= 0) {
- FX_BOOL btemp2 = row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2), patternStart, FALSE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- if (btemp2) {
- CFX_Int32Array *result = FX_NEW CFX_Int32Array;
- result->SetSize(3);
- (*result)[0] = patternStart;
- (*result)[1] = i;
- (*result)[2] = bestMatch;
- return result;
- }
- }
- patternStart += counters[0] + counters[1];
- for (int32_t y = 2; y < patternLength; y++) {
- counters[y - 2] = counters[y];
- }
- counters[patternLength - 2] = 0;
- counters[patternLength - 1] = 0;
- counterPosition--;
- } else {
- counterPosition++;
- }
- counters[counterPosition] = 1;
- isWhite = !isWhite;
- }
- }
- e = BCExceptionNotFound;
- return NULL;
-}
-int32_t CBC_OnedCode128Reader::DecodeCode(CBC_CommonBitArray *row, CFX_Int32Array *counters, int32_t rowOffset, int32_t &e)
-{
- RecordPattern(row, rowOffset, counters, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- int32_t bestVariance = MAX_AVG_VARIANCE;
- int32_t bestMatch = -1;
- for (int32_t d = 0; d < 107; d++) {
- int32_t variance = PatternMatchVariance(counters, &CODE_PATTERNS[d][0], MAX_INDIVIDUAL_VARIANCE);
- if (variance < bestVariance) {
+ rowOffset++;
+ }
+ int32_t counterPosition = 0;
+ CFX_Int32Array counters;
+ counters.SetSize(6);
+ int32_t patternStart = rowOffset;
+ FX_BOOL isWhite = FALSE;
+ int32_t patternLength = counters.GetSize();
+ for (int32_t i = rowOffset; i < width; i++) {
+ FX_BOOL pixel = row->Get(i);
+ if (pixel ^ isWhite) {
+ counters[counterPosition]++;
+ } else {
+ if (counterPosition == patternLength - 1) {
+ int32_t bestVariance = MAX_AVG_VARIANCE;
+ int32_t bestMatch = -1;
+ for (int32_t startCode = CODE_START_A; startCode <= CODE_START_C;
+ startCode++) {
+ int32_t variance = PatternMatchVariance(
+ &counters, &CODE_PATTERNS[startCode][0], MAX_INDIVIDUAL_VARIANCE);
+ if (variance < bestVariance) {
bestVariance = variance;
- bestMatch = d;
+ bestMatch = startCode;
+ }
+ }
+ if (bestMatch >= 0) {
+ FX_BOOL btemp2 =
+ row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),
+ patternStart, FALSE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ if (btemp2) {
+ CFX_Int32Array* result = FX_NEW CFX_Int32Array;
+ result->SetSize(3);
+ (*result)[0] = patternStart;
+ (*result)[1] = i;
+ (*result)[2] = bestMatch;
+ return result;
+ }
}
+ patternStart += counters[0] + counters[1];
+ for (int32_t y = 2; y < patternLength; y++) {
+ counters[y - 2] = counters[y];
+ }
+ counters[patternLength - 2] = 0;
+ counters[patternLength - 1] = 0;
+ counterPosition--;
+ } else {
+ counterPosition++;
+ }
+ counters[counterPosition] = 1;
+ isWhite = !isWhite;
}
- if (bestMatch >= 0) {
- return bestMatch;
- } else {
- e = BCExceptionNotFound;
- return 0;
+ }
+ e = BCExceptionNotFound;
+ return NULL;
+}
+int32_t CBC_OnedCode128Reader::DecodeCode(CBC_CommonBitArray* row,
+ CFX_Int32Array* counters,
+ int32_t rowOffset,
+ int32_t& e) {
+ RecordPattern(row, rowOffset, counters, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ int32_t bestVariance = MAX_AVG_VARIANCE;
+ int32_t bestMatch = -1;
+ for (int32_t d = 0; d < 107; d++) {
+ int32_t variance = PatternMatchVariance(counters, &CODE_PATTERNS[d][0],
+ MAX_INDIVIDUAL_VARIANCE);
+ if (variance < bestVariance) {
+ bestVariance = variance;
+ bestMatch = d;
}
+ }
+ if (bestMatch >= 0) {
+ return bestMatch;
+ } else {
+ e = BCExceptionNotFound;
return 0;
+ }
+ return 0;
}
-CFX_ByteString CBC_OnedCode128Reader::DecodeRow(int32_t rowNumber, CBC_CommonBitArray *row, int32_t hints, int32_t &e)
-{
- CFX_Int32Array *startPatternInfo = FindStartPattern(row, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- int32_t startCode = (*startPatternInfo)[2];
- int32_t codeSet;
- switch (startCode) {
- case 103:
- codeSet = CODE_CODE_A;
- break;
- case 104:
- codeSet = CODE_CODE_B;
- break;
- case 105:
- codeSet = CODE_CODE_C;
- break;
- default:
- if(startPatternInfo != NULL) {
- startPatternInfo->RemoveAll();
- delete startPatternInfo;
- startPatternInfo = NULL;
- }
- e = BCExceptionFormatException;
- return "";
- }
- FX_BOOL done = FALSE;
- FX_BOOL isNextShifted = FALSE;
- CFX_ByteString result;
- int32_t lastStart = (*startPatternInfo)[0];
- int32_t nextStart = (*startPatternInfo)[1];
- if(startPatternInfo != NULL) {
+CFX_ByteString CBC_OnedCode128Reader::DecodeRow(int32_t rowNumber,
+ CBC_CommonBitArray* row,
+ int32_t hints,
+ int32_t& e) {
+ CFX_Int32Array* startPatternInfo = FindStartPattern(row, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ int32_t startCode = (*startPatternInfo)[2];
+ int32_t codeSet;
+ switch (startCode) {
+ case 103:
+ codeSet = CODE_CODE_A;
+ break;
+ case 104:
+ codeSet = CODE_CODE_B;
+ break;
+ case 105:
+ codeSet = CODE_CODE_C;
+ break;
+ default:
+ if (startPatternInfo != NULL) {
startPatternInfo->RemoveAll();
delete startPatternInfo;
startPatternInfo = NULL;
+ }
+ e = BCExceptionFormatException;
+ return "";
+ }
+ FX_BOOL done = FALSE;
+ FX_BOOL isNextShifted = FALSE;
+ CFX_ByteString result;
+ int32_t lastStart = (*startPatternInfo)[0];
+ int32_t nextStart = (*startPatternInfo)[1];
+ if (startPatternInfo != NULL) {
+ startPatternInfo->RemoveAll();
+ delete startPatternInfo;
+ startPatternInfo = NULL;
+ }
+ CFX_Int32Array counters;
+ counters.SetSize(6);
+ int32_t lastCode = 0;
+ int32_t code = 0;
+ int32_t checksumTotal = startCode;
+ int32_t multiplier = 0;
+ FX_BOOL lastCharacterWasPrintable = TRUE;
+ while (!done) {
+ FX_BOOL unshift = isNextShifted;
+ isNextShifted = FALSE;
+ lastCode = code;
+ code = DecodeCode(row, &counters, nextStart, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = TRUE;
}
- CFX_Int32Array counters;
- counters.SetSize(6);
- int32_t lastCode = 0;
- int32_t code = 0;
- int32_t checksumTotal = startCode;
- int32_t multiplier = 0;
- FX_BOOL lastCharacterWasPrintable = TRUE;
- while (!done) {
- FX_BOOL unshift = isNextShifted;
- isNextShifted = FALSE;
- lastCode = code;
- code = DecodeCode(row, &counters, nextStart, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- if (code != CODE_STOP) {
- lastCharacterWasPrintable = TRUE;
- }
- if (code != CODE_STOP) {
- multiplier++;
- checksumTotal += multiplier * code;
- }
- lastStart = nextStart;
- for (int32_t i = 0; i < counters.GetSize(); i++) {
- nextStart += counters[i];
- }
- switch (code) {
- case 103:
- case 104:
- case 105:
- e = BCExceptionFormatException;
- return "";
- }
- switch (codeSet) {
+ if (code != CODE_STOP) {
+ multiplier++;
+ checksumTotal += multiplier * code;
+ }
+ lastStart = nextStart;
+ for (int32_t i = 0; i < counters.GetSize(); i++) {
+ nextStart += counters[i];
+ }
+ switch (code) {
+ case 103:
+ case 104:
+ case 105:
+ e = BCExceptionFormatException;
+ return "";
+ }
+ switch (codeSet) {
+ case 101:
+ if (code < 64) {
+ result += (FX_CHAR)(' ' + code);
+ } else if (code < 96) {
+ result += (FX_CHAR)(code - 64);
+ } else {
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = FALSE;
+ }
+ switch (code) {
+ case 102:
+ case 97:
+ case 96:
case 101:
- if (code < 64) {
- result += (FX_CHAR) (' ' + code);
- } else if (code < 96) {
- result += (FX_CHAR) (code - 64);
- } else {
- if (code != CODE_STOP) {
- lastCharacterWasPrintable = FALSE;
- }
- switch (code) {
- case 102:
- case 97:
- case 96:
- case 101:
- break;
- case 98:
- isNextShifted = TRUE;
- codeSet = CODE_CODE_B;
- break;
- case 100:
- codeSet = CODE_CODE_B;
- break;
- case 99:
- codeSet = CODE_CODE_C;
- break;
- case 106:
- done = TRUE;
- break;
- }
- }
- break;
+ break;
+ case 98:
+ isNextShifted = TRUE;
+ codeSet = CODE_CODE_B;
+ break;
+ case 100:
+ codeSet = CODE_CODE_B;
+ break;
+ case 99:
+ codeSet = CODE_CODE_C;
+ break;
+ case 106:
+ done = TRUE;
+ break;
+ }
+ }
+ break;
+ case 100:
+ if (code < 96) {
+ result += (FX_CHAR)(' ' + code);
+ } else {
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = FALSE;
+ }
+ switch (code) {
+ case 102:
+ case 97:
+ case 96:
case 100:
- if (code < 96) {
- result += (FX_CHAR) (' ' + code);
- } else {
- if (code != CODE_STOP) {
- lastCharacterWasPrintable = FALSE;
- }
- switch (code) {
- case 102:
- case 97:
- case 96:
- case 100:
- break;
- case 98:
- isNextShifted = TRUE;
- codeSet = CODE_CODE_A;
- break;
- case 101:
- codeSet = CODE_CODE_A;
- break;
- case 99:
- codeSet = CODE_CODE_C;
- break;
- case 106:
- done = TRUE;
- break;
- }
- }
- break;
+ break;
+ case 98:
+ isNextShifted = TRUE;
+ codeSet = CODE_CODE_A;
+ break;
+ case 101:
+ codeSet = CODE_CODE_A;
+ break;
case 99:
- if (code < 100) {
- if (code < 10) {
- result += '0';
- }
- FX_CHAR temp[128];
+ codeSet = CODE_CODE_C;
+ break;
+ case 106:
+ done = TRUE;
+ break;
+ }
+ }
+ break;
+ case 99:
+ if (code < 100) {
+ if (code < 10) {
+ result += '0';
+ }
+ FX_CHAR temp[128];
#if defined(_FX_WINAPI_PARTITION_APP_)
- sprintf_s(temp, 128, "%d", code);
+ sprintf_s(temp, 128, "%d", code);
#else
- sprintf(temp, "%d", code);
+ sprintf(temp, "%d", code);
#endif
- result += temp;
- } else {
- if (code != CODE_STOP) {
- lastCharacterWasPrintable = FALSE;
- }
- switch (code) {
- case 102:
- break;
- case 101:
- codeSet = CODE_CODE_A;
- break;
- case 100:
- codeSet = CODE_CODE_B;
- break;
- case 106:
- done = TRUE;
- break;
- }
- }
- break;
- }
- if (unshift) {
- codeSet = codeSet == CODE_CODE_A ? CODE_CODE_B : CODE_CODE_A;
- }
- }
- int32_t width = row->GetSize();
- while (nextStart < width && row->Get(nextStart)) {
- nextStart++;
- }
- FX_BOOL boolT1 = row->IsRange(nextStart, FX_MIN(width, nextStart + (nextStart - lastStart) / 2), FALSE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- if (!boolT1) {
- e = BCExceptionNotFound;
- return "";
- }
- checksumTotal -= multiplier * lastCode;
- if (checksumTotal % 103 != lastCode) {
- e = BCExceptionChecksumException;
- return "";
- }
- int32_t resultLength = result.GetLength();
- if (resultLength > 0 && lastCharacterWasPrintable) {
- if (codeSet == CODE_CODE_C) {
- result = result.Mid(0, result.GetLength() - 2);
+ result += temp;
} else {
- result = result.Mid(0, result.GetLength() - 1);
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = FALSE;
+ }
+ switch (code) {
+ case 102:
+ break;
+ case 101:
+ codeSet = CODE_CODE_A;
+ break;
+ case 100:
+ codeSet = CODE_CODE_B;
+ break;
+ case 106:
+ done = TRUE;
+ break;
+ }
}
+ break;
}
- if (result.GetLength() == 0) {
- e = BCExceptionFormatException;
- return "";
+ if (unshift) {
+ codeSet = codeSet == CODE_CODE_A ? CODE_CODE_B : CODE_CODE_A;
+ }
+ }
+ int32_t width = row->GetSize();
+ while (nextStart < width && row->Get(nextStart)) {
+ nextStart++;
+ }
+ FX_BOOL boolT1 = row->IsRange(
+ nextStart, FX_MIN(width, nextStart + (nextStart - lastStart) / 2), FALSE,
+ e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ if (!boolT1) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ checksumTotal -= multiplier * lastCode;
+ if (checksumTotal % 103 != lastCode) {
+ e = BCExceptionChecksumException;
+ return "";
+ }
+ int32_t resultLength = result.GetLength();
+ if (resultLength > 0 && lastCharacterWasPrintable) {
+ if (codeSet == CODE_CODE_C) {
+ result = result.Mid(0, result.GetLength() - 2);
+ } else {
+ result = result.Mid(0, result.GetLength() - 1);
}
- return result;
+ }
+ if (result.GetLength() == 0) {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ return result;
}