1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html 4 /* 5 ******************************************************************************* 6 * Copyright (C) 2003-2014, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 package android.icu.text; 11 12 import java.text.ParseException; 13 14 /** 15 * Exception that signals an error has occurred while parsing the 16 * input to StringPrep or IDNA. 17 * 18 * @author Ram Viswanadha 19 */ 20 public class StringPrepParseException extends ParseException { 21 // Generated by serialver from JDK 1.4.1_01 22 static final long serialVersionUID = 7160264827701651255L; 23 24 /** 25 */ 26 public static final int INVALID_CHAR_FOUND = 0; 27 /** 28 */ 29 public static final int ILLEGAL_CHAR_FOUND = 1; 30 /** 31 */ 32 public static final int PROHIBITED_ERROR = 2; 33 /** 34 */ 35 public static final int UNASSIGNED_ERROR = 3; 36 /** 37 */ 38 public static final int CHECK_BIDI_ERROR = 4; 39 /** 40 */ 41 public static final int STD3_ASCII_RULES_ERROR = 5; 42 /** 43 */ 44 public static final int ACE_PREFIX_ERROR = 6; 45 /** 46 */ 47 public static final int VERIFICATION_ERROR = 7; 48 /** 49 */ 50 public static final int LABEL_TOO_LONG_ERROR = 8; 51 /** 52 */ 53 public static final int BUFFER_OVERFLOW_ERROR = 9; 54 55 /** 56 */ 57 public static final int ZERO_LENGTH_LABEL = 10; 58 59 /** 60 */ 61 public static final int DOMAIN_NAME_TOO_LONG_ERROR = 11; 62 63 /** 64 * Construct a ParseException object with the given message 65 * and error code 66 * 67 * @param message A string describing the type of error that occurred 68 * @param error The error that has occurred 69 */ StringPrepParseException(String message,int error)70 public StringPrepParseException(String message,int error){ 71 super(message, -1); 72 this.error = error; 73 this.line = 0; 74 } 75 76 /** 77 * Construct a ParseException object with the given message and 78 * error code 79 * 80 * @param message A string describing the type of error that occurred 81 * @param error The error that has occurred 82 * @param rules The input rules string 83 * @param pos The position of error in the rules string 84 */ StringPrepParseException(String message,int error, String rules, int pos)85 public StringPrepParseException(String message,int error, String rules, int pos){ 86 super(message, -1); 87 this.error = error; 88 setContext(rules,pos); 89 this.line = 0; 90 } 91 /** 92 * Construct a ParseException object with the given message and error code 93 * 94 * @param message A string describing the type of error that occurred 95 * @param error The error that has occurred 96 * @param rules The input rules string 97 * @param pos The position of error in the rules string 98 * @param lineNumber The line number at which the error has occurred. 99 * If the parse engine is not using this field, it should set it to zero. Otherwise 100 * it should be a positive integer. The default value of this field 101 * is -1. It will be set to 0 if the code populating this struct is not 102 * using line numbers. 103 */ StringPrepParseException(String message, int error, String rules, int pos, int lineNumber)104 public StringPrepParseException(String message, int error, String rules, int pos, int lineNumber){ 105 super(message, -1); 106 this.error = error; 107 setContext(rules,pos); 108 this.line = lineNumber; 109 } 110 /** 111 * Compare this ParseException to another and evaluate if they are equal. 112 * The comparison works only on the type of error and does not compare 113 * the rules strings, if any, for equality. 114 * 115 * @param other The exception that this object should be compared to 116 * @return true if the objects are equal, false if unequal 117 */ 118 @Override equals(Object other)119 public boolean equals(Object other){ 120 if(!(other instanceof StringPrepParseException)){ 121 return false; 122 } 123 return ((StringPrepParseException)other).error == this.error; 124 125 } 126 127 /** 128 * Mock implementation of hashCode(). This implementation always returns a constant 129 * value. When Java assertion is enabled, this method triggers an assertion failure. 130 * @return a hash code value for this object. 131 * @hide original deprecated declaration 132 */ 133 @Override hashCode()134 public int hashCode() { 135 assert false : "hashCode not designed"; 136 return 42; 137 } 138 139 /** 140 * Returns the position of error in the rules string 141 * 142 * @return String 143 */ 144 @Override toString()145 public String toString(){ 146 StringBuilder buf = new StringBuilder(); 147 buf.append(super.getMessage()); 148 buf.append(". line: "); 149 buf.append(line); 150 buf.append(". preContext: "); 151 buf.append(preContext); 152 buf.append(". postContext: "); 153 buf.append(postContext); 154 buf.append("\n"); 155 return buf.toString(); 156 } 157 158 private int error; 159 160 /** 161 * The line on which the error occurred. If the parse engine 162 * is not using this field, it should set it to zero. Otherwise 163 * it should be a positive integer. The default value of this field 164 * is -1. It will be set to 0 if the code populating this struct is not 165 * using line numbers. 166 */ 167 private int line; 168 169 170 /** 171 * Textual context before the error. Null-terminated. 172 * May be the empty string if not implemented by parser. 173 */ 174 private StringBuffer preContext = new StringBuffer(); 175 176 /** 177 * Textual context after the error. Null-terminated. 178 * May be the empty string if not implemented by parser. 179 */ 180 private StringBuffer postContext = new StringBuffer(); 181 182 private static final int PARSE_CONTEXT_LEN = 16; 183 setPreContext(String str, int pos)184 private void setPreContext(String str, int pos){ 185 setPreContext(str.toCharArray(),pos); 186 } 187 setPreContext(char[] str, int pos)188 private void setPreContext(char[] str, int pos){ 189 int start = (pos <= PARSE_CONTEXT_LEN)? 0 : (pos - (PARSE_CONTEXT_LEN-1)); 190 int len = (start <= PARSE_CONTEXT_LEN)? start : PARSE_CONTEXT_LEN; 191 preContext.append(str,start,len); 192 193 } 194 setPostContext(String str, int pos)195 private void setPostContext(String str, int pos){ 196 setPostContext(str.toCharArray(),pos); 197 } 198 setPostContext(char[] str, int pos)199 private void setPostContext(char[] str, int pos){ 200 int start = pos; 201 int len = str.length - start; 202 postContext.append(str,start,len); 203 204 } 205 setContext(String str,int pos)206 private void setContext(String str,int pos){ 207 setPreContext(str,pos); 208 setPostContext(str,pos); 209 } 210 211 /** 212 * Returns the error code of this exception. 213 * This method is only used for testing to verify the error. 214 * @return The error code 215 */ getError()216 public int getError(){ 217 return error; 218 } 219 } 220