Skip to content

Commit

Permalink
add iso8859-14 caseMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lopex committed Apr 18, 2018
1 parent 89650fb commit 4136a05
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/org/jcodings/specific/ISO8859_14Encoding.java
Expand Up @@ -19,14 +19,63 @@
*/
package org.jcodings.specific;

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

public final class ISO8859_14Encoding extends ISOEncoding {

protected ISO8859_14Encoding() {
super("ISO-8859-14", ISO8859_14CtypeTable, ISO8859_14ToLowerCaseTable, ISO8859_14CaseFoldMap);
}

@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 == 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 ((ISO8859_14CtypeTable[code] & CharacterType.BIT_UPPER) != 0 && (flags & (Config.CASE_DOWNCASE | Config.CASE_FOLD)) != 0) {
flags |= Config.CASE_MODIFIED;
code = LowerCaseTable[code];
} else if ((ISO8859_14CtypeTable[code] & CharacterType.BIT_LOWER) != 0 && (flags & Config.CASE_UPCASE) != 0) {
flags |= Config.CASE_MODIFIED;
if (code == 0xA2 || code == 0xA5 || code == 0xB1 || code == 0xB3 || code == 0xB5 || code == 0xBE)
code -= 0x1;
else if (code == 0xAB)
code -= 0x5;
else if (code == 0xFF)
code -= 0x50;
else if (code == 0xB9)
code -= 0x2;
else if (code == 0xBF)
code -= 0x4;
else if (code == 0xB8 || code == 0xBA || code == 0xBC)
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;
}

static final short ISO8859_14CtypeTable[] = {
0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008,
Expand Down

0 comments on commit 4136a05

Please sign in to comment.