/** * Choose the best mode by examining the content. Note that 'encoding' is used as a hint; * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}. */ private static Mode chooseMode(String content, String encoding) { if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) { // Choose Kanji mode if all input are double-byte characters return Mode.KANJI; } boolean hasNumeric = false; boolean hasAlphanumeric = false; for (int i = 0; i < content.length(); ++i) { char c = content.charAt(i); if (c >= '0' && c <= '9') { hasNumeric = true; } else if (getAlphanumericCode(c) != -1) { hasAlphanumeric = true; } else { return Mode.BYTE; } } if (hasAlphanumeric) { return Mode.ALPHANUMERIC; } if (hasNumeric) { return Mode.NUMERIC; } return Mode.BYTE; }
/** * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits". */ static void appendBytes(String content, Mode mode, BitArray bits, String encoding) throws WriterException { switch (mode) { case NUMERIC: appendNumericBytes(content, bits); break; case ALPHANUMERIC: appendAlphanumericBytes(content, bits); break; case BYTE: append8BitBytes(content, bits, encoding); break; case KANJI: appendKanjiBytes(content, bits); break; default: throw new WriterException("Invalid mode: " + mode); } }
static void appendBytes(String content, Mode mode, BitArray bits, String encoding) throws WriterException { switch (mode) { case NUMERIC: appendNumericBytes(content, bits); return; case ALPHANUMERIC: appendAlphanumericBytes(content, bits); return; case BYTE: append8BitBytes(content, bits, encoding); return; case KANJI: appendKanjiBytes(content, bits); return; default: throw new WriterException("Invalid mode: " + mode); } }
/** * Choose the best mode by examining the content. Note that 'encoding' is used as a hint; * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}. */ private static Mode chooseMode(String content, String encoding) { if ("Shift_JIS".equals(encoding)) { // Choose Kanji mode if all input are double-byte characters return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE; } boolean hasNumeric = false; boolean hasAlphanumeric = false; for (int i = 0; i < content.length(); ++i) { char c = content.charAt(i); if (c >= '0' && c <= '9') { hasNumeric = true; } else if (getAlphanumericCode(c) != -1) { hasAlphanumeric = true; } else { return Mode.BYTE; } } if (hasAlphanumeric) { return Mode.ALPHANUMERIC; } if (hasNumeric) { return Mode.NUMERIC; } return Mode.BYTE; }
/** * Choose the best mode by examining the content. Note that 'encoding' is used as a hint; * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link com.google.zxing.qrcode.decoder.Mode#KANJI}. */ private static Mode chooseMode(String content, String encoding) { if ("Shift_JIS".equals(encoding)) { // Choose Kanji mode if all input are double-byte characters return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE; } boolean hasNumeric = false; boolean hasAlphanumeric = false; for (int i = 0; i < content.length(); ++i) { char c = content.charAt(i); if (c >= '0' && c <= '9') { hasNumeric = true; } else if (getAlphanumericCode(c) != -1) { hasAlphanumeric = true; } else { return Mode.BYTE; } } if (hasAlphanumeric) { return Mode.ALPHANUMERIC; } if (hasNumeric) { return Mode.NUMERIC; } return Mode.BYTE; }