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

Commits on Mar 24, 2015

  1. Copy the full SHA
    a715f17 View commit details
  2. Copy the full SHA
    4050406 View commit details
Showing with 83 additions and 1 deletion.
  1. +73 −0 src/org/jcodings/exception/ErrorCodes.java
  2. +10 −1 src/org/jcodings/specific/BaseSJISEncoding.java
73 changes: 73 additions & 0 deletions src/org/jcodings/exception/ErrorCodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.jcodings.exception;

public interface ErrorCodes {
public static final int NORMAL = 0;
public static final int MISMATCH = -1;
public static final int NO_SUPPORT_CONFIG = -2;

/* internal error */
public static final int ERR_MEMORY = -5;
public static final int ERR_TYPE_BUG = -6;
public static final int ERR_PARSER_BUG = -11;
public static final int ERR_STACK_BUG = -12;
public static final int ERR_UNDEFINED_BYTECODE = -13;
public static final int ERR_UNEXPECTED_BYTECODE = -14;
public static final int ERR_MATCH_STACK_LIMIT_OVER = -15;
public static final int ERR_DEFAULT_ENCODING_IS_NOT_SET = -21;
public static final int ERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR = -22;
/* general error */
public static final int ERR_INVALID_ARGUMENT = -30;
/* syntax error */
public static final int ERR_END_PATTERN_AT_LEFT_BRACE = -100;
public static final int ERR_END_PATTERN_AT_LEFT_BRACKET = -101;
public static final int ERR_EMPTY_CHAR_CLASS = -102;
public static final int ERR_PREMATURE_END_OF_CHAR_CLASS = -103;
public static final int ERR_END_PATTERN_AT_ESCAPE = -104;
public static final int ERR_END_PATTERN_AT_META = -105;
public static final int ERR_END_PATTERN_AT_CONTROL = -106;
public static final int ERR_META_CODE_SYNTAX = -108;
public static final int ERR_CONTROL_CODE_SYNTAX = -109;
public static final int ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE = -110;
public static final int ERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE = -111;
public static final int ERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS = -112;
public static final int ERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED = -113;
public static final int ERR_TARGET_OF_REPEAT_OPERATOR_INVALID = -114;
public static final int ERR_NESTED_REPEAT_OPERATOR = -115;
public static final int ERR_UNMATCHED_CLOSE_PARENTHESIS = -116;
public static final int ERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS = -117;
public static final int ERR_END_PATTERN_IN_GROUP = -118;
public static final int ERR_UNDEFINED_GROUP_OPTION = -119;
public static final int ERR_INVALID_POSIX_BRACKET_TYPE = -121;
public static final int ERR_INVALID_LOOK_BEHIND_PATTERN = -122;
public static final int ERR_INVALID_REPEAT_RANGE_PATTERN = -123;
public static final int ERR_INVALID_CONDITION_PATTERN = -124;
/* values error (syntax error) */
public static final int ERR_TOO_BIG_NUMBER = -200;
public static final int ERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE = -201;
public static final int ERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE = -202;
public static final int ERR_EMPTY_RANGE_IN_CHAR_CLASS = -203;
public static final int ERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE = -204;
public static final int ERR_TOO_MANY_MULTI_BYTE_RANGES = -205;
public static final int ERR_TOO_SHORT_MULTI_BYTE_STRING = -206;
public static final int ERR_TOO_BIG_BACKREF_NUMBER = -207;
public static final int ERR_INVALID_BACKREF = -208;
public static final int ERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED = -209;
public static final int ERR_TOO_SHORT_DIGITS = -210;
public static final int ERR_TOO_LONG_WIDE_CHAR_VALUE = -212;
public static final int ERR_EMPTY_GROUP_NAME = -214;
public static final int ERR_INVALID_GROUP_NAME = -215;
public static final int ERR_INVALID_CHAR_IN_GROUP_NAME = -216;
public static final int ERR_UNDEFINED_NAME_REFERENCE = -217;
public static final int ERR_UNDEFINED_GROUP_REFERENCE = -218;
public static final int ERR_MULTIPLEX_DEFINED_NAME = -219;
public static final int ERR_MULTIPLEX_DEFINITION_NAME_CALL = -220;
public static final int ERR_NEVER_ENDING_RECURSION = -221;
public static final int ERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY = -222;
public static final int ERR_INVALID_CHAR_PROPERTY_NAME = -223;
public static final int ERR_TOO_MANY_CAPTURE_GROUPS = -224;
public static final int ERR_INVALID_CODE_POINT_VALUE = -400;
public static final int ERR_INVALID_WIDE_CHAR_VALUE = -400;
public static final int ERR_TOO_BIG_WIDE_CHAR_VALUE = -401;
public static final int ERR_NOT_SUPPORTED_ENCODING_COMBINATION = -402;
public static final int ERR_INVALID_COMBINATION_OF_OPTIONS = -403;
}
11 changes: 10 additions & 1 deletion src/org/jcodings/specific/BaseSJISEncoding.java
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
import org.jcodings.ascii.AsciiTables;
import org.jcodings.constants.CharacterType;
import org.jcodings.exception.EncodingException;
import org.jcodings.exception.ErrorCodes;
import org.jcodings.exception.ErrorMessages;
import org.jcodings.exception.InternalException;
import org.jcodings.util.BytesHash;
@@ -51,12 +52,20 @@ public int codeToMbcLength(int code) {
if (code < 256) {
return SjisEncLen[code] == 1 ? 1 : 0;
} else if (code <= 0xffff) {
int low = code & 0xff;
if (!SJIS_ISMB_TRAIL(low)) {
return ErrorCodes.ERR_INVALID_CODE_POINT_VALUE;
}
return 2;
} else {
throw new EncodingException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
return ErrorCodes.ERR_INVALID_CODE_POINT_VALUE;
}
}

private static boolean SJIS_ISMB_TRAIL(int code) {
return SJIS_CAN_BE_TRAIL_TABLE[code];
}

@Override
public int codeToMbc(int code, byte[]bytes, int p) {
int p_ = p;