Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jcodings
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6f74302089fe
Choose a base ref
...
head repository: jruby/jcodings
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6b60d54ff197
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 13, 2015

  1. Dummy UTF-32 and UTF-16 need to be replicas with dummy flag.

    Dummy flag is used in various places, so these replicas can't be
    perfect replicas. See jruby/jruby#2581.
    headius committed Mar 13, 2015
    Copy the full SHA
    4bcfdc3 View commit details
  2. Typos in port of UTF-32 input handling.

    Relates to jruby/jruby#2581.
    headius committed Mar 13, 2015
    Copy the full SHA
    042076b View commit details
  3. Fix dummy logic for replicas broken by dummyUnicode fix.

    My fix caused all replicas to be marked as dummy. This change
    fixes that by restoring the dummy-specific path.
    headius committed Mar 13, 2015
    Copy the full SHA
    d1adf02 View commit details

Commits on Mar 16, 2015

  1. Copy the full SHA
    6b60d54 View commit details
31 changes: 28 additions & 3 deletions src/org/jcodings/Encoding.java
Original file line number Diff line number Diff line change
@@ -33,12 +33,13 @@ public abstract class Encoding implements Cloneable {
private static int count;

protected final int minLength, maxLength;
protected final boolean isFixedWidth, isSingleByte, isDummy, isAsciiCompatible;
protected final boolean isFixedWidth, isSingleByte, isAsciiCompatible;

protected byte[]name;
protected int hashCode;
private int index;
protected Charset charset = null;
protected boolean isDummy;

protected Encoding(String name, int minLength, int maxLength, boolean isDummy) {
setName(name);
@@ -67,6 +68,10 @@ protected final void setName(byte[]name) {
this.hashCode = BytesHash.hashCode(this.name, 0, this.name.length);
}

protected final void setDummy(boolean dummy) {
this.isDummy = dummy;
}

@Override
public final String toString() {
return new String(name);
@@ -120,9 +125,14 @@ public String getCharsetName() {
}

public Encoding replicate(byte[]name) {
return replicate(name, false);
}

public Encoding replicate(byte[]name, boolean dummy) {
try {
Encoding clone = (Encoding)clone();
clone.setName(name);
clone.setDummy(dummy);
clone.index = count++;
return clone;
} catch (CloneNotSupportedException cnse){
@@ -535,18 +545,33 @@ public final boolean isFixedWidth() {
public static final byte NEW_LINE = (byte)0x0a;

public static Encoding load(String name) {
String encClassName = "org.jcodings.specific." + name + "Encoding";
return loadDummyOrEncoding(name, false);
}

public static Encoding loadForDummy(String name) {
return loadDummyOrEncoding(name, true);
}

private static Encoding loadDummyOrEncoding(String name, boolean dummy) {
String encClassName = "org.jcodings.specific." + name + "Encoding";
Class<?> encClass;
try {
encClass = Class.forName(encClassName);
} catch (ClassNotFoundException cnfe) {
throw new InternalException(ErrorMessages.ERR_ENCODING_CLASS_DEF_NOT_FOUND, encClassName);
}

if (dummy) {
try {
return (Encoding) encClass.getField("DUMMY").get(encClass);
} catch (Exception e) {
// try to fall back on normal instance
}
}

try {
return (Encoding)encClass.getField("INSTANCE").get(encClass);
} catch (Exception e) {
} catch (Exception e2) {
throw new InternalException(ErrorMessages.ERR_ENCODING_LOAD_ERROR, encClassName);
}
}
20 changes: 18 additions & 2 deletions src/org/jcodings/EncodingDB.java
Original file line number Diff line number Diff line change
@@ -58,6 +58,11 @@ private Entry (byte[]name, String encodingClass, Entry base, boolean isDummy) {
this(name, ascii.encodingClass, ascii, true);
}

// dummy with base
Entry(byte[]name, Entry base, boolean dummy) {
this(name, base.encodingClass, base, dummy);
}

@Override
public int hashCode() {
return encodingClass.hashCode();
@@ -73,7 +78,7 @@ public Encoding getEncoding() {
encoding = Encoding.load(encodingClass);
} else {
if (isDummy) {
encoding = ASCIIEncoding.DUMMY.replicate(name);
encoding = Encoding.loadForDummy(encodingClass).replicate(name, isDummy);
} else {
encoding = Encoding.load(encodingClass).replicate(name);
}
@@ -166,12 +171,16 @@ public static void alias(String alias, String original) {
}

public static void replicate(String replica, String original) {
replicate(replica, original, false);
}

private static void replicate(String replica, String original, boolean dummy) {
byte[]origBytes = original.getBytes();
Entry originalEntry = encodings.get(origBytes);
if (originalEntry == null) throw new InternalException(ErrorMessages.ERR_NO_SUCH_ENCODNG, original);
byte[]replicaBytes = replica.getBytes();
if (encodings.get(replicaBytes) != null) throw new InternalException(ErrorMessages.ERR_ENCODING_REPLICA_ALREADY_REGISTERED, replica);
encodings.putDirect(replicaBytes, new Entry(replicaBytes, originalEntry));
encodings.putDirect(replicaBytes, new Entry(replicaBytes, originalEntry, dummy));
}

public static void set_base(String name, String original) {
@@ -188,6 +197,10 @@ public static void dummy(String name) {
dummy(name.getBytes());
}

public static void dummyUnicode(String replica) {
replicate(replica, replica + "BE", true);
}

static {
for (int i = 0; i < builtin.length / 2; i++) {
declare(builtin[i << 1], builtin[(i << 1) + 1]);
@@ -213,6 +226,9 @@ public static void dummy(String name) {
case 'D':
dummy(enc[1]);
break;
case 'U': // ENC_DUMMY_UNICODE from encdb.c
dummyUnicode(enc[1]);
break;
default:
Thread.dumpStack();
throw new InternalException("Unknown flag: " + enc[0].charAt(0));
4 changes: 2 additions & 2 deletions src/org/jcodings/EncodingList.java
Original file line number Diff line number Diff line change
@@ -133,8 +133,8 @@ final class EncodingList {
{"R", "UTF8-MAC", "UTF-8"},
{"A", "UTF-8-MAC", "UTF8-MAC"},
{"A", "UTF-8-HFS", "UTF8-MAC" /* Emacs 23.2 */},
{"R", "UTF-16", "UTF-16BE"},
{"R", "UTF-32", "UTF-32BE"},
{"U", "UTF-16"},
{"U", "UTF-32"},
{"A", "UCS-2BE", "UTF-16BE"},
{"A", "UCS-4BE", "UTF-32BE"},
{"A", "UCS-4LE", "UTF-32LE"},
2 changes: 1 addition & 1 deletion src/org/jcodings/MultiByteEncoding.java
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@ protected final int mb4CodeToMbc(int code, byte[]bytes, int p) {
}

protected final boolean mb2IsCodeCType(int code, int ctype) {
if (code < 128) {
if ((code & 0xFFFFFFFFL) < 128) { // unsigned 32-bit
return isCodeCTypeInternal(code, ctype); // configured with ascii
} else {
if (isWordGraphPrint(ctype)) {
5 changes: 3 additions & 2 deletions src/org/jcodings/transcode/TranscodeFunctions.java
Original file line number Diff line number Diff line change
@@ -165,16 +165,17 @@ public static int funSiFromUTF32(byte[] statep, byte[] s, int sStart, int l) {
switch (sp[0]) {
case 0:
s3 = s[sStart+3] & 0xFF;
if (s0 == 0 && s1 == 0 && s2 == 0xFE && s3 == 0xEE) {
if (s0 == 0 && s1 == 0 && s2 == 0xFE && s3 == 0xFF) {
sp[0] = BE;
return TranscodingInstruction.ZERObt;
} else if (s0 == 0xFF && s1 == 0xFE && s2 == 0 && s3 == 0) {
sp[0] = LE;
return TranscodingInstruction.ZERObt;
}
break;
case BE:
if (s0 == 0 && ((0 < s1 && s1 <= 0x10)) ||
(s1 == 0 && (s2 < 0xD8 && 0xDF < s2))) {
(s1 == 0 && (s2 < 0xD8 || 0xDF < s2))) {
return TranscodingInstruction.FUNso;
}
break;