Skip to content

Commit

Permalink
Showing 6 changed files with 24 additions and 40 deletions.
5 changes: 0 additions & 5 deletions src/org/jcodings/AbstractEncoding.java
Original file line number Diff line number Diff line change
@@ -33,11 +33,6 @@ protected AbstractEncoding(String name, int minLength, int maxLength, short[]CTy
this.CTypeTable = CTypeTable;
}

protected AbstractEncoding(String name, int minLength, int maxLength, short[]CTypeTable, boolean isDummy) {
super(name, minLength, maxLength, isDummy);
this.CTypeTable = CTypeTable;
}

/** CTYPE_TO_BIT
*/
private static int CTypeToBit(int ctype) {
33 changes: 13 additions & 20 deletions src/org/jcodings/Encoding.java
Original file line number Diff line number Diff line change
@@ -33,15 +33,16 @@ public abstract class Encoding implements Cloneable {
private static int count;

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

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

protected Encoding(String name, int minLength, int maxLength, boolean isDummy) {
protected Encoding(String name, int minLength, int maxLength) {
setName(name);

this.minLength = minLength;
@@ -50,12 +51,7 @@ protected Encoding(String name, int minLength, int maxLength, boolean isDummy) {
this.isSingleByte = isFixedWidth && minLength == 1;
this.index = count++;

this.isDummy = isDummy;
this.isAsciiCompatible = minLength == 1 && !isDummy;
}

protected Encoding(String name, int minLength, int maxLength) {
this(name, minLength, maxLength, false);
this.isAsciiCompatible = minLength == 1;
}

protected final void setName(String name) {
@@ -68,8 +64,9 @@ 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;
protected final void setDummy() {
isDummy = true;
isAsciiCompatible = false;
}

@Override
@@ -124,15 +121,11 @@ public String getCharsetName() {
return null;
}

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

public Encoding replicate(byte[]name, boolean dummy) {
Encoding replicate(byte[]name, boolean dummy) {
try {
Encoding clone = (Encoding)clone();
clone.setName(name);
clone.setDummy(dummy);
if (dummy) clone.setDummy();
clone.index = count++;
return clone;
} catch (CloneNotSupportedException cnse){
4 changes: 2 additions & 2 deletions src/org/jcodings/EncodingDB.java
Original file line number Diff line number Diff line change
@@ -78,9 +78,9 @@ public Encoding getEncoding() {
encoding = Encoding.load(encodingClass);
} else {
if (isDummy) {
encoding = Encoding.loadForDummy(encodingClass).replicate(name, isDummy);
encoding = Encoding.loadForDummy(encodingClass).replicate(name, true);
} else {
encoding = Encoding.load(encodingClass).replicate(name);
encoding = Encoding.load(encodingClass).replicate(name, false);
}
}
}
9 changes: 2 additions & 7 deletions src/org/jcodings/SingleByteEncoding.java
Original file line number Diff line number Diff line change
@@ -32,13 +32,8 @@ protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTa
this.LowerCaseTable = LowerCaseTable;
}

protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTable, boolean isDummy) {
super(name, 1, 1, CTypeTable, isDummy);
this.LowerCaseTable = LowerCaseTable;
}

protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTable, boolean isDummy, int codeSize) {
this(name, CTypeTable, LowerCaseTable, isDummy);
protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTable, int codeSize) {
this(name, CTypeTable, LowerCaseTable);
this.codeSize = codeSize;
}

11 changes: 6 additions & 5 deletions src/org/jcodings/specific/ASCIIEncoding.java
Original file line number Diff line number Diff line change
@@ -27,10 +27,6 @@ protected ASCIIEncoding() {
super("ASCII-8BIT", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable);
}

protected ASCIIEncoding(boolean isDummy) {
super(isDummy ? "DUMMY" : "ASCII-8BIT", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable, isDummy);
}

@Override
public final byte[] toLowerCaseTable() {
return LowerCaseTable;
@@ -49,5 +45,10 @@ public boolean isCodeCType(int code, int ctype) {
}

public static final ASCIIEncoding INSTANCE = new ASCIIEncoding();
public static final ASCIIEncoding DUMMY = new ASCIIEncoding(true);
public static final ASCIIEncoding DUMMY;
static {
DUMMY = new ASCIIEncoding();
DUMMY.setName("DUMMY");
DUMMY.setDummy();
}
}
2 changes: 1 addition & 1 deletion src/org/jcodings/specific/USASCIIEncoding.java
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
public final class USASCIIEncoding extends SingleByteEncoding {

protected USASCIIEncoding() {
super("US-ASCII", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable, false, 0x7f);
super("US-ASCII", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable, 0x7f);
}

@Override

0 comments on commit d9edcd4

Please sign in to comment.