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

com.jtransc.charset.charsets.JTranscCharsetUTF16Base Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package com.jtransc.charset.charsets;

import com.jtransc.JTranscBits;

import java.io.ByteArrayOutputStream;
import com.jtransc.charset.JTranscCharset;

abstract class JTranscCharsetUTF16Base extends JTranscCharset {
	private String[] aliases;
	private boolean littleEndian;

	public JTranscCharsetUTF16Base(String[] names, boolean littleEndian) {
		super(names, 2, 2 ,2);
		this.littleEndian = littleEndian;
	}

	@Override
	public void encode(char[] in, int offset, int len, ByteArrayOutputStream out) {
		for (int n = 0; n < len; n++) {
			char c = in[offset + n];
			if (littleEndian) {
				out.write((c >>> 0) & 0xFF);
				out.write((c >>> 8) & 0xFF);
			} else {
				out.write((c >>> 8) & 0xFF);
				out.write((c >>> 0) & 0xFF);
			}
		}
	}

	@Override
	public void decode(byte[] in, int offset, int len, StringBuilder out) {
		for (int n = 0; n < len; n += 2) {
			out.append((char)JTranscBits.readInt16(in, offset + n, littleEndian));
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy