/** * 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; }
/** * 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; }
/** * 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}. */ public 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; } else 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 Mode#KANJI}. */ public 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; } else if (hasNumeric) { return Mode.NUMERIC; } return Mode.BYTE; }