Support UTF-8 BOM - closes #141
This commit is contained in:
parent
0b7ab6dfe0
commit
76a71dd87c
1 changed files with 7 additions and 4 deletions
|
@ -3,17 +3,14 @@ package org.ligi.passandroid.model;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.ibm.icu.text.CharsetDetector;
|
||||
import com.ibm.icu.text.CharsetMatch;
|
||||
|
||||
import org.ligi.passandroid.App;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import org.ligi.passandroid.App;
|
||||
|
||||
@VisibleForTesting
|
||||
public class AppleStylePassTranslation extends HashMap<String, String> {
|
||||
|
@ -63,6 +60,12 @@ public class AppleStylePassTranslation extends HashMap<String, String> {
|
|||
dataInputStream.readFully(fileData);
|
||||
dataInputStream.close();
|
||||
|
||||
if (fileData[0] == (byte) 0xEF && fileData[1] == (byte) 0xBB && fileData[2] == (byte) 0xBF) {
|
||||
final byte[] crop = new byte[fileData.length - 3];
|
||||
System.arraycopy(fileData, 3, crop, 0, crop.length);
|
||||
return new String(crop, "utf-8");
|
||||
}
|
||||
|
||||
final CharsetMatch match = new CharsetDetector().setText(fileData).detect();
|
||||
|
||||
if (match != null) try {
|
||||
|
|
Loading…
Reference in a new issue