package com.google.zxing.datamatrix.encoder; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public final class X12Encoder extends C40Encoder { @Override // com.google.zxing.datamatrix.encoder.C40Encoder, com.google.zxing.datamatrix.encoder.Encoder public int getEncodingMode() { return 3; } @Override // com.google.zxing.datamatrix.encoder.C40Encoder, com.google.zxing.datamatrix.encoder.Encoder public void encode(EncoderContext encoderContext) { StringBuilder sb = new StringBuilder(); while (true) { if (!encoderContext.hasMoreCharacters()) { break; } char currentChar = encoderContext.getCurrentChar(); encoderContext.pos++; encodeChar(currentChar, sb); if (sb.length() % 3 == 0) { writeNextTriplet(encoderContext, sb); if (HighLevelEncoder.lookAheadTest(encoderContext.getMessage(), encoderContext.pos, getEncodingMode()) != getEncodingMode()) { encoderContext.signalEncoderChange(0); break; } } } handleEOD(encoderContext, sb); } @Override // com.google.zxing.datamatrix.encoder.C40Encoder int encodeChar(char c, StringBuilder sb) { if (c == '\r') { sb.append((char) 0); } else if (c == ' ') { sb.append((char) 3); } else if (c == '*') { sb.append((char) 1); } else if (c == '>') { sb.append((char) 2); } else if (c >= '0' && c <= '9') { sb.append((char) (c - ',')); } else if (c >= 'A' && c <= 'Z') { sb.append((char) (c - '3')); } else { HighLevelEncoder.illegalCharacter(c); } return 1; } @Override // com.google.zxing.datamatrix.encoder.C40Encoder void handleEOD(EncoderContext encoderContext, StringBuilder sb) { encoderContext.updateSymbolInfo(); int dataCapacity = encoderContext.getSymbolInfo().getDataCapacity() - encoderContext.getCodewordCount(); encoderContext.pos -= sb.length(); if (encoderContext.getRemainingCharacters() > 1 || dataCapacity > 1 || encoderContext.getRemainingCharacters() != dataCapacity) { encoderContext.writeCodeword((char) 254); } if (encoderContext.getNewEncoding() < 0) { encoderContext.signalEncoderChange(0); } } }