Commit e0e26ae2 authored by Christophe Henry's avatar Christophe Henry

Merge branch 'fix-share-formatting' into 'develop'

Fix slight bug in share formatting

See merge request christophehenry/freshrss-android!20
parents 0f9905e7 84881492
......@@ -23,7 +23,7 @@ object ShareIntent: Intent(Intent.ACTION_SEND) {
it.makeChunk().apply {append(defaultTemplate)}
}
private fun format(attributes: Map<String, String>) = template.apply {
fun format(attributes: Map<String, String>) = template.apply {
attributes.entries.forEach {(t, u) -> set(t, u)}
}.toString()
......
......@@ -7,15 +7,18 @@ import java.util.regex.Pattern
import kotlin.text.RegexOption.IGNORE_CASE
// Will match any separator token, i.e, any word not containing at least a letter or a number
const val sepToken = "[\\S&&[^\\p{L}]&&[^\\d]]"
object ChunkFilters {
private val excludedChars = listOf("'", ":")
// Will match any separator token, i.e, any word not containing at least a letter or a number
val sepToken = "[\\S&&[^\\p{L}]&&[^\\d]${excludedChars.joinToString(separator = "") {"&&[^$it]"}}]"
}
class SentenceCapFilter: ObjectFilter() {
override fun getFilterName() = "sentence_cap"
override fun transformObject(chunk: Chunk?, `object`: Any?, args: FilterArgs?) = `object`.toString().let {
var result = it
it.split("\\s*$sepToken+\\s*".toRegex())
it.split("\\s*${ChunkFilters.sepToken}+\\s*".toRegex())
.map {t ->
when {
t.isBlank() -> t
......@@ -48,10 +51,10 @@ class StripFragmentFilter: ObjectFilter() {
fun stripFragment(title: String, author: String): String {
return when {
// Case where author is in the middle of the title, for instance: "Video series #1 | Author | Title"
title.contains("\\s*$sepToken+\\s*${Pattern.quote(author)}\\s*$sepToken+\\s*".toRegex()) ->
"\\s*$sepToken*\\s*${Pattern.quote(author)}".toRegex(IGNORE_CASE).replace(title, "")
title.contains("\\s*${ChunkFilters.sepToken}+\\s*${Pattern.quote(author)}\\s*${ChunkFilters.sepToken}+\\s*".toRegex()) ->
"\\s*${ChunkFilters.sepToken}*\\s*${Pattern.quote(author)}".toRegex(IGNORE_CASE).replace(title, "")
else ->
"\\s*$sepToken*\\s*${Pattern.quote(author)}\\s*$sepToken*\\s*".toRegex(IGNORE_CASE).replace(title, "")
"\\s*${ChunkFilters.sepToken}*\\s*${Pattern.quote(author)}\\s*${ChunkFilters.sepToken}*\\s*".toRegex(IGNORE_CASE).replace(title, "")
}
}
}
......
......@@ -29,12 +29,11 @@ class ShareIntentTest {
@Test
fun format() {
assertEquals(
ShareIntent.format(attributes), """
val expected = """
|My title - My series #1 - This is awesome! — The Subscription
|http://example.com
""".trimMargin("|")
)
assertEquals(expected, ShareIntent.format(attributes))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment