Skip to content

Commit

Permalink
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/org/jcodings/AbstractEncoding.java
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ int asciiOnlyCaseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]
if (code >= 'a' && code <= 'z' && ((flags & Config.CASE_UPCASE) != 0)) {
flags |= Config.CASE_MODIFIED;
code += 'A' - 'a';
} else if (code >= 'A' && code <= 'Z' && ((flags & Config.CASE_DOWNCASE | Config.CASE_FOLD) != 0)) {
} else if (code >= 'A' && code <= 'Z' && ((flags & (Config.CASE_DOWNCASE | Config.CASE_FOLD)) != 0)) {
flags |= Config.CASE_MODIFIED;
code += 'a' - 'A';
}
27 changes: 24 additions & 3 deletions test/org/jcodings/specific/TestCaseMap.java
Original file line number Diff line number Diff line change
@@ -7,20 +7,41 @@

import org.jcodings.Config;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.IntHolder;
import org.jcodings.util.CaseInsensitiveBytesHash;
import org.junit.Test;

public class TestCaseMap {
String caseMap(Encoding enc, String fromS, int flags) throws Exception {
String caseMap(Encoding enc, String transcode, String fromS, int flags) throws Exception {
int CASE_MAPPING_ADDITIONAL_LENGTH = 20;
byte[]from = fromS.getBytes(enc.toString());
byte[]from = fromS.getBytes(transcode);
IntHolder fromP = new IntHolder();
fromP.value = 0;
byte[]to = new byte[from.length + CASE_MAPPING_ADDITIONAL_LENGTH];
IntHolder flagP = new IntHolder();
flagP.value = flags;
int len = enc.caseMap(flagP, from, fromP, from.length, to, 0, to.length);
return new String(to, 0, len, enc.toString());
return new String(to, 0, len, transcode);
}

String caseMap(Encoding enc, String fromS, int flags) throws Exception {
return caseMap(enc, enc.toString(), fromS, flags);
}

@Test
public void testASCIICaseMap() throws Exception {
CaseInsensitiveBytesHash<EncodingDB.Entry> list = EncodingDB.getEncodings();
String transcodeFrom = "iso-8859-1";
for (EncodingDB.Entry entry: list) {
Encoding enc = entry.getEncoding();
if (enc.isAsciiCompatible()) {
assertTrue(caseMap(enc, transcodeFrom, "abcdefghijklmnopqrstuvwxyz", Config.CASE_UPCASE).equals("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
assertTrue(caseMap(enc, transcodeFrom, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Config.CASE_UPCASE).equals("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
assertTrue(caseMap(enc, transcodeFrom, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Config.CASE_DOWNCASE).equals("abcdefghijklmnopqrstuvwxyz"));
assertTrue(caseMap(enc, transcodeFrom, "abcdefghijklmnopqrstuvwxyz", Config.CASE_DOWNCASE).equals("abcdefghijklmnopqrstuvwxyz"));
}
}
}

@Test

0 comments on commit 12dec8f

Please sign in to comment.