jsMain.kotlinx.io.charsets.ISO88591.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-io-js Show documentation
Show all versions of kotlinx-io-js Show documentation
IO support libraries for Kotlin
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