Skip to content

Commit e53db67

Browse files
committed
v2.5.7
修复 1. 配置导入导出
1 parent 74c0b16 commit e53db67

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
minSdkVersion 23
1313
//noinspection OldTargetApi
1414
targetSdkVersion 34
15-
versionCode 79
16-
versionName '2.5.6'
15+
versionCode 80
16+
versionName '2.5.7'
1717
resourceConfigurations += ['zh', 'zh-rCN']
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

app/src/main/java/top/fumiama/copymanga/strings/Base16384.kt

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ object Base16384 {
1111
fun encode(input: ByteArray): String {
1212
val sb = StringBuilder()
1313
var buffer = 0
14-
var bitCount = 0
14+
var bLen = 0
1515

1616
for (b in input) {
1717
buffer = (buffer shl 8) or (b.toInt() and 0xFF)
18-
bitCount += 8
19-
while (bitCount >= 14) {
20-
bitCount -= 14
21-
val index = (buffer shr bitCount) and (BASE - 1)
18+
bLen += 8
19+
while (bLen >= 14) {
20+
bLen -= 14
21+
val index = (buffer shr bLen) and (BASE - 1)
2222
sb.append(Char(FIRST_CHAR + index))
23-
buffer = buffer and ((1 shl bitCount) - 1)
23+
buffer = buffer and ((1 shl bLen) - 1)
2424
}
2525
}
2626

27-
if (bitCount in 1..6) {
28-
buffer = (buffer shl (14 - bitCount))
27+
if (bLen > 0) {
28+
buffer = (buffer shl (14 - bLen))
2929
val index = buffer and (BASE - 1)
3030
sb.append(Char(FIRST_CHAR + index))
31-
val padIndex = PAD_START + bitCount
31+
val padIndex = PAD_START + (input.size%7)
3232
sb.append(Char(padIndex))
3333
}
3434

35-
Log.d("MyB14", "encode bitCount $bitCount, len ${input.size}, data: ${Base64.encode(input, Base64.DEFAULT).decodeToString()}")
35+
Log.d("MyB14", "encode offset ${input.size%7}, len ${input.size}, data: ${Base64.encode(input, Base64.DEFAULT).decodeToString()}")
3636

3737
return sb.toString()
3838
}
3939

4040
fun decode(input: String): ByteArray {
4141
val bits = mutableListOf<Boolean>()
42-
var tailBits = 0
42+
var offset = 0
4343
for (c in input) {
4444
when (val code = c.code) {
4545
in FIRST_CHAR until FIRST_CHAR + BASE -> {
@@ -49,25 +49,33 @@ object Base16384 {
4949
}
5050
}
5151
in (PAD_START + 1)..(PAD_START + 6) -> {
52-
tailBits = code - PAD_START
52+
offset = code - PAD_START
5353
break
5454
}
5555
else -> throw IllegalArgumentException("Invalid base16384 char: $c")
5656
}
5757
}
5858

59-
val totalBits = bits.size - (14 - tailBits)
60-
val byteCount = totalBits / 8
61-
val out = ByteArray(byteCount)
62-
for (i in 0 until byteCount) {
59+
val dLen = input.toByteArray(Charsets.UTF_16BE).size
60+
val outLen = when (offset) {
61+
0 -> dLen
62+
1 -> dLen - 4
63+
2, 3 -> dLen - 6
64+
4, 5 -> dLen - 8
65+
6 -> dLen - 10
66+
else -> dLen
67+
}/8*7 + offset
68+
69+
val out = ByteArray(outLen)
70+
for (i in 0 until outLen) {
6371
var byteVal = 0
6472
for (j in 0 until 8) {
6573
if (bits[i * 8 + j]) byteVal = byteVal or (1 shl (7 - j))
6674
}
6775
out[i] = byteVal.toByte()
6876
}
6977

70-
Log.d("MyB14", "decode totalBits $totalBits, tailBits $tailBits, len ${out.size}, data: ${Base64.encode(out, Base64.DEFAULT).decodeToString()}")
78+
Log.d("MyB14", "decode offset $offset, len ${out.size}, data: ${Base64.encode(out, Base64.DEFAULT).decodeToString()}")
7179
return out
7280
}
7381
}

0 commit comments

Comments
 (0)