mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
support for utf8-encoded zip entry names
This commit is contained in:
parent
b512d3505f
commit
4e4e780f03
2 changed files with 39 additions and 7 deletions
|
@ -89,12 +89,43 @@ final class MyBufferedInputStream extends InputStream {
|
||||||
return (fourthByte << 24) + (thirdByte << 16) + (secondByte << 8) + firstByte;
|
return (fourthByte << 24) + (thirdByte << 16) + (secondByte << 8) + firstByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
String readString(int stringLength) throws IOException {
|
private static final boolean isUtf8String(byte[] array) {
|
||||||
char[] array = new char[stringLength];
|
int nonLeadingCharsCounter = 0;
|
||||||
for (int i = 0; i < stringLength; i++) {
|
for (byte b : array) {
|
||||||
array[i] = (char)read();
|
if (nonLeadingCharsCounter == 0) {
|
||||||
|
if ((b & 0x80) != 0) {
|
||||||
|
if ((b & 0xE0) == 0xC0) {
|
||||||
|
nonLeadingCharsCounter = 1;
|
||||||
|
} else if ((b & 0xF0) == 0xE0) {
|
||||||
|
nonLeadingCharsCounter = 2;
|
||||||
|
} else if ((b & 0xF8) == 0xF0) {
|
||||||
|
nonLeadingCharsCounter = 3;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return new String(array);
|
}
|
||||||
|
} else {
|
||||||
|
if ((b & 0xC0) != 0x80) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
--nonLeadingCharsCounter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nonLeadingCharsCounter == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String readString(int stringLength) throws IOException {
|
||||||
|
final byte[] array = new byte[stringLength];
|
||||||
|
read(array);
|
||||||
|
if (isUtf8String(array)) {
|
||||||
|
return new String(array, "utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
final char[] chars = new char[stringLength];
|
||||||
|
for (int i = 0; i < stringLength; i++) {
|
||||||
|
chars[i] = (char)(array[i] & 0xFF);
|
||||||
|
}
|
||||||
|
return new String(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <ZLFile.h>
|
#include <ZLFile.h>
|
||||||
#include <FileEncryptionInfo.h>
|
#include <FileEncryptionInfo.h>
|
||||||
#include <ZLFileImage.h>
|
#include <ZLFileImage.h>
|
||||||
|
#include <ZLUnicodeUtil.h>
|
||||||
|
|
||||||
#include "AndroidUtil.h"
|
#include "AndroidUtil.h"
|
||||||
#include "JniEnvelope.h"
|
#include "JniEnvelope.h"
|
||||||
|
@ -288,13 +289,13 @@ jstring AndroidUtil::createJavaString(JNIEnv* env, const std::string &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AndroidUtil::convertNonUtfString(const std::string &str) {
|
std::string AndroidUtil::convertNonUtfString(const std::string &str) {
|
||||||
const int len = str.length();
|
if (ZLUnicodeUtil::isUtf8String(str)) {
|
||||||
if (len == 0) {
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEnv *env = getEnv();
|
JNIEnv *env = getEnv();
|
||||||
|
|
||||||
|
const int len = str.length();
|
||||||
jchar *chars = new jchar[len];
|
jchar *chars = new jchar[len];
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
chars[i] = (unsigned char)str[i];
|
chars[i] = (unsigned char)str[i];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue