mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-06-09 03:52:12 +03:00
Stripaccents
This commit is contained in:
parent
c2a249f00e
commit
625bb670fe
@ -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 {
|
||||||
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user