package org.jcodings.specific;
import org.jcodings.Config;
import org.jcodings.IntHolder;
import org.jcodings.ascii.AsciiTables;
import org.jcodings.unicode.FixedWidthUnicodeEncoding;
public final class UTF32BEEncoding extends FixedWidthUnicodeEncoding {
protected UTF32BEEncoding() {
super("UTF-32BE", 4);
}
@Override
public boolean isNewLine(byte[]bytes, int p, int end) {
if (p + 3 < end) {
if (bytes[p + 3] == (byte)0x0a && bytes[p + 2] == 0 && bytes[p + 1] == 0 && bytes[p] == 0) return true;
if (Config.USE_UNICODE_ALL_LINE_TERMINATORS) {
if ((Config.USE_CRNL_AS_LINE_TERMINATOR && bytes[p + 3] == (byte)0x0d) ||
bytes[p + 3] == (byte)0x85 && bytes[p + 2] == 0 && bytes[p + 1] == 0 && bytes[p] == 0) return true;
if (bytes[p + 2] == (byte)0x20 &&
(bytes[p + 3] == (byte)0x29 || bytes[p + 3] == (byte)0x28) &&
bytes[p + 1] == 0 && bytes[p] == 0) return true;
}
}
return false;
}
@Override
public int mbcToCode(byte[]bytes, int p, int end) {
return (((bytes[p] & 0xff) * 256 + (bytes[p + 1] & 0xff)) * 256 + (bytes[p + 2] & 0xff)) * 256 + (bytes[p + 3] & 0xff);
}
@Override
public int codeToMbc(int code, byte[]bytes, int p) {
int p_ = p;
bytes[p_++] = (byte)((code & 0xff000000) >>> 24);
bytes[p_++] = (byte)((code & 0xff0000) >>> 16);
bytes[p_++] = (byte)((code & 0xff00) >>> 8);
bytes[p_++] = (byte) (code & 0xff);
return 4;
}
@Override
public int mbcCaseFold(int flag, byte[]bytes, IntHolder pp, int end, byte[]fold) {
int p = pp.value;
int foldP = 0;
if (isAscii(bytes[p + 3] & 0xff) && bytes[p + 2] == 0 && bytes[p + 1] == 0 && bytes[p] == 0) {
fold[foldP++] = 0;
fold[foldP++] = 0;
if (Config.USE_UNICODE_CASE_FOLD_TURKISH_AZERI) {
if ((flag & Config.CASE_FOLD_TURKISH_AZERI) != 0) {
if (bytes[p + 3] == (byte)0x49) {
fold[foldP++] = (byte)0x01;
fold[foldP] = (byte)0x31;
pp.value += 4;
return 4;
}
}
}
fold[foldP++] = 0;
fold[foldP] = AsciiTables.ToLowerCaseTable[bytes[p + 3] & 0xff];
pp.value += 4;
return 4;
} else {
return super.mbcCaseFold(flag, bytes, pp, end, fold);
}
}
public static UTF32BEEncoding INSTANCE = new UTF32BEEncoding();
}