All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.extensions.String.kt Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
package io.fluidsonic.stdlib


fun String.truncatedTo(maximumLength: Int, truncationSuffix: String = ""): String {
	require(maximumLength >= 0) { "maximumLength must be >= 0" }

	if (length <= maximumLength) {
		return this
	}
	if (maximumLength <= truncationSuffix.length) {
		return truncationSuffix.take(truncationSuffix.length)
	}

	return take(maximumLength - truncationSuffix.length) + truncationSuffix
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy