1 7 8 package java.util.regex; 9 10 import sun.security.action.GetPropertyAction; 11 12 13 22 23 public class PatternSyntaxException 24 extends IllegalArgumentException 25 { 26 27 private final String desc; 28 private final String pattern; 29 private final int index; 30 31 44 public PatternSyntaxException(String desc, String regex, int index) { 45 this.desc = desc; 46 this.pattern = regex; 47 this.index = index; 48 } 49 50 56 public int getIndex() { 57 return index; 58 } 59 60 65 public String getDescription() { 66 return desc; 67 } 68 69 74 public String getPattern() { 75 return pattern; 76 } 77 78 private static String nl; 79 80 static { 81 nl = (String )java.security.AccessController 82 .doPrivileged(new GetPropertyAction("line.separator")); 83 } 84 85 92 public String getMessage() { 93 String nl = System.getProperty("line.separator"); 94 StringBuffer sb = new StringBuffer (); 95 sb.append(desc); 96 if (index >= 0) { 97 sb.append(" near index "); 98 sb.append(index); 99 } 100 sb.append(nl); 101 sb.append(pattern); 102 if (index >= 0) { 103 sb.append(nl); 104 for (int i = 0; i < index; i++) sb.append(' '); 105 sb.append('^'); 106 } 107 return sb.toString(); 108 } 109 110 } 111 | Popular Tags |