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

commonMain.ru.casperix.multiplatform.text.impl.TextDirectionSolver.kt Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package ru.casperix.multiplatform.text.impl

/**
 * TODO: For js see "Intl.Segmenter"
 */
object TextDirectionSolver {
    private val arabic = ('\u0600'..'\u06FF').iterator().asSequence().toList().toSet()
    private val persian = ('\u0600'..'\u06FF').iterator().asSequence().toList().toSet()
    private val hebrew = ('\u0590'..'\u05FF').iterator().asSequence().toList().toSet()
    private val sindhi = ('\u0AE0'..'\u0AEF').iterator().asSequence().toList().toSet()
    private val urdu = ('\u067E'..'\u06DF').iterator().asSequence().toList().toSet()

    private val rightDirectionChars: Set = arabic + persian + hebrew + sindhi + urdu
    private val leftDirectionsChars: Set = emptySet()

    fun isLeftToRight(line: String): Boolean {
        line.forEach {
            if (it.isLetter()) {
                if (leftDirectionsChars.contains(it)) return true
                if (rightDirectionChars.contains(it)) return false
            }
        }
        return true
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy