Skip to content

Commit

Permalink
add windows-1257 caseMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lopex committed Apr 19, 2018
1 parent e6989a0 commit 3b27707
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/org/jcodings/specific/Windows_1257Encoding.java
Expand Up @@ -20,14 +20,65 @@
package org.jcodings.specific;

import org.jcodings.CaseFoldMapEncoding;
import org.jcodings.Config;
import org.jcodings.ISOEncoding;
import org.jcodings.IntHolder;
import org.jcodings.constants.CharacterType;

final public class Windows_1257Encoding extends CaseFoldMapEncoding {

protected Windows_1257Encoding() {
super("Windows-1257", CP1257_CtypeTable, CP1257_ToLowerCaseTable, CP1257_CaseFoldMap, true);
}

static final int DOTLESS_i = 0xB9;
static final int I_WITH_DOT_ABOVE = 0xA9;

@Override
public int caseMap(IntHolder flagP, byte[] bytes, IntHolder pp, int end, byte[] to, int toP, int toEnd) {
int toStart = toP;
int flags = flagP.value;

while (pp.value < end && toP < toEnd) {
int code = bytes[pp.value++] & 0xff;
if (code == ISOEncoding.SHARP_s) {
if ((flags & Config.CASE_UPCASE) != 0) {
flags |= Config.CASE_MODIFIED;
to[toP++] = 'S';
code = (flags & Config.CASE_TITLECASE) != 0 ? 's' : 'S';
} else if ((flags & Config.CASE_FOLD) != 0) {
flags |= Config.CASE_MODIFIED;
to[toP++] = 's';
code = 's';
}
} else if (code == 0xB5) {
} else if ((CP1257_CtypeTable[code] & CharacterType.BIT_UPPER) != 0 && (flags & (Config.CASE_DOWNCASE | Config.CASE_FOLD)) != 0) {
flags |= Config.CASE_MODIFIED;
if (code == 'I') {
code = (flags & Config.CASE_FOLD_TURKISH_AZERI) != 0 ? DOTLESS_i : 'i';
} else {
code = LowerCaseTable[code];
}
} else if ((CP1257_CtypeTable[code] & CharacterType.BIT_LOWER) != 0 && (flags & Config.CASE_UPCASE) != 0) {
flags |= Config.CASE_MODIFIED;
if (code == 'i') {
code = (flags & Config.CASE_FOLD_TURKISH_AZERI) != 0 ? I_WITH_DOT_ABOVE : 'I';
} else if (code == DOTLESS_i) {
code = 'I';
} else if (code >= 0xB0 && code <= 0xBF)
code -= 0x10;
else
code -= 0x20;
}
to[toP++] = (byte)code;
if ((flags & Config.CASE_TITLECASE) != 0) {
flags ^= (Config.CASE_UPCASE | Config.CASE_DOWNCASE | Config.CASE_TITLECASE);
}
}
flagP.value = flags;
return toP - toStart;
}

@Override
public int mbcCaseFold(int flag, byte[]bytes, IntHolder pp, int end, byte[]lower) {
int p = pp.value;
Expand Down

0 comments on commit 3b27707

Please sign in to comment.