Skip to content

Commit

Permalink
add iso8859-9 caseMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lopex committed Apr 18, 2018
1 parent 6f27648 commit e7f99c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/jcodings/specific/ISO8859_3Encoding.java
Expand Up @@ -62,7 +62,7 @@ else if ((ISO8859_3CtypeTable[code] & CharacterType.BIT_UPPER) != 0 && (flags &
} else if ((ISO8859_3CtypeTable[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 ? DOTLESS_i : '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) {
Expand Down
51 changes: 51 additions & 0 deletions src/org/jcodings/specific/ISO8859_9Encoding.java
Expand Up @@ -19,14 +19,65 @@
*/
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_9Encoding extends ISOEncoding {

protected ISO8859_9Encoding() {
super("ISO-8859-9", ISO8859_9CtypeTable, ISO8859_9ToLowerCaseTable, ISO8859_9CaseFoldMap);
}

static final int DOTLESS_i = 0xFD;
static final int I_WITH_DOT_ABOVE = 0xDD;

@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 (code == 0xAA || code == 0xB5 || code == 0xBA || code == 0xFF);
else if ((ISO8859_9CtypeTable[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 ((ISO8859_9CtypeTable[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 {
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_9CtypeTable[] = {
0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008,
Expand Down

0 comments on commit e7f99c8

Please sign in to comment.