fix ellipsize
This commit is contained in:
@@ -125,11 +125,30 @@ suspend fun GalleryInfo.getRequestBuilders(): List<Request.Builder> {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.ellipsize(n: Int): String =
|
||||
if (this.length > n)
|
||||
this.slice(0 until n) + "…"
|
||||
else
|
||||
this
|
||||
fun byteCount(codePoint: Int): Int = when (codePoint) {
|
||||
in 0 ..< 0x80 -> 1
|
||||
in 0x80 ..< 0x800 -> 2
|
||||
in 0x800 ..< 0x10000 -> 3
|
||||
in 0x10000 ..< 0x110000 -> 4
|
||||
else -> 0
|
||||
}
|
||||
|
||||
fun String.ellipsize(n: Int): String = buildString {
|
||||
var count = 0
|
||||
var index = 0
|
||||
val codePointLength = this.codePointCount(0, this.length)
|
||||
|
||||
while (index < codePointLength) {
|
||||
val next = this.codePointAt(index)
|
||||
if (count + next > 124) {
|
||||
append("…")
|
||||
break
|
||||
}
|
||||
appendCodePoint(next)
|
||||
count += next
|
||||
index++
|
||||
}
|
||||
}
|
||||
|
||||
operator fun JsonElement.get(index: Int) =
|
||||
this.jsonArray[index]
|
||||
|
||||
Reference in New Issue
Block a user