Skip to content

Commit

Permalink
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/org/jcodings/ISOEncoding.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
package org.jcodings;

public abstract class ISOEncoding extends CaseFoldMapEncoding {
public static int SHARP_s = 0xdf;

protected ISOEncoding(String name, short[]CTypeTable, byte[]LowerCaseTable, int[][]CaseFoldMap) {
this(name, CTypeTable, LowerCaseTable, CaseFoldMap, true);
37 changes: 37 additions & 0 deletions src/org/jcodings/specific/ISO8859_1Encoding.java
Original file line number Diff line number Diff line change
@@ -21,7 +21,10 @@

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

public final class ISO8859_1Encoding extends ISOEncoding {

@@ -85,6 +88,40 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
return EMPTY_FOLD_CODES;
}

@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_1CtypeTable[code] & CharacterType.BIT_UPPER) != 0 && (flags & (Config.CASE_DOWNCASE | Config.CASE_FOLD)) != 0) {
flags |= Config.CASE_MODIFIED;
code += 0x20;
} else if (code == 0xAA || code == 0xBA || code == 0xB5 || code == 0xFF) {
} else if ((ISO8859_1CtypeTable[code] & CharacterType.BIT_LOWER) != 0 && (flags & Config.CASE_UPCASE) != 0) {
flags |= Config.CASE_MODIFIED;
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_1CtypeTable[] = {
0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008,

0 comments on commit fb25693

Please sign in to comment.