Skip to content

Commit 00be48a

Browse files
Merge pull request #57 from tea999/fix
solve string index out of bounds exception
2 parents f114519 + 7192fbe commit 00be48a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
8080
val lineCount = layout.lineCount
8181
for (i in 0 until lineCount) {
8282
val end = layout.getLineEnd(i)
83-
if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text[end - 1], text[end]))
83+
if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text[end - 1]))
8484
return 1
8585
if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
8686
maxWidth = layout.getLineRight(i).toInt() - layout.getLineLeft(i).toInt()
@@ -98,8 +98,8 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
9898
initialized = true
9999
}
100100

101-
fun isValidWordWrap(before: Char, after: Char): Boolean {
102-
return before == ' ' || before == '-'
101+
fun isValidWordWrap(c: Char): Boolean {
102+
return c == ' ' || c == '-'
103103
}
104104

105105
override fun setAllCaps(allCaps: Boolean) {

0 commit comments

Comments
 (0)