summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.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/datamatrix/BC_EdifactEncoder.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/datamatrix/BC_EdifactEncoder.cpp')
-rw-r--r--xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp219
1 files changed, 110 insertions, 109 deletions
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
index cc46b8156d..60b796a196 100644
--- a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
+++ b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
@@ -29,125 +29,126 @@
#include "BC_EncoderContext.h"
#include "BC_HighLevelEncoder.h"
#include "BC_EdifactEncoder.h"
-CBC_EdifactEncoder::CBC_EdifactEncoder()
-{
+CBC_EdifactEncoder::CBC_EdifactEncoder() {}
+CBC_EdifactEncoder::~CBC_EdifactEncoder() {}
+int32_t CBC_EdifactEncoder::getEncodingMode() {
+ return EDIFACT_ENCODATION;
}
-CBC_EdifactEncoder::~CBC_EdifactEncoder()
-{
-}
-int32_t CBC_EdifactEncoder::getEncodingMode()
-{
- return EDIFACT_ENCODATION;
-}
-void CBC_EdifactEncoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- CFX_WideString buffer;
- while (context.hasMoreCharacters()) {
- FX_WCHAR c = context.getCurrentChar();
- encodeChar(c, buffer, e);
- if (e != BCExceptionNO) {
- return;
- }
- context.m_pos++;
- int32_t count = buffer.GetLength();
- if (count >= 4) {
- context.writeCodewords(encodeToCodewords(buffer, 0, e));
- if (e != BCExceptionNO) {
- return;
- }
- buffer.Delete(0, 4);
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- context.signalEncoderChange(ASCII_ENCODATION);
- break;
- }
- }
+void CBC_EdifactEncoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ encodeChar(c, buffer, e);
+ if (e != BCExceptionNO) {
+ return;
}
- buffer += (FX_WCHAR)31;
- handleEOD(context, buffer, e);
-}
-void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext &context, CFX_WideString buffer, int32_t &e)
-{
+ context.m_pos++;
int32_t count = buffer.GetLength();
- if (count == 0) {
+ if (count >= 4) {
+ context.writeCodewords(encodeToCodewords(buffer, 0, e));
+ if (e != BCExceptionNO) {
return;
+ }
+ buffer.Delete(0, 4);
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(ASCII_ENCODATION);
+ break;
+ }
}
- if (count == 1) {
- context.updateSymbolInfo(e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
- int32_t remaining = context.getRemainingCharacters();
- if (remaining == 0 && available <= 2) {
- return;
- }
+ }
+ buffer += (FX_WCHAR)31;
+ handleEOD(context, buffer, e);
+}
+void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext& context,
+ CFX_WideString buffer,
+ int32_t& e) {
+ int32_t count = buffer.GetLength();
+ if (count == 0) {
+ return;
+ }
+ if (count == 1) {
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ return;
}
- if (count > 4) {
- e = BCExceptionIllegalStateCountMustNotExceed4;
- return;
+ int32_t available =
+ context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ int32_t remaining = context.getRemainingCharacters();
+ if (remaining == 0 && available <= 2) {
+ return;
}
- int32_t restChars = count - 1;
- CFX_WideString encoded = encodeToCodewords(buffer, 0, e);
+ }
+ if (count > 4) {
+ e = BCExceptionIllegalStateCountMustNotExceed4;
+ return;
+ }
+ int32_t restChars = count - 1;
+ CFX_WideString encoded = encodeToCodewords(buffer, 0, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_BOOL endOfSymbolReached = !context.hasMoreCharacters();
+ FX_BOOL restInAscii = endOfSymbolReached && restChars <= 2;
+ if (restChars <= 2) {
+ context.updateSymbolInfo(context.getCodewordCount() + restChars, e);
if (e != BCExceptionNO) {
- return;
- }
- FX_BOOL endOfSymbolReached = !context.hasMoreCharacters();
- FX_BOOL restInAscii = endOfSymbolReached && restChars <= 2;
- if (restChars <= 2) {
- context.updateSymbolInfo(context.getCodewordCount() + restChars, e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
- if (available >= 3) {
- restInAscii = FALSE;
- context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(), e);
- if (e != BCExceptionNO) {
- return;
- }
- }
+ return;
}
- if (restInAscii) {
- context.resetSymbolInfo();
- context.m_pos -= restChars;
- } else {
- context.writeCodewords(encoded);
+ int32_t available =
+ context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ if (available >= 3) {
+ restInAscii = FALSE;
+ context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(),
+ e);
+ if (e != BCExceptionNO) {
+ return;
+ }
}
- context.signalEncoderChange(ASCII_ENCODATION);
+ }
+ if (restInAscii) {
+ context.resetSymbolInfo();
+ context.m_pos -= restChars;
+ } else {
+ context.writeCodewords(encoded);
+ }
+ context.signalEncoderChange(ASCII_ENCODATION);
}
-void CBC_EdifactEncoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e)
-{
- if (c >= ' ' && c <= '?') {
- sb += c;
- } else if (c >= '@' && c <= '^') {
- sb += (FX_WCHAR)(c - 64);
- } else {
- CBC_HighLevelEncoder::illegalCharacter(c, e);
- }
+void CBC_EdifactEncoder::encodeChar(FX_WCHAR c,
+ CFX_WideString& sb,
+ int32_t& e) {
+ if (c >= ' ' && c <= '?') {
+ sb += c;
+ } else if (c >= '@' && c <= '^') {
+ sb += (FX_WCHAR)(c - 64);
+ } else {
+ CBC_HighLevelEncoder::illegalCharacter(c, e);
+ }
}
-CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb, int32_t startPos, int32_t &e)
-{
- int32_t len = sb.GetLength() - startPos;
- if (len == 0) {
- e = BCExceptionNoContents;
- return (FX_WCHAR*)"";
- }
- FX_WCHAR c1 = sb.GetAt(startPos);
- FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
- FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
- FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
- int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
- FX_WCHAR cw1 = (FX_WCHAR) ((v >> 16) & 255);
- FX_WCHAR cw2 = (FX_WCHAR) ((v >> 8) & 255);
- FX_WCHAR cw3 = (FX_WCHAR) (v & 255);
- CFX_WideString res;
- res += cw1;
- if (len >= 2) {
- res += cw2;
- }
- if (len >= 3) {
- res += cw3;
- }
- return res;
+CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb,
+ int32_t startPos,
+ int32_t& e) {
+ int32_t len = sb.GetLength() - startPos;
+ if (len == 0) {
+ e = BCExceptionNoContents;
+ return (FX_WCHAR*)"";
+ }
+ FX_WCHAR c1 = sb.GetAt(startPos);
+ FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
+ FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
+ FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
+ int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
+ FX_WCHAR cw1 = (FX_WCHAR)((v >> 16) & 255);
+ FX_WCHAR cw2 = (FX_WCHAR)((v >> 8) & 255);
+ FX_WCHAR cw3 = (FX_WCHAR)(v & 255);
+ CFX_WideString res;
+ res += cw1;
+ if (len >= 2) {
+ res += cw2;
+ }
+ if (len >= 3) {
+ res += cw3;
+ }
+ return res;
}