From: srowen Date: Fri, 15 Feb 2008 16:21:55 +0000 (+0000) Subject: Fixed UTF-8 detection, again, and added unit test X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=4618d7794696e813e530b5ffc1df447176aebcf3;hp=55937e92102b86ece5f367d98e44907aa70bd6f1;p=zxing.git Fixed UTF-8 detection, again, and added unit test git-svn-id: http://zxing.googlecode.com/svn/trunk@204 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index e69ca8d5..4de854f9 100644 --- a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -208,28 +208,31 @@ final class DecodedBitStreamParser { // If we see something else in that second byte, we'll make the risky guess // that it's UTF-8. int length = bytes.length; + boolean canBeISO88591 = true; for (int i = 0; i < length; i++) { int value = bytes[i] & 0xFF; if (value >= 0x80 && value <= 0x9F && i < length - 1) { + canBeISO88591 = false; // ISO-8859-1 shouldn't use this, but before we decide it is Shift_JIS, // just double check that it is followed by a byte that's valid in // the Shift_JIS encoding int nextValue = bytes[i + 1] & 0xFF; if ((value & 0x1) == 0) { - // if even, - if (nextValue >= 0x9F && nextValue <= 0xFC) { - return SHIFT_JIS; + // if even, next value should be in [0x9F,0xFC] + // if not, we'll guess UTF-8 + if (nextValue < 0x9F || nextValue > 0xFC) { + return UTF8; } } else { - if (nextValue >= 0x40 && nextValue <= 0x9E) { - return SHIFT_JIS; + // if odd, next value should be in [0x40,0x9E] + // if not, we'll guess UTF-8 + if (nextValue < 0x40 || nextValue > 0x9E) { + return UTF8; } } - // otherwise we're going to take a guess that it's UTF-8 - return UTF8; } } - return ISO88591; + return canBeISO88591 ? ISO88591 : SHIFT_JIS; } } diff --git a/core/test/data/blackbox/qrcode-1/21.png b/core/test/data/blackbox/qrcode-1/21.png new file mode 100644 index 00000000..b924a35a Binary files /dev/null and b/core/test/data/blackbox/qrcode-1/21.png differ diff --git a/core/test/data/blackbox/qrcode-1/21.txt b/core/test/data/blackbox/qrcode-1/21.txt new file mode 100644 index 00000000..6bc3cf2e --- /dev/null +++ b/core/test/data/blackbox/qrcode-1/21.txt @@ -0,0 +1,2 @@ +ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP +árvíztűrő tükörfúrógép \ No newline at end of file