This commit is contained in:
gedoor 2022-01-02 21:23:22 +08:00
parent c3ce99cce2
commit 95c9edf541
4 changed files with 16 additions and 17 deletions

View File

@ -1,6 +1,6 @@
// © 2016 and later: Unicode, Inc. and others. // © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html // License & terms of use: http://www.unicode.org/copyright.html
/** /*
* ****************************************************************************** * ******************************************************************************
* Copyright (C) 2005-2016, International Business Machines Corporation and * * Copyright (C) 2005-2016, International Business Machines Corporation and *
* others. All Rights Reserved. * * others. All Rights Reserved. *
@ -85,13 +85,13 @@ public class CharsetMatch implements Comparable<CharsetMatch> {
* @stable ICU 3.4 * @stable ICU 3.4
*/ */
public String getString(int maxLength) throws java.io.IOException { public String getString(int maxLength) throws java.io.IOException {
String result = null; String result;
if (fInputStream != null) { if (fInputStream != null) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
char[] buffer = new char[1024]; char[] buffer = new char[1024];
Reader reader = getReader(); Reader reader = getReader();
int max = maxLength < 0 ? Integer.MAX_VALUE : maxLength; int max = maxLength < 0 ? Integer.MAX_VALUE : maxLength;
int bytesRead = 0; int bytesRead;
while ((bytesRead = reader.read(buffer, 0, Math.min(max, 1024))) >= 0) { while ((bytesRead = reader.read(buffer, 0, Math.min(max, 1024))) >= 0) {
sb.append(buffer, 0, bytesRead); sb.append(buffer, 0, bytesRead);
@ -231,7 +231,7 @@ public class CharsetMatch implements Comparable<CharsetMatch> {
// If user gave us a byte array, this is it. // If user gave us a byte array, this is it.
private int fRawLength; // Length of data in fRawInput array. private int fRawLength; // Length of data in fRawInput array.
private InputStream fInputStream = null; // User's input stream, or null if the user private final InputStream fInputStream; // User's input stream, or null if the user
// gave us a byte array. // gave us a byte array.
private final String fCharsetName; // The name of the charset this CharsetMatch private final String fCharsetName; // The name of the charset this CharsetMatch

View File

@ -45,7 +45,7 @@ abstract class CharsetRecog_2022 extends CharsetRecognizer {
byte[] seq = escapeSequences[escN]; byte[] seq = escapeSequences[escN];
if ((textLen - i) < seq.length) { if ((textLen - i) < seq.length) {
continue checkEscapes; continue;
} }
for (j = 1; j < seq.length; j++) { for (j = 1; j < seq.length; j++) {

View File

@ -159,8 +159,7 @@ abstract class CharsetRecog_mbcs extends CharsetRecognizer {
done = true; done = true;
return -1; return -1;
} }
int byteValue = det.fRawInput[nextIndex++] & 0x00ff; return det.fRawInput[nextIndex++] & 0x00ff;
return byteValue;
} }
} }
@ -322,9 +321,9 @@ abstract class CharsetRecog_mbcs extends CharsetRecognizer {
@Override @Override
boolean nextChar(iteratedChar it, CharsetDetector det) { boolean nextChar(iteratedChar it, CharsetDetector det) {
it.error = false; it.error = false;
int firstByte = 0; int firstByte;
int secondByte = 0; int secondByte;
int thirdByte = 0; int thirdByte;
//int fourthByte = 0; //int fourthByte = 0;
buildChar: buildChar:
@ -374,7 +373,7 @@ abstract class CharsetRecog_mbcs extends CharsetRecognizer {
} }
} }
return (it.done == false); return (!it.done);
} }
/** /**
@ -466,10 +465,10 @@ abstract class CharsetRecog_mbcs extends CharsetRecognizer {
@Override @Override
boolean nextChar(iteratedChar it, CharsetDetector det) { boolean nextChar(iteratedChar it, CharsetDetector det) {
it.error = false; it.error = false;
int firstByte = 0; int firstByte;
int secondByte = 0; int secondByte;
int thirdByte = 0; int thirdByte;
int fourthByte = 0; int fourthByte;
buildChar: buildChar:
{ {
@ -510,11 +509,10 @@ abstract class CharsetRecog_mbcs extends CharsetRecognizer {
} }
it.error = true; it.error = true;
break buildChar;
} }
} }
return (it.done == false); return (!it.done);
} }
static int[] commonChars = static int[] commonChars =

View File

@ -263,6 +263,7 @@ abstract class CharsetRecog_sbcs extends CharsetRecognizer {
return parser.parse(det, spaceChar); return parser.parse(det, spaceChar);
} }
@SuppressWarnings("SameParameterValue")
int matchIBM420(CharsetDetector det, int[] ngrams, byte[] byteMap, byte spaceChar) { int matchIBM420(CharsetDetector det, int[] ngrams, byte[] byteMap, byte spaceChar) {
NGramParser_IBM420 parser = new NGramParser_IBM420(ngrams, byteMap); NGramParser_IBM420 parser = new NGramParser_IBM420(ngrams, byteMap);
return parser.parse(det, spaceChar); return parser.parse(det, spaceChar);