determineConsecutiveDigitCount() public static method

Determines the number of consecutive characters that are encodable using numeric compaction.
public static determineConsecutiveDigitCount ( String msg, int startpos ) : int
msg String the message
startpos int the start position within the message
return int
コード例 #1
0
        public void encode(EncoderContext context)
        {
            //step B
            int n = HighLevelEncoder.determineConsecutiveDigitCount(context.Message, context.Pos);

            if (n >= 2)
            {
                context.writeCodeword(encodeASCIIDigits(context.Message[context.Pos],
                                                        context.Message[context.Pos + 1]));
                context.Pos += 2;
            }
            else
            {
                char c       = context.CurrentChar;
                int  newMode = HighLevelEncoder.lookAheadTest(context.Message, context.Pos, EncodingMode);
                if (newMode != EncodingMode)
                {
                    switch (newMode)
                    {
                    case Encodation.BASE256:
                        context.writeCodeword(HighLevelEncoder.LATCH_TO_BASE256);
                        context.signalEncoderChange(Encodation.BASE256);
                        return;

                    case Encodation.C40:
                        context.writeCodeword(HighLevelEncoder.LATCH_TO_C40);
                        context.signalEncoderChange(Encodation.C40);
                        return;

                    case Encodation.X12:
                        context.writeCodeword(HighLevelEncoder.LATCH_TO_ANSIX12);
                        context.signalEncoderChange(Encodation.X12);
                        break;

                    case Encodation.TEXT:
                        context.writeCodeword(HighLevelEncoder.LATCH_TO_TEXT);
                        context.signalEncoderChange(Encodation.TEXT);
                        break;

                    case Encodation.EDIFACT:
                        context.writeCodeword(HighLevelEncoder.LATCH_TO_EDIFACT);
                        context.signalEncoderChange(Encodation.EDIFACT);
                        break;

                    default:
                        throw new InvalidOperationException("Illegal mode: " + newMode);
                    }
                }
                else if (HighLevelEncoder.isExtendedASCII(c))
                {
                    context.writeCodeword(HighLevelEncoder.UPPER_SHIFT);
                    context.writeCodeword((char)(c - 128 + 1));
                    context.Pos++;
                }
                else
                {
                    context.writeCodeword((char)(c + 1));
                    context.Pos++;
                }
            }
        }