Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Implemented an improved cleanPrefix method #5604

Merged
merged 5 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions composeApp/src/commonMain/kotlin/it/fast4x/rimusic/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ const val LOCAL_KEY_PREFIX = "local:"
const val YTP_PREFIX = "account:"
const val YTEDITABLEPLAYLIST_PREFIX = "editable:"

/**
* Assumption: all prefixes end with ":" and have at least 1 (other) character.
* Removes a "prefix of prefixes" including multiple times the same prefix (at different locations).
*/
fun cleanPrefix(text: String): String {
val cleanText = text.replace(PINNED_PREFIX, "", true)
.replace(MONTHLY_PREFIX, "", true)
.replace(PIPED_PREFIX, "", true)
.replace(YTEDITABLEPLAYLIST_PREFIX, "", true)
.replace(EXPLICIT_PREFIX, "", true)
.replace(MODIFIED_PREFIX, "", true)
.replace(YTP_PREFIX, "", true)


return cleanText
val splitText = text.split(":")
var i = 0
while (i < splitText.size-1) {
if ("${splitText[i]}:" !in listOf(PINNED_PREFIX, MODIFIED_PREFIX, MONTHLY_PREFIX, PIPED_PREFIX,
EXPLICIT_PREFIX, LOCAL_KEY_PREFIX, YTP_PREFIX, YTEDITABLEPLAYLIST_PREFIX)) {
break
}
i++
}
if(i >= splitText.size) return ""
return splitText.subList(i, splitText.size).joinToString(":")
}

fun cleanString(text: String): String {
Expand Down