All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.snipme.highlights.internal.locator.AnnotationLocator.kt Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
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