Skip to content

Commit

Permalink
add windows-1252 caseMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lopex committed Apr 19, 2018
1 parent e296af2 commit bf2a941
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/org/jcodings/specific/Windows_1252Encoding.java
Expand Up @@ -20,14 +20,56 @@
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_1252Encoding extends CaseFoldMapEncoding {

protected Windows_1252Encoding() {
super("Windows-1252", CP1252_CtypeTable, CP1252_ToLowerCaseTable, CP1252_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 ((CP1252_CtypeTable[code] & CharacterType.BIT_UPPER) != 0 && (flags & (Config.CASE_DOWNCASE | Config.CASE_FOLD)) != 0) {
flags |= Config.CASE_MODIFIED;
code = LowerCaseTable[code];
} else if (code == 0x83 || code == 0xAA || code == 0xBA || code == 0xB5) {
} else if ((CP1252_CtypeTable[code] & CharacterType.BIT_LOWER) != 0 && (flags & Config.CASE_UPCASE) != 0) {
flags |= Config.CASE_MODIFIED;
if (code == 0x9A || code == 0x9C || code == 0x9E)
code -= 0x10;
else if (code == 0xFF)
code -= 0x60;
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 bf2a941

Please sign in to comment.