
commonMain.dev.snipme.highlights.internal.locator.AnnotationLocator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of highlights Show documentation
Show all versions of highlights Show documentation
Kotlin Multiplatform syntax highlighting engine.
package dev.snipme.highlights.internal.locator
import dev.snipme.highlights.model.PhraseLocation
import dev.snipme.highlights.internal.SyntaxTokens.TOKEN_DELIMITERS
import dev.snipme.highlights.internal.indicesOf
internal object AnnotationLocator {
fun locate(code: String): Set {
val foundAnnotations = emptyList()
val locations = mutableSetOf()
code.split(*TOKEN_DELIMITERS.toTypedArray())
.asSequence()
.filter { it.isNotEmpty() }
.filter { foundAnnotations.contains(it).not() }
.filter { it.contains('@') }
.forEach { annotation ->
code.indicesOf(annotation).forEach { phraseStartIndex ->
val symbolLocation = annotation.indexOf('@')
val startIndex = phraseStartIndex + symbolLocation
locations.add(
PhraseLocation(
startIndex,
startIndex + annotation.length - symbolLocation
)
)
}
}
return locations.toSet()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy