music: trim simple names after punct removal

Trim simple names once punctuation has been removed.

This prevents situations where album names like "& Yet & Yet" (a real
album by post-rock outfit Do Make Say Think) will have blank thumbs.
This probably isn't the best approach in general, but nothing about the
intelligent name system is a good approach.
This commit is contained in:
Alexander Capehart
2023-08-18 11:47:50 -06:00
parent 5cd46193d5
commit 2c2bd79ae2
3 changed files with 11 additions and 119 deletions
@@ -148,6 +148,8 @@ sealed interface Name : Comparable<Name> {
private val collator: Collator = Collator.getInstance().apply { strength = Collator.PRIMARY }
private val punctRegex by lazy { Regex("[\\p{Punct}+]") }
// TODO: Consider how you want to handle whitespace and "gaps" in names.
/**
* Plain [Name.Known] implementation that is internationalization-safe.
*
@@ -159,7 +161,7 @@ private data class SimpleKnownName(override val raw: String, override val sort:
private fun parseToken(name: String): SortToken {
// Remove excess punctuation from the string, as those usually aren't considered in sorting.
val stripped = name.replace(punctRegex, "").ifEmpty { name }
val stripped = name.replace(punctRegex, "").trim().ifEmpty { name }
val collationKey = collator.getCollationKey(stripped)
// Always use lexicographic mode since we aren't parsing any numeric components
return SortToken(collationKey, SortToken.Type.LEXICOGRAPHIC)
@@ -180,7 +182,8 @@ private data class IntelligentKnownName(override val raw: String, override val s
// optimize it
val stripped =
name
// Remove excess punctuation from the string, as those u
// Remove excess punctuation from the string, as those usually aren't
// considered in sorting.
.replace(punctRegex, "")
.ifEmpty { name }
.run {