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; } } } buffer += (FX_WCHAR)31; handleEOD(context, buffer, e); }
void CBC_ASCIIEncoder::Encode(CBC_EncoderContext& context, int32_t& e) { int32_t n = CBC_HighLevelEncoder::determineConsecutiveDigitCount( context.m_msg, context.m_pos); if (n >= 2) { FX_WCHAR code = encodeASCIIDigits(context.m_msg.GetAt(context.m_pos), context.m_msg.GetAt(context.m_pos + 1), e); if (e != BCExceptionNO) { return; } context.writeCodeword(code); context.m_pos += 2; } else { FX_WCHAR c = context.getCurrentChar(); int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( context.m_msg, context.m_pos, getEncodingMode()); if (newMode != getEncodingMode()) { switch (newMode) { case BASE256_ENCODATION: context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_BASE256); context.signalEncoderChange(BASE256_ENCODATION); return; case C40_ENCODATION: context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_C40); context.signalEncoderChange(C40_ENCODATION); return; case X12_ENCODATION: context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_ANSIX12); context.signalEncoderChange(X12_ENCODATION); break; case TEXT_ENCODATION: context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_TEXT); context.signalEncoderChange(TEXT_ENCODATION); break; case EDIFACT_ENCODATION: context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_EDIFACT); context.signalEncoderChange(EDIFACT_ENCODATION); break; default: e = BCExceptionIllegalStateIllegalMode; return; } } else if (CBC_HighLevelEncoder::isExtendedASCII(c)) { context.writeCodeword(CBC_HighLevelEncoder::UPPER_SHIFT); context.writeCodeword((FX_WCHAR)(c - 128 + 1)); context.m_pos++; } else { context.writeCodeword((FX_WCHAR)(c + 1)); context.m_pos++; } } }
int32_t CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext& context, CFX_WideString& buffer, CFX_WideString& removed, int32_t lastCharSize, int32_t& e) { int32_t count = buffer.GetLength(); buffer.Delete(count - lastCharSize, count); context.m_pos--; FX_WCHAR c = context.getCurrentChar(); lastCharSize = encodeChar(c, removed, e); BC_EXCEPTION_CHECK_ReturnValue(e, -1); context.resetSymbolInfo(); return lastCharSize; }
void CBC_C40Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { CFX_WideString buffer; while (context.hasMoreCharacters()) { FX_WCHAR c = context.getCurrentChar(); context.m_pos++; int32_t lastCharSize = encodeChar(c, buffer, e); if (e != BCExceptionNO) { return; } int32_t unwritten = (buffer.GetLength() / 3) * 2; int32_t curCodewordCount = context.getCodewordCount() + unwritten; context.updateSymbolInfo(curCodewordCount, e); if (e != BCExceptionNO) { return; } int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount; if (!context.hasMoreCharacters()) { CFX_WideString removed; if ((buffer.GetLength() % 3) == 2) { if (available < 2 || available > 2) { lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize, e); if (e != BCExceptionNO) { return; } } } while ((buffer.GetLength() % 3) == 1 && ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) { lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize, e); if (e != BCExceptionNO) { return; } } break; } int32_t count = buffer.GetLength(); if ((count % 3) == 0) { int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( context.m_msg, context.m_pos, getEncodingMode()); if (newMode != getEncodingMode()) { context.signalEncoderChange(newMode); break; } } } handleEOD(context, buffer, e); }
void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { CFX_WideString buffer; buffer += (FX_WCHAR)'\0'; while (context.hasMoreCharacters()) { FX_WCHAR c = context.getCurrentChar(); buffer += c; context.m_pos++; int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( context.m_msg, context.m_pos, getEncodingMode()); if (newMode != getEncodingMode()) { context.signalEncoderChange(newMode); break; } } int32_t dataCount = buffer.GetLength() - 1; FX_CHAR buf[128]; FXSYS_itoa(dataCount, buf, 10); buffer.SetAt(0, FX_WCHAR(*buf) - '0'); int32_t lengthFieldSize = 1; int32_t currentSize = context.getCodewordCount() + dataCount + lengthFieldSize; context.updateSymbolInfo(currentSize, e); if (e != BCExceptionNO) { return; } FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0; if (context.hasMoreCharacters() || mustPad) { if (dataCount <= 249) { buffer.SetAt(0, (FX_WCHAR)dataCount); } else if (dataCount > 249 && dataCount <= 1555) { buffer.SetAt(0, (FX_WCHAR)((dataCount / 250) + 249)); buffer.Insert(1, (FX_WCHAR)(dataCount % 250)); } else { e = BCExceptionIllegalStateMessageLengthInvalid; return; } } for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) { context.writeCodeword( randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1)); } }
void CBC_X12Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { CFX_WideString buffer; while (context.hasMoreCharacters()) { FX_WCHAR c = context.getCurrentChar(); context.m_pos++; encodeChar(c, buffer, e); if (e != BCExceptionNO) { return; } int32_t count = buffer.GetLength(); if ((count % 3) == 0) { writeNextTriplet(context, buffer); int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( context.m_msg, context.m_pos, getEncodingMode()); if (newMode != getEncodingMode()) { context.signalEncoderChange(newMode); break; } } } handleEOD(context, buffer, e); }