Improve Cp1252Charset.contains()

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent 2525501901
commit eef8fc1f0c
  1. 10
      util/src/main/java/dev/openrs2/util/charset/Cp1252Charset.kt

@ -6,10 +6,8 @@ import java.nio.charset.Charset
import java.nio.charset.CharsetDecoder import java.nio.charset.CharsetDecoder
import java.nio.charset.CharsetEncoder import java.nio.charset.CharsetEncoder
import java.nio.charset.CoderResult import java.nio.charset.CoderResult
import java.nio.charset.StandardCharsets
object Cp1252Charset : Charset("Cp1252", null) { object Cp1252Charset : Charset("Cp1252", null) {
private val ASCII_CHARSET = StandardCharsets.US_ASCII.javaClass
private val CODE_PAGE = charArrayOf( private val CODE_PAGE = charArrayOf(
'\u20AC', '\u0000', '\u201A', '\u0192', '\u201E', '\u2026', '\u2020', '\u2021', '\u20AC', '\u0000', '\u201A', '\u0192', '\u201E', '\u2026', '\u2020', '\u2021',
'\u02C6', '\u2030', '\u0160', '\u2039', '\u0152', '\u0000', '\u017D', '\u0000', '\u02C6', '\u2030', '\u0160', '\u2039', '\u0152', '\u0000', '\u017D', '\u0000',
@ -55,15 +53,11 @@ object Cp1252Charset : Charset("Cp1252", null) {
} }
override fun contains(cs: Charset): Boolean { override fun contains(cs: Charset): Boolean {
return ASCII_CHARSET.isInstance(cs) || cs is Cp1252Charset return Charsets.US_ASCII.contains(cs) || cs is Cp1252Charset
} }
override fun newEncoder(): CharsetEncoder { override fun newEncoder(): CharsetEncoder {
return object : CharsetEncoder(this, 1F, 1F) { return object : CharsetEncoder(this, 1F, 1F, byteArrayOf(REPLACEMENT_BYTE)) {
init {
replaceWith(byteArrayOf(REPLACEMENT_BYTE))
}
override fun encodeLoop(input: CharBuffer, output: ByteBuffer): CoderResult { override fun encodeLoop(input: CharBuffer, output: ByteBuffer): CoderResult {
while (input.hasRemaining()) { while (input.hasRemaining()) {
if (!output.hasRemaining()) { if (!output.hasRemaining()) {

Loading…
Cancel
Save