Merge branch 'stripAccents' into 'develop'

Stripaccents

Closes #816

See merge request ultrasonic/ultrasonic!845
This commit is contained in:
Nite 2022-10-04 16:14:08 +00:00
commit 6f54e99409
2 changed files with 35 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import org.moire.ultrasonic.domain.Identifiable
import org.moire.ultrasonic.imageloader.ImageLoader
import org.moire.ultrasonic.util.FileUtil
import org.moire.ultrasonic.util.Settings
import org.moire.ultrasonic.util.Util
/**
* Creates a Row in a RecyclerView which contains the details of an Artist
@ -106,7 +107,7 @@ class ArtistRowBinder(
if (name.isEmpty()) return SECTION_KEY_DEFAULT
val section = name.first().uppercaseChar()
if (!section.isLetter()) return SECTION_KEY_DEFAULT
return section.toString()
return Util.stripAccents(section.toString())!!
}
private fun showArtistPicture(): Boolean {

View File

@ -46,8 +46,10 @@ import java.io.Closeable
import java.io.UnsupportedEncodingException
import java.security.MessageDigest
import java.text.DecimalFormat
import java.text.Normalizer
import java.util.Locale
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
@ -670,6 +672,37 @@ object Util {
)
}
/**
* Removes diacritics (~= accents) from a string. The case will not be altered.
* Note that ligatures will be left as is.
*
* @param input String to be stripped
* @return input text with diacritics removed
*
*/
fun stripAccents(input: String): String {
val decomposed: java.lang.StringBuilder =
java.lang.StringBuilder(Normalizer.normalize(input, Normalizer.Form.NFD))
convertRemainingAccentCharacters(decomposed)
return STRIP_ACCENTS_PATTERN.matcher(decomposed).replaceAll("")
}
/**
* Pattern used in [.stripAccents].
*/
private val STRIP_ACCENTS_PATTERN: Pattern =
Pattern.compile("\\p{InCombiningDiacriticalMarks}+") // $NON-NLS-1$
private fun convertRemainingAccentCharacters(decomposed: java.lang.StringBuilder) {
for (i in decomposed.indices) {
if (decomposed[i] == '\u0141') {
decomposed.setCharAt(i, 'L')
} else if (decomposed[i] == '\u0142') {
decomposed.setCharAt(i, 'l')
}
}
}
fun getPlayListFromTimeline(
timeline: Timeline?,
shuffle: Boolean,