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_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_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); }