Use string instead of string buffer

This commit is contained in:
Owen Stephens 2017-11-29 09:47:31 +00:00
parent 93431daecf
commit 0c97ad1b69

View File

@ -81,45 +81,46 @@ public class PatternSyntaxExceptionParser {
} }
public String getUserMessage() { public String getUserMessage() {
String msg = "";
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String desc = exception.getDescription(); String desc = exception.getDescription();
switch(desc) switch(desc)
{ {
case "Unclosed character class": case "Unclosed character class":
sb.append("The regular expression is missing a closing ']' character, or has an empty pair of square brackets '[]'."); msg = "The regular expression is missing a closing ']' character, or has an empty pair of square brackets '[]'.";
break; break;
case "Unmatched closing ')'": case "Unmatched closing ')'":
sb.append("The regular expression is missing a opening '(' character."); msg = "The regular expression is missing a opening '(' character.";
break; break;
case "Unclosed group": case "Unclosed group":
sb.append("The regular expression is missing a closing ')' character."); msg = "The regular expression is missing a closing ')' character.";
break; break;
case "Dangling meta character '*'": case "Dangling meta character '*'":
case "Dangling meta character '+'": case "Dangling meta character '+'":
case "Dangling meta character '?'": case "Dangling meta character '?'":
sb.append("The regular expression has a '*','+' or '?' in the wrong place."); msg = "The regular expression has a '*','+' or '?' in the wrong place.";
break; break;
case "Unexpected internal error": case "Unexpected internal error":
sb.append("The regular expression has a backslash '\\' at the end."); msg = "The regular expression has a backslash '\\' at the end.";
break; break;
case "Unclosed counted closure": case "Unclosed counted closure":
sb.append("The regular expression is missing a closing '}' character, or has an incorrect quantifier statement in curly brackets '{}'."); msg = "The regular expression is missing a closing '}' character, or has an incorrect quantifier statement in curly brackets '{}'.";
break; break;
case "Illegal repetition": case "Illegal repetition":
sb.append("The regular expression has an incomplete or incorrect quantifier statement in curly brackets '{}'."); msg = "The regular expression has an incomplete or incorrect quantifier statement in curly brackets '{}'.";
break; break;
case "Illegal repetition range": case "Illegal repetition range":
sb.append("The regular expression has a quantifier statement where the minimum is larger than the maximum (e.g. {4,3})."); msg = "The regular expression has a quantifier statement where the minimum is larger than the maximum (e.g. {4,3}).";
break; break;
case "Illegal character range": case "Illegal character range":
sb.append("The regular expression has a range statement which is incomplete or has the characters in the incorrect order (e.g. [9-0])"); msg = "The regular expression has a range statement which is incomplete or has the characters in the incorrect order (e.g. [9-0])";
break; break;
default: default:
// If no special handling in place fall back on error msg // If no special handling in place fall back on error msg
// created by java.util.regex.PatternSyntaxException // created by java.util.regex.PatternSyntaxException
sb.append(exception.getMessage()); msg = exception.getMessage();
break; break;
} }
return sb.toString(); return msg;
} }
} }