use of com.google.zxing.common.BitArray in project zxing by zxing.
the class EncoderTest method testStuffBits.
private static void testStuffBits(int wordSize, String bits, String expected) {
BitArray in = toBitArray(bits);
BitArray stuffed = Encoder.stuffBits(in, wordSize);
assertEquals("stuffBits() failed for input string: " + bits, stripSpace(expected), stripSpace(stuffed.toString()));
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class EncoderTest method testHighLevelEncodeString.
private static void testHighLevelEncodeString(String s, String expectedBits) {
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
String receivedBits = stripSpace(bits.toString());
assertEquals("highLevelEncode() failed for input string: " + s, stripSpace(expectedBits), receivedBits);
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class BinaryUtil method buildBitArrayFromString.
/*
* Constructs a BitArray from a String like the one returned from BitArray.toString()
*/
public static BitArray buildBitArrayFromString(CharSequence data) {
CharSequence dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
BitArray binary = new BitArray(SPACE.matcher(dotsAndXs).replaceAll("").length());
int counter = 0;
for (int i = 0; i < dotsAndXs.length(); ++i) {
if (i % 9 == 0) {
// spaces
if (dotsAndXs.charAt(i) != ' ') {
throw new IllegalStateException("space expected");
}
continue;
}
char currentChar = dotsAndXs.charAt(i);
if (currentChar == 'X' || currentChar == 'x') {
binary.set(counter);
}
counter++;
}
return binary;
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class BinaryUtilTest method checkWithoutSpaces.
private static void checkWithoutSpaces(CharSequence data) {
CharSequence dataWithoutSpaces = SPACE.matcher(data).replaceAll("");
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(dataWithoutSpaces);
assertEquals(data, binary.toString());
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class BinaryUtilTest method check.
private static void check(CharSequence data) {
BitArray binary = BinaryUtil.buildBitArrayFromString(data);
assertEquals(data, binary.toString());
}
Aggregations