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: 0bbb033d3c72
Choose a base ref
...
head repository: jruby/jcodings
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 50467122c04b
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 1, 2017

  1. MRI does not treat any single-byte encodings differently.

    US-ASCII only checks > 0xFF here, like the other single-byte
    encodings.
    headius committed Aug 1, 2017
    Copy the full SHA
    1e1f98a View commit details
  2. Return error code, not zero.

    headius committed Aug 1, 2017
    Copy the full SHA
    5046712 View commit details
11 changes: 3 additions & 8 deletions src/org/jcodings/SingleByteEncoding.java
Original file line number Diff line number Diff line change
@@ -23,19 +23,14 @@

public abstract class SingleByteEncoding extends AbstractEncoding {

public static final int MAX_BYTE = 0xff;
protected final byte[] LowerCaseTable;
protected int codeSize = 0xff;

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

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

/** onigenc_single_byte_mbc_enc_len
*/
@Override
@@ -71,7 +66,7 @@ public int mbcToCode(byte[] bytes, int p, int end) {
@Override
public int codeToMbcLength(int code) {
if (Config.VANILLA) {
if (code <= codeSize) return 1;
if (code <= MAX_BYTE) return 1;
return ErrorCodes.ERR_INVALID_CODE_POINT_VALUE;
} else {
return 1;
@@ -82,7 +77,7 @@ public int codeToMbcLength(int code) {
*/
@Override
public final int codeToMbc(int code, byte[] bytes, int p) {
if (code > codeSize) return ErrorCodes.ERR_TOO_BIG_WIDE_CHAR_VALUE;
if (code > MAX_BYTE) return ErrorCodes.ERR_TOO_BIG_WIDE_CHAR_VALUE;

bytes[p] = (byte)(code & 0xff); // c implementation also uses mask here
return 1;
2 changes: 1 addition & 1 deletion src/org/jcodings/specific/BaseSJISEncoding.java
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public int mbcToCode(byte[]bytes, int p, int end) {
@Override
public int codeToMbcLength(int code) {
if (code < 256) {
return SjisEncLen[code] == 1 ? 1 : 0;
return SjisEncLen[code] == 1 ? 1 : ErrorCodes.ERR_INVALID_CODE_POINT_VALUE;
} else if (code <= 0xffff) {
int low = code & 0xff;
if (!SJIS_ISMB_TRAIL(low)) {
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, 0x7f);
super("US-ASCII", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable);
}

@Override
2 changes: 1 addition & 1 deletion test/org/jcodings/specific/TestUSASCIIEncoding.java
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ public void testValidCodeToMbc() {
@Test
public void testInvalidCodeToMbc() {
byte[] buffer = new byte[1];
assertEquals(EncodingError.ERR_TOO_BIG_WIDE_CHAR_VALUE.getCode(), USASCIIEncoding.INSTANCE.codeToMbc(0x80, buffer, 0));
assertEquals(EncodingError.ERR_TOO_BIG_WIDE_CHAR_VALUE.getCode(), USASCIIEncoding.INSTANCE.codeToMbc(0xff + 1, buffer, 0));
}