private boolean checkAnnotation(char ch) throws UcumException { if (ch == '{') { StringBuilder b = new StringBuilder(); while (ch != '}') { ch = nextChar(); if (!Utilities.isAsciiChar(ch)) throw new UcumException("Error processing unit'"+source+"': Annotation contains non-ascii characters"); if (ch == 0) throw new UcumException("Error processing unit'"+source+"': unterminated annotation"); b.append(ch); } // got to the end of the annotation - need to do it again token = b.toString(); type = TokenType.ANNOTATION; return true; } else return false; }
public void consume() throws UcumException { token = null; type = TokenType.NONE; start = index; if (index < source.length()) { char ch = nextChar(); if (!(checkSingle(ch, '/', TokenType.SOLIDUS) || checkSingle(ch, '.', TokenType.PERIOD) || checkSingle(ch, '(', TokenType.OPEN) || checkSingle(ch, ')', TokenType.CLOSE) || checkAnnotation(ch) || checkNumber(ch) || checkNumberOrSymbol(ch))) throw new UcumException("Error processing unit '"+source+"': unexpected character '"+ch+"' at position "+Integer.toString(start)); } }
private boolean checkAnnotation(char ch) throws UcumException { if (ch == '{') { StringBuilder b = new StringBuilder(); while (ch != '}') { ch = nextChar(); if (!Utilities.isAsciiChar(ch)) throw new UcumException("Error processing unit'"+source+"': Annotation contains non-ascii characters"); if (ch == 0) throw new UcumException("Error processing unit'"+source+"': unterminated annotation"); b.append(ch); } // got to the end of the annotation - need to do it again token = b.toString(); type = TokenType.ANNOTATION; return true; } else return false; }
public void consume() throws UcumException { token = null; type = TokenType.NONE; start = index; if (index < source.length()) { char ch = nextChar(); if (!(checkSingle(ch, '/', TokenType.SOLIDUS) || checkSingle(ch, '.', TokenType.PERIOD) || checkSingle(ch, '(', TokenType.OPEN) || checkSingle(ch, ')', TokenType.CLOSE) || checkAnnotation(ch) || checkNumber(ch) || checkNumberOrSymbol(ch))) throw new UcumException("Error processing unit '"+source+"': unexpected character '"+ch+"' at position "+Integer.toString(start)); } }