Add an extension function to limit the number of characters in a string. Dependency updates

This commit is contained in:
len
2016-11-19 14:46:49 +01:00
parent 1d014a5a94
commit 59c626b4a8
3 changed files with 22 additions and 12 deletions

View File

@@ -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
}