Skip to content

Commit

Permalink
Showing 5 changed files with 51 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/org/jcodings/AbstractEncoding.java
Original file line number Diff line number Diff line change
@@ -90,9 +90,9 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
int b = bytes[p] & 0xff;

if (0x41 <= b && b <= 0x5a) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{b + 0x20})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, b + 0x20)};
} else if (0x61 <= b && b <= 0x7a) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{b - 0x20})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, b - 0x20)};
} else {
return EMPTY_FOLD_CODES;
}
20 changes: 14 additions & 6 deletions src/org/jcodings/CaseFoldCodeItem.java
Original file line number Diff line number Diff line change
@@ -19,16 +19,24 @@
*/
package org.jcodings;

public class CaseFoldCodeItem {
static final int ENC_MAX_COMP_CASE_FOLD_CODE_LEN = 3;

public final class CaseFoldCodeItem {
public final int byteLen;
public final int codeLen;
public final int code[];

public CaseFoldCodeItem(int byteLen, int codeLen, int[]code) {
private CaseFoldCodeItem(int byteLen, int[]code) {
this.byteLen = byteLen;
this.codeLen = codeLen;
this.code = code;
}

public static CaseFoldCodeItem create(int byteLen, int code1) {
return new CaseFoldCodeItem(byteLen, new int[] {code1});
}

public static CaseFoldCodeItem create(int byteLen, int code1, int code2) {
return new CaseFoldCodeItem(byteLen, new int[] {code1, code2});
}

public static CaseFoldCodeItem create(int byteLen, int code1, int code2, int code3) {
return new CaseFoldCodeItem(byteLen, new int[] {code1, code2, code3});
}
}
20 changes: 10 additions & 10 deletions src/org/jcodings/CaseFoldMapEncoding.java
Original file line number Diff line number Diff line change
@@ -70,39 +70,39 @@ private void ssApplyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object a
int b = bytes[p] & 0xff;

if (0x41 <= b && b <= 0x5a) {
CaseFoldCodeItem item0 = new CaseFoldCodeItem(1, 1, new int[]{b + 0x20});
CaseFoldCodeItem item0 = CaseFoldCodeItem.create(1, b + 0x20);

if (b == 0x53 && essTsettFlag && end > p + 1 &&
(bytes[p+1] == (byte)0x53 || bytes[p+1] == (byte)0x73)) { /* SS */
CaseFoldCodeItem item1 = new CaseFoldCodeItem(2, 1, new int[]{0xdf});
CaseFoldCodeItem item1 = CaseFoldCodeItem.create(2, 0xdf);
return new CaseFoldCodeItem[]{item0, item1};
} else {
return new CaseFoldCodeItem[]{item0};
}
} else if (0x61 <= b && b <= 0x7a) {
CaseFoldCodeItem item0 = new CaseFoldCodeItem(1, 1, new int[]{b - 0x20});
CaseFoldCodeItem item0 = CaseFoldCodeItem.create(1, b - 0x20);

if (b == 0x73 && essTsettFlag && end >p + 1 &&
(bytes[p+1] == (byte)0x73 || bytes[p+1] == (byte)0x53)) { /* ss */
CaseFoldCodeItem item1 = new CaseFoldCodeItem(2, 1, new int[]{0xdf});
CaseFoldCodeItem item1 = CaseFoldCodeItem.create(2, 0xdf);

return new CaseFoldCodeItem[]{item0, item1};
} else {
return new CaseFoldCodeItem[]{item0};
}
} else if (b == 0xdf && essTsettFlag) {
CaseFoldCodeItem item0 = new CaseFoldCodeItem(1, 2, new int[]{'s', 's'});
CaseFoldCodeItem item1 = new CaseFoldCodeItem(1, 2, new int[]{'S', 'S'});
CaseFoldCodeItem item2 = new CaseFoldCodeItem(1, 2, new int[]{'s', 'S'});
CaseFoldCodeItem item3 = new CaseFoldCodeItem(1, 2, new int[]{'S', 's'});
CaseFoldCodeItem item0 = CaseFoldCodeItem.create(1, 's', 's');
CaseFoldCodeItem item1 = CaseFoldCodeItem.create(1, 'S', 'S');
CaseFoldCodeItem item2 = CaseFoldCodeItem.create(1, 's', 'S');
CaseFoldCodeItem item3 = CaseFoldCodeItem.create(1, 'S', 's');

return new CaseFoldCodeItem[]{item0, item1, item2, item3};
} else {
for (int i=0; i<mapSize; i++) {
if (b == map[i][0]) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{map[i][1]})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, map[i][1])};
} else if (b == map[i][1]) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{map[i][0]})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, map[i][0])};
}
}
}
24 changes: 12 additions & 12 deletions src/org/jcodings/specific/ISO8859_1Encoding.java
Original file line number Diff line number Diff line change
@@ -44,45 +44,45 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
int b = bytes[p] & 0xff;

