Skip to content

Commit

Permalink
fix(common): handle empty groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Irineu333 committed Nov 20, 2024
1 parent 6994dbb commit 0ddbb82
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/extension/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ val config = Config(
major = 2,
minor = 2,
patch = 0,
release = Config.Release.Candidate()
release = Config.Release.Candidate(number = 2)
),
android = Config.Android(
compileSdk = 34,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ actual fun String.matchAll(
add(
Match(
text = match.value,
groups = match.groups.mapNotNull {
groups = match.groups.map {

if (it == null) return@mapNotNull null
if (it == null) return@map null

Match.Group(
text = it.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ fun Highlight.toAnnotatedString(text: String): AnnotatedString {

for ((index, group) in result.groups.withIndex()) {

if (group == null) continue

spanStyles.add(
AnnotatedString.Range(
item = spans.getOrNull(index) ?: continue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.neoutils.highlight.compose.extension

data class Match(
val text: String,
val groups: List<Group>
val groups: List<Group?>
) {
data class Group(
val text: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ actual fun String.matchAll(
Match(
text = match.toString(),
groups = buildList {
groupsWithIndex.forEach { (index, it) ->
val range = indices[index].unsafeCast<IntArray>()
groupsWithIndex.forEach { (index, group) ->
val range = indices[index]?.unsafeCast<IntArray>()

add(
Match.Group(
text = it.toString(),
range = range.toRange()
)
range?.let {
Match.Group(
text = group.unsafeCast<String>(),
range = range.toRange()
)
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ actual fun String.matchAll(
add(
Match(
text = match.value,
groups = match.groups.mapNotNull {
groups = match.groups.map {

if (it == null) return@mapNotNull null
if (it == null) return@map null

Match.Group(
text = it.value,
Expand Down

0 comments on commit 0ddbb82

Please sign in to comment.