* @return the character value without enclosing quotes and embedded
* escapes
* @exception IllegalArgumentException if the literal value cannot be converted
*/
public char charValue() {
Scanner scanner = this.ast.scanner;
char[] source = this.escapedValue.toCharArray();
scanner.setSource(source);
scanner.resetTo(0, source.length);
int firstChar = scanner.getNextChar();
int secondChar = scanner.getNextChar();
if (firstChar == -1 || firstChar != '\'') {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
char value = (char) secondChar;
int nextChar = scanner.getNextChar();
if (secondChar == '\\') {
if (nextChar == -1) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
switch(nextChar) {
case 'b' :
value = '\b';
break;
case 't' :
value = '\t';
break;
case 'n' :
value = '\n';
break;
case 'f' :
value = '\f';
break;
case 'r' :
value = '\r';
break;
case '\"':
value = '\"';
break;
case '\'':
value = '\'';
break;
case '\\':
value = '\\';
break;
default : //octal (well-formed: ended by a ' )
try {
if (ScannerHelper.isDigit((char) nextChar)) {
int number = ScannerHelper.getNumericValue((char) nextChar);
nextChar = scanner.getNextChar();
if (nextChar == -1) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
if (nextChar != '\'') {
if (!ScannerHelper.isDigit((char) nextChar)) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
number = (number * 8) + ScannerHelper.getNumericValue((char) nextChar);
nextChar = scanner.getNextChar();
if (nextChar == -1) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
if (nextChar != '\'') {
if (!ScannerHelper.isDigit((char) nextChar)) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
number = (number * 8) + ScannerHelper.getNumericValue((char) nextChar);
}
}
return (char) number;
} else {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
} catch (InvalidInputException e) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
}
nextChar = scanner.getNextChar();
if (nextChar == -1) {
throw new IllegalArgumentException("illegal character literal");//$NON-NLS-1$
}
}
if (nextChar == -1 || nextChar != '\'') {