if (0x41 <= b && b <= 0x5a) {
CaseFoldCodeItem item0 = new CaseFoldCodeItem(1, 1, new int[]{b + 0x20});
CaseFoldCodeItem item0 = CaseFoldCodeItem.create(1, b + 0x20);

if (b == 0x53 && end > p + 1 &&
(bytes[p+1] == (byte)0x53 || bytes[p+1] == (byte)0x73)) { /* ss */
CaseFoldCodeItem item1 = new CaseFoldCodeItem(2, 1, new int[]{SHARP_s});
CaseFoldCodeItem item1 = CaseFoldCodeItem.create(2, SHARP_s);

return new CaseFoldCodeItem[]{item0, item1};
} else {
return new CaseFoldCodeItem[]{item0};
}
} else if (0x61 <= b && b <= 0x7a) {
CaseFoldCodeItem item0 = new CaseFoldCodeItem(1, 1, new int[]{b - 0x20});
CaseFoldCodeItem item0 = CaseFoldCodeItem.create(1, b - 0x20);

if (b == 0x73 && end > p + 1 &&
(bytes[p+1] == (byte)0x73 || bytes[p+1] == (byte)0x53)) { /* ss */
CaseFoldCodeItem item1 = new CaseFoldCodeItem(2, 1, new int[]{SHARP_s});
CaseFoldCodeItem item1 = CaseFoldCodeItem.create(2, SHARP_s);
return new CaseFoldCodeItem[]{item0, item1};
} else {
return new CaseFoldCodeItem[]{item0};
}

} else if (0xc0 <= b && b <= 0xcf) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{b + 0x20})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, b + 0x20)};
} else if (0xd0 <= b && b <= SHARP_s) {
if (b == SHARP_s) {
CaseFoldCodeItem item0 = new CaseFoldCodeItem(1, 2, new int[]{'s', 's'});
CaseFoldCodeItem item1 = new CaseFoldCodeItem(1, 2, new int[]{'S', 'S'});
CaseFoldCodeItem item2 = new CaseFoldCodeItem(1, 2, new int[]{'s', 'S'});
CaseFoldCodeItem item3 = new CaseFoldCodeItem(1, 2, new int[]{'S', 's'});
CaseFoldCodeItem item0 = CaseFoldCodeItem.create(1, 's', 's');
CaseFoldCodeItem item1 = CaseFoldCodeItem.create(1, 'S', 'S');
CaseFoldCodeItem item2 = CaseFoldCodeItem.create(1, 's', 'S');
CaseFoldCodeItem item3 = CaseFoldCodeItem.create(1, 'S', 's');

return new CaseFoldCodeItem[]{item0, item1, item2, item3};
} else if (b != 0xd7) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{b + 0x20})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, b + 0x20)};
}
} else if (0xe0 <= b && b <= 0xef) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{b - 0x20})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, b - 0x20)};
} else if (0xf0 <= b && b <= 0xfe) {
if (b != 0xf7) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(1, 1, new int[]{b - 0x20})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(1, b - 0x20)};
}
}
return EMPTY_FOLD_CODES;
26 changes: 13 additions & 13 deletions src/org/jcodings/unicode/UnicodeEncoding.java
Original file line number Diff line number Diff line change
@@ -262,13 +262,13 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (Config.USE_UNICODE_CASE_FOLD_TURKISH_AZERI) {
if ((flag & Config.CASE_FOLD_TURKISH_AZERI) != 0) {
if (code == 'I') {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(len, 1, new int[]{DOTLESS_i})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(len, DOTLESS_i)};
} else if(code == I_WITH_DOT_ABOVE) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(len, 1, new int[]{'i'})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(len, 'i')};
} else if(code == DOTLESS_i) {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(len, 1, new int[]{'I'})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(len, 'I')};
} else if(code == 'i') {
return new CaseFoldCodeItem[]{new CaseFoldCodeItem(len, 1, new int[]{I_WITH_DOT_ABOVE})};
return new CaseFoldCodeItem[]{CaseFoldCodeItem.create(len, I_WITH_DOT_ABOVE)};
}
}
} // USE_UNICODE_CASE_FOLD_TURKISH_AZERI
@@ -283,7 +283,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (to.codes.length == 1) {
int origCode = code;

items[0] = new CaseFoldCodeItem(len, 1, new int[]{to.codes[0]});
items[0] = CaseFoldCodeItem.create(len, to.codes[0]);
n++;

code = to.codes[0];
@@ -292,7 +292,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (to != null) {
for (int i=0; i<to.codes.length; i++) {
if (to.codes[i] != origCode) {
items[n] = new CaseFoldCodeItem(len, 1, new int[]{to.codes[i]});
items[n] = CaseFoldCodeItem.create(len, to.codes[i]);
n++;
}
}
@@ -317,7 +317,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (fn == 2) {
for (int i=0; i<ncs[0]; i++) {
for (int j=0; j<ncs[1]; j++) {
items[n] = new CaseFoldCodeItem(len, 2, new int[]{cs[0][i], cs[1][j]});
items[n] = CaseFoldCodeItem.create(len, cs[0][i], cs[1][j]);
n++;
}
}
@@ -326,15 +326,15 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (z2 != null) {
for (int i=0; i<z2.codes.length; i++) {
if (z2.codes[i] == code) continue;
items[n] = new CaseFoldCodeItem(len, 1, new int[]{z2.codes[i]});
items[n] = CaseFoldCodeItem.create(len, z2.codes[i]);
n++;
}
}
} else {
for (int i=0; i<ncs[0]; i++) {
for (int j=0; j<ncs[1]; j++) {
for (int k=0; k<ncs[2]; k++) {
items[n] = new CaseFoldCodeItem(len, 3, new int[]{cs[0][i], cs[1][j], cs[2][k]});
items[n] = CaseFoldCodeItem.create(len, cs[0][i], cs[1][j], cs[2][k]);
n++;
}
}
@@ -343,7 +343,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (z2 != null) {
for (int i=0; i<z2.codes.length; i++) {
if (z2.codes[i] == code) continue;
items[n] = new CaseFoldCodeItem(len, 1, new int[]{z2.codes[i]});
items[n] = CaseFoldCodeItem.create(len, z2.codes[i]);
n++;
}
}
@@ -356,7 +356,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
if (to != null) {
items = new CaseFoldCodeItem[Config.ENC_GET_CASE_FOLD_CODES_MAX_NUM];
for (int i=0; i<to.codes.length; i++) {
items[n] = new CaseFoldCodeItem(len, 1, new int[]{to.codes[i]});
items[n] = CaseFoldCodeItem.create(len, to.codes[i]);
n++;
}
}
@@ -382,7 +382,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
CodeList z2 = CaseUnfold12.Hash.get(codes0, codes1);
if (z2 != null) {
for (int i=0; i<z2.codes.length; i++) {
items[n] = new CaseFoldCodeItem(len, 1, new int[]{z2.codes[i]});
items[n] = CaseFoldCodeItem.create(len, z2.codes[i]);
n++;
}
}
@@ -402,7 +402,7 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
z2 = CaseUnfold13.Hash.get(codes0, codes1, codes2);
if (z2 != null) {
for (int i=0; i<z2.codes.length; i++) {
items[n] = new CaseFoldCodeItem(len, 1, new int[]{z2.codes[i]});
items[n] = CaseFoldCodeItem.create(len, z2.codes[i]);
n++;
}
}

0 comments on commit 3e314df

Please sign in to comment.