private TypeExpressionNode validateNode(TypeExpressionNode result, StringCharacterIterator iter) throws TypeExpressionParsingException { if (result instanceof UnionTypeExpressionNode) { if (result.getChildren().size() < 2) { throw new TypeExpressionParsingException("Invalid union type expression.", iter.getIndex()); } } else if (result instanceof ArrayTypeExpressionNode) { if (result.getChildren().size() != 1) { throw new TypeExpressionParsingException("Invalid array type expression.", iter.getIndex()); } } return result; }
private TypeExpressionNode validateNode(TypeExpressionNode result, StringCharacterIterator iter) throws TypeExpressionParsingException { if (result instanceof UnionTypeExpressionNode) { if (result.getChildren().size() < 2) { throw new TypeExpressionParsingException("Invalid union type expression.", iter.getIndex()); } } else if (result instanceof ArrayTypeExpressionNode) { if (result.getChildren().size() != 1) { throw new TypeExpressionParsingException("Invalid array type expression.", iter.getIndex()); } } return result; }
StringTokenizer(String value, char delim) { string = value; // Loop on the characters counting the separators and remembering // their positions StringCharacterIterator sci = new StringCharacterIterator(string); char c = sci.first(); while (c != CharacterIterator.DONE) { if (c == delim) { // Remember its position separatorPosition[tokens] = sci.getIndex(); tokens++; // Resize the position array if needed if (tokens >= separatorPosition.length) { int[] copy = new int[separatorPosition.length * 10]; System.arraycopy(separatorPosition, 0, copy, 0, separatorPosition.length); separatorPosition = copy; } } c = sci.next(); } // Add one token: tokens = separatorCount + 1 tokens++; }
private int countChar(char searchChar, String inTargetString) { StringCharacterIterator iter = new StringCharacterIterator(inTargetString); int i = 0; if (iter.first() == searchChar) i++; while (iter.getIndex() < iter.getEndIndex()) { if (iter.next() == searchChar) { i++; } } return i; }
private TypeExpressionNode handleExpressionFinished(Node currentNode, Stack<TypeExpressionNode> typeStack, StringCharacterIterator iter, StringBuilder simpleExpression) throws TypeExpressionParsingException { handleSimpleExpression(currentNode, iter, typeStack, simpleExpression); TypeExpressionNode result = null; if (typeStack.isEmpty()) { throw new TypeExpressionParsingException("Invalid empty expression.", iter.getIndex()); } while (!typeStack.isEmpty()) { final TypeExpressionNode node = typeStack.pop(); if (result != null) { node.addChild(result); } result = node; validateNode(result, iter); } return result; }
int iStart = i.getIndex(); char ch = decodeEscapeSequence(i); if (ch != StringCharacterIterator.DONE) { BasicEnvironment benv = getEnvironment(); benv.problem(ProblemHandler.Severity.ERROR, ProblemHandler.Phase.PARSER, OCLMessages .bind(OCLMessages.InvalidEscapeSequence_ERROR, string.substring(iStart, i.getIndex())), "unquote", //$NON-NLS-1$ token);
private String getUnicodeString(String key) { StringCharacterIterator iter= new StringCharacterIterator(key); StringBuilder result= new StringBuilder(); while (iter.getIndex() < iter.getEndIndex()) { char c= iter.current(); if (c == '\\') { iter.next(); c= iter.current(); if (c == 'u') { StringBuilder unicode= new StringBuilder(); unicode.append(iter.next()); unicode.append(iter.next()); unicode.append(iter.next()); unicode.append(iter.next()); c= (char)Integer.parseInt(unicode.toString(), 16); } } result.append(c); iter.next(); } return result.toString(); }
private String getUnicodeString(String key) { StringCharacterIterator iter= new StringCharacterIterator(key); StringBuffer result= new StringBuffer(); while (iter.getIndex() < iter.getEndIndex()) { char c= iter.current(); if (c == '\\') { iter.next(); c= iter.current(); if (c == 'u') { StringBuffer unicode= new StringBuffer(); unicode.append(iter.next()); unicode.append(iter.next()); unicode.append(iter.next()); unicode.append(iter.next()); c= (char)Integer.parseInt(unicode.toString(), 16); } } result.append(c); iter.next(); } return result.toString(); }
/** * Parses a string according to the format specified for ASCII property lists. * Such strings can contain escape sequences which are unescaped in this method. * * @param s The escaped string according to the ASCII property list format, without leading and trailing quotation marks. * @return The unescaped string in UTF-8 * @throws ParseException The string contains an invalid escape sequence. */ private static synchronized String parseQuotedString(String s) throws ParseException { StringBuilder result = new StringBuilder(); StringCharacterIterator iterator = new StringCharacterIterator(s); char c = iterator.current(); while (iterator.getIndex() < iterator.getEndIndex()) { switch (c) { case '\\': { //An escaped sequence is following result.append(parseEscapedSequence(iterator)); break; } default: { //a normal UTF-8 char result.append(c); break; } } c = iterator.next(); } //Build string return result.toString(); }
private TypeExpressionNode handleExpressionFinished(Node currentNode, Stack<TypeExpressionNode> typeStack, StringCharacterIterator iter, StringBuilder simpleExpression) throws TypeExpressionParsingException { handleSimpleExpression(currentNode, iter, typeStack, simpleExpression); TypeExpressionNode result = null; if (typeStack.isEmpty()) { throw new TypeExpressionParsingException("Invalid empty expression.", iter.getIndex()); } while (!typeStack.isEmpty()) { final TypeExpressionNode node = typeStack.pop(); if (result != null) { node.addChild(result); } result = node; validateNode(result, iter); } return result; }
series.add(parseSingleNumber(dataStr.substring(baseIndex, iterator.getIndex()), min, max)); baseIndex = iterator.getIndex() + 1; iterator.next(); series.add(parseSingleNumber(dataStr.substring(baseIndex, iterator.getIndex()), min, max)); baseIndex = iterator.getIndex() + 1; dataset.add(series); series = new java.util.ArrayList(); series.add(parseSingleNumber(dataStr.substring(baseIndex, iterator.getIndex()), min, max)); dataset.add(series); return dataset;
int iStart = i.getIndex(); char ch = decodeEscapeSequence(i); if (ch != StringCharacterIterator.DONE) { BasicEnvironment benv = getEnvironment(); benv.problem(ProblemHandler.Severity.ERROR, ProblemHandler.Phase.PARSER, OCLMessages .bind(OCLMessages.InvalidEscapeSequence_ERROR, string.substring(iStart, i.getIndex())), "unquote", //$NON-NLS-1$ token);
private String getUnicodeString(String key) { StringCharacterIterator iter= new StringCharacterIterator(key); StringBuffer result= new StringBuffer(); while (iter.getIndex() < iter.getEndIndex()) { char c= iter.current(); if (c == '\\') { iter.next(); c= iter.current(); if (c == 'u') { StringBuffer unicode= new StringBuffer(); unicode.append(iter.next()); unicode.append(iter.next()); unicode.append(iter.next()); unicode.append(iter.next()); c= (char)Integer.parseInt(unicode.toString(), 16); } } result.append(c); iter.next(); } return result.toString(); }
throw new ParseException("The property list contains a string with an invalid escape sequence: \\" + c + unicodeValue, iterator.getIndex() - 4); throw new ParseException("The property list contains a string with an invalid escape sequence: \\" + num, iterator.getIndex() - 2); throw new ParseException("The property list contains a string with an invalid escape sequence: \\" + c, iterator.getIndex());
int save = iterator.getIndex(); String ampersand_tag = isAmpersandTag(text, save);
int save = iterator.getIndex(); String ampersand_tag = isAmpersandTag(text, save);
final Position startPosition = currentNode.getStartPosition().rightShift(iter.getIndex() - expressionString.length()); final Position endPosition = currentNode.getStartPosition().rightShift(iter.getIndex()); final Node parse = nodeReferenceFactory.parse(currentNode, expressionString, iter.getIndex()); if (parse instanceof ErrorNode)
final Position startPosition = currentNode.getStartPosition().rightShift(iter.getIndex() - expressionString.length()); final Position endPosition = currentNode.getStartPosition().rightShift(iter.getIndex()); final Node parse = nodeReferenceFactory.parse(currentNode, expressionString, iter.getIndex()); if (parse instanceof ErrorNode)
if (expressionStack.isEmpty()) throw new TypeExpressionParsingException("Expecting a type expression before |.", iter.getIndex()); if (expressionStack.isEmpty()) throw new TypeExpressionParsingException("Expecting a type expression before [.", iter.getIndex()); throw new TypeExpressionParsingException("Invalid character '" + iter.current() + "' expecting ']'.", iter.getIndex()); throw new TypeExpressionParsingException("Parenthesis are not correctly balanced.", iter.getIndex());