lz-string4java
lz-string4java copied to clipboard
suggestion
https://github.com/rufushuang/lz-string4java/blob/fb6d5d489ef8b747340244c74d30710b63435773/src/rufus/lzstring4java/LZString.java#L465 I'm process with lzstring into kotlin,I just found you java repoistry. here is some thing may be help:
}
// TODO: very strange here, c above is as char/string, here further is a int, rename "c" in the switch as "cc"
int cc;
switch (cc = bits) {
Your defined int cc
should be int next
.
as we can find in pre codes. next
is used to find out next step
here is my in kotlin
while (true) {
if (data.index > length) {
return ""
}
doPower(0, 1, numBits)
next=bits //source js version is take mistake,make mixed with next and c
when (next) {
0 -> doPower(0, 1, 8, 2)
1 -> doPower(0, 1, 16, 2)
2 -> return builder.toString()
}
checkEnlargeIn()
if (dictionary.size>next) {
entry = dictionary[next]
} else if (next == dictSize) {
entry = w + w[0]
} else {
return null
}
builder.append(entry)
also happend in here
fun doPower(initBits: Int, initPower: Int, initMaxPowerFactor: Int, mode: Int = 0) {
bits = initBits
maxpower = initMaxPowerFactor.power()
power = initPower
while (power != maxpower) {
resb = data.`val`.toInt() and data.position
data.position = data.position shr 1
if (data.position == 0) {
data.position = resetValue
data.`val` = getNextValue(data.index++)
}
bits = bits or (if (resb > 0) 1 else 0) * power
power = power shl 1
}
when (mode) {
0 -> Unit
1 -> c = bits.string //here just c is good
2 -> {
dictionary.add(dictSize++ , bits.string)
next = (dictSize - 1) //here should be next ,not c
enlargeIn--
}
}
}
already done. may check https://github.com/ZenLiuCN/lz-string4k