mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Add an extension function to limit the number of characters in a string. Dependency updates
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package eu.kanade.tachiyomi.util
|
||||
|
||||
/**
|
||||
* Replaces the given string to have at most [count] characters using [replacement] at its end.
|
||||
* If [replacement] is longer than [count] an exception will be thrown when `length > count`.
|
||||
*/
|
||||
fun String.chop(count: Int, replacement: String = "..."): String {
|
||||
return if (length > count)
|
||||
take(count - replacement.length) + replacement
|
||||
else
|
||||
this
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user