Stripaccents

This commit is contained in:
tzugen 2022-09-20 08:06:24 +02:00
parent c2a249f00e
commit 625bb670fe
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
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.imageloader.ImageLoader
import org.moire.ultrasonic.util.FileUtil import org.moire.ultrasonic.util.FileUtil
import org.moire.ultrasonic.util.Settings 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 * 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 if (name.isEmpty()) return SECTION_KEY_DEFAULT
val section = name.first().uppercaseChar() val section = name.first().uppercaseChar()
if (!section.isLetter()) return SECTION_KEY_DEFAULT if (!section.isLetter()) return SECTION_KEY_DEFAULT
return section.toString() return Util.stripAccents(section.toString())!!
} }
private fun showArtistPicture(): Boolean { private fun showArtistPicture(): Boolean {

View File

@ -46,8 +46,10 @@ import java.io.Closeable
import java.io.UnsupportedEncodingException import java.io.UnsupportedEncodingException
import java.security.MessageDigest import java.security.MessageDigest
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.Normalizer
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt 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( fun getPlayListFromTimeline(
timeline: Timeline?, timeline: Timeline?,
shuffle: Boolean, shuffle: Boolean,