Flatten packages
Remove modules prefix
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package be.simplenotes.domain.usecases.search
|
||||
|
||||
import be.simplenotes.search.SearchTerms
|
||||
|
||||
private fun innerRegex(name: String) =
|
||||
"""$name:['"](.*?)['"]""".toRegex()
|
||||
private fun outerRegex(name: String) =
|
||||
"""($name:['"].*?['"])""".toRegex()
|
||||
|
||||
private val titleRe = innerRegex("title")
|
||||
private val outerTitleRe = outerRegex("title")
|
||||
|
||||
private val tagRe = innerRegex("tag")
|
||||
private val outerTagRe = outerRegex("tag")
|
||||
|
||||
private val contentRe = innerRegex("content")
|
||||
private val outerContentRe = outerRegex("content")
|
||||
|
||||
internal fun parseSearchTerms(input: String): SearchTerms {
|
||||
var c: String = input
|
||||
|
||||
fun extract(innerRegex: Regex, outerRegex: Regex): String? {
|
||||
val match = innerRegex.find(input)?.groups?.get(1)?.value
|
||||
if (match != null) {
|
||||
val group = outerRegex.find(input)?.groups?.get(1)?.value
|
||||
group?.let { c = c.replace(it, "") }
|
||||
}
|
||||
return match
|
||||
}
|
||||
|
||||
val title: String? = extract(titleRe, outerTitleRe)
|
||||
val tag: String? = extract(tagRe, outerTagRe)
|
||||
val content: String? = extract(contentRe, outerContentRe)
|
||||
|
||||
val all = c.trim().ifEmpty { null }
|
||||
|
||||
return SearchTerms(
|
||||
title = title,
|
||||
tag = tag,
|
||||
content = content,
|
||||
all = all
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user