throws ImageReadException, IOException {
String name;
String token;
token = cParser.nextToken();
if (!"static".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no 'static' token");
}
token = cParser.nextToken();
if (!"char".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no 'char' token");
}
token = cParser.nextToken();
if (!"*".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no '*' token");
}
name = cParser.nextToken();
if (name == null) {
throw new ImageReadException(
"Parsing XPM file failed, no variable name");
}
if (name.charAt(0) != '_' && !Character.isLetter(name.charAt(0))) {
throw new ImageReadException(
"Parsing XPM file failed, variable name "
+ "doesn't start with letter or underscore");
}
for (int i = 0; i < name.length(); i++) {
final char c = name.charAt(i);
if (!Character.isLetterOrDigit(c) && c != '_') {
throw new ImageReadException(
"Parsing XPM file failed, variable name "
+ "contains non-letter non-digit non-underscore");
}
}
token = cParser.nextToken();
if (!"[".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no '[' token");
}
token = cParser.nextToken();
if (!"]".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no ']' token");
}
token = cParser.nextToken();
if (!"=".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no '=' token");
}
token = cParser.nextToken();
if (!"{".equals(token)) {
throw new ImageReadException(
"Parsing XPM file failed, no '{' token");
}
final StringBuilder row = new StringBuilder();
final boolean hasMore = parseNextString(cParser, row);
if (!hasMore) {
throw new ImageReadException("Parsing XPM file failed, "
+ "file too short");
}
final XpmHeader xpmHeader = parseXpmValuesSection(row.toString());
parsePaletteEntries(xpmHeader, cParser);
return xpmHeader;