Skip to content

Commit

Permalink
add windows-1250 caseMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lopex committed Apr 19, 2018
1 parent 5c6a4d2 commit 0149fb1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/org/jcodings/specific/Windows_1250Encoding.java
Expand Up @@ -20,14 +20,58 @@
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_1250Encoding extends CaseFoldMapEncoding {

protected Windows_1250Encoding() {
super("Windows-1250", CP1250_CtypeTable, CP1250_ToLowerCaseTable, CP1250_CaseFoldMap, true);
}

@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 ((CP1250_CtypeTable[code] & CharacterType.BIT_UPPER) != 0 && (flags & (Config.CASE_DOWNCASE | Config.CASE_FOLD)) != 0) {
flags |= Config.CASE_MODIFIED;
code = LowerCaseTable[code];
} else if (code == 0xB5) {
} else if ((CP1250_CtypeTable[code] & CharacterType.BIT_LOWER) != 0 && (flags & Config.CASE_UPCASE) != 0) {
flags |= Config.CASE_MODIFIED;
if (code == 0xB9)
code = 0xA5;
else if (code == 0xBE)
code = 0xBC;
else if (code >= 0x8A && code <= 0xBF && code != 0xB9)
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 0149fb1

Please sign in to comment.