Updated on 2026-08-14

This commit is contained in:
Tangem 2023-04-19 20:12:05 +03:00
parent 9b6100c09c
commit 282772a0fc

View file

@ -4,9 +4,13 @@ import com.tangem.utils.extensions.isNotWhitespace
/**
[REDACTED_AUTHOR]
* Class which provides helper functions to determine lead or last part of words for suggestions
*/
internal class PartWordFinder {
/**
* Searches and return part of a word on the left side of the [cursorPosition] into the [text]
*/
fun getLeadPartOfWord(text: String, cursorPosition: Int): String? {
val charText = text.toCharArray().asList()
if (cursorPosition > charText.size || cursorPosition < 0) {
@ -41,6 +45,10 @@ internal class PartWordFinder {
return null
}
/**
* Returns a substring of the [word] which excludes the first word part found on the left of [cursorPosition] in
* the [text]
*/
fun getLastPartOfWord(text: String, word: String, cursorPosition: Int): String {
val leadPart = getLeadPartOfWord(text, cursorPosition) ?: return ""