Commit e3d47d60 authored by Christophe Henry's avatar Christophe Henry

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

Change share regex to better detect separator tokens

See merge request !41
parents 2da65836 98f0d5ff
......@@ -15,18 +15,22 @@ object ChunkFilters {
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*${ChunkFilters.sepToken}+\\s*".toRegex())
.map { t ->
when {
t.isBlank() -> t
t.length == 1 -> t[0].toString().toUpperCase()
else -> "${t[0].toString().toUpperCase()}${t.substring(1).toLowerCase()}"
}
}
.forEach { t -> result = result.replace(t, t, ignoreCase = true) }
result
override fun transformObject(chunk: Chunk?, `object`: Any?, args: FilterArgs?) =
`object`.toString().let(::sentenceCap)
companion object {
fun sentenceCap(token: String): String {
var result = token
token.split("\\s+${ChunkFilters.sepToken}+\\s+".toRegex())
.map { t ->
when {
t.isBlank() -> t
t.length == 1 -> t[0].toString().toUpperCase()
else -> "${t[0].toString().toUpperCase()}${t.substring(1).toLowerCase()}"
}
}.forEach { t -> result = result.replace(t, t, ignoreCase = true) }
return result
}
}
}
......
package fr.chenry.android.freshrss.components.subscriptionarticles
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.ShareIntent
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.SentenceCapFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.StripFragmentFilter
import org.junit.Assert.assertEquals
import org.junit.Test
......@@ -27,6 +28,14 @@ class ShareIntentTest {
)
}
@Test
fun sentenceCapTest() {
val origin = "Comment la Glorieuse Révolution a-t-elle favorisé l'essor économique de l'Angleterre ?"
val expected = "Comment la glorieuse révolution a-t-elle favorisé l'essor économique de l'angleterre ?"
val result = SentenceCapFilter.sentenceCap(origin)
assertEquals(expected, result)
}
@Test
fun format() {
val expected = """
......
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