Skip to content

Commit

Permalink
Fix crash by using special characters using find
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Jul 3, 2024
1 parent fbf2fc9 commit e2adc7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/hamza.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/assets/html/changelogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h4>Bug Fixes</h4>
<li>Fixed crashing on resizing app screen on Android desktop environments.</li>
<li>Fixed crashing on reading faulty apps info for <i>Info Strip</i>.</li>
<li>Fixed crashes caused by mismatching panel IDs.</li>
<li>Fixed crash casued by using special characters when using <i>find</i> in XML files.</li>
<li>Fixed some minor issues.</li>
</ul>

Expand Down
31 changes: 21 additions & 10 deletions app/src/main/java/app/simple/inure/text/EditTextHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import android.os.Build
import android.text.Layout
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.*
import android.text.style.AbsoluteSizeSpan
import android.text.style.AlignmentSpan
import android.text.style.BackgroundColorSpan
import android.text.style.BulletSpan
import android.text.style.MaskFilterSpan
import android.text.style.QuoteSpan
import android.text.style.RelativeSizeSpan
import android.text.style.StrikethroughSpan
import android.text.style.StyleSpan
import android.text.style.SubscriptSpan
import android.text.style.SuperscriptSpan
import android.text.style.UnderlineSpan
import android.widget.EditText
import androidx.core.text.toSpannable
import app.simple.inure.preferences.AppearancePreferences
import app.simple.inure.util.ConditionUtils.invert
import java.util.*
import java.util.Locale
import java.util.Objects
import kotlin.math.roundToInt

object EditTextHelper {
Expand Down Expand Up @@ -562,16 +573,16 @@ object EditTextHelper {
}

fun EditText.findMatches(searchKeyword: String): ArrayList<Pair<Int, Int>> {
val pattern = searchKeyword.lowercase().toRegex()
val matcher = pattern.toPattern().matcher(text.toString().lowercase(Locale.getDefault()).toSpannable())
val lowerCaseText = text.toString().lowercase(Locale.getDefault())
val lowerCaseKeyword = searchKeyword.lowercase()
val list = ArrayList<Pair<Int, Int>>()

if (searchKeyword.isNotEmpty()) {
while (matcher.find()) {
list.add(Pair(matcher.start(), matcher.end()))
}
var index = lowerCaseText.indexOf(lowerCaseKeyword)
while (index >= 0) {
list.add(Pair(index, index + lowerCaseKeyword.length))
index = lowerCaseText.indexOf(lowerCaseKeyword, index + 1)
}

return list
}
}
}

0 comments on commit e2adc7b

Please sign in to comment.