mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
add trim to #162 so " " behavior stays same.
This commit is contained in:
parent
8a1385710d
commit
c1cbf1e916
1 changed files with 4 additions and 3 deletions
|
|
@ -20,17 +20,18 @@ import com.geeksville.mesh.service.MeshService
|
|||
/// that user. If the original name is only one word, strip vowels from the original name and if the result is
|
||||
/// 3 or more characters, use the first three characters. If not, just take the first 3 characters of the
|
||||
/// original name.
|
||||
fun getInitials(name: String): String {
|
||||
fun getInitials(nameIn: String): String {
|
||||
val nchars = 3
|
||||
val minchars = 2
|
||||
val name = nameIn.trim()
|
||||
val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||
|
||||
val initials = when (words.size) {
|
||||
in 0..minchars-1 -> {
|
||||
in 0..minchars - 1 -> {
|
||||
val nm = name.filterNot { c -> c.toLowerCase() in "aeiou" }
|
||||
if (nm.length >= nchars) nm else name
|
||||
}
|
||||
else -> words.map{ it.first() }.joinToString("")
|
||||
else -> words.map { it.first() }.joinToString("")
|
||||
}
|
||||
return initials.take(nchars)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue