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

jsMain.kotlinx.io.charsets.ISO88591.kt Maven / Gradle / Ivy

There is a newer version: 0.1.16
Show newest version
package kotlinx.io.charsets

import kotlinx.io.core.*
import org.khronos.webgl.*

internal fun encodeISO88591(input: CharSequence, fromIndex: Int, toIndex: Int, dst: IoBuffer): Int {
    if (fromIndex >= toIndex) return 0

    dst.writeDirect { view ->
        val i8 = Int8Array(view.buffer, view.byteOffset, view.byteLength)
        var writeIndex = 0
        for (index in fromIndex until toIndex) {
            val character = input[index].toInt()
            if (character > 0xff) {
                failedToMapError(character)
            }
            i8[writeIndex++] = character.toByte()
        }
        writeIndex
    }
    return toIndex - fromIndex
}

private fun failedToMapError(ch: Int): Nothing {
    throw MalformedInputException("The character with unicode point $ch couldn't be mapped to ISO-8859-1 character" )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy