Java tutorial
//package com.java2s; //License from project: Common Public License import java.util.List; public class Main { /** * @param domainsAtt * @param i * @param propsAtts * @return */ private static int parsePropsDomain(String domainsAtt, int p, List<String> propsAtts) { if (p >= domainsAtt.length()) { throw new RuntimeException( "Unexpected end of string, expected '(' in domains attribute value \"" + domainsAtt + "\""); } char c = domainsAtt.charAt(p++); if (c != '(') { throw new RuntimeException("Expected '(' following 'a', found '" + c + "' at position " + p + " in domains attribute value \"" + domainsAtt + "\""); } StringBuilder buf = new StringBuilder(); boolean done = false; while (!done && p < domainsAtt.length()) { c = domainsAtt.charAt(p); switch (c) { case ')': p++; done = true; break; default: buf.append(c); p++; } } if (!done) { throw new RuntimeException( "Unexpected end of string, expected ')' in domains attribute value \"" + domainsAtt + "\""); } String[] tokens = buf.toString().trim().split(" "); if (tokens.length < 2) { throw new RuntimeException("Expected two tokens in attribute domain declaration, found " + tokens.length + " in domains attribute value \"" + domainsAtt + "\""); } if ("props".equals(tokens[0])) { propsAtts.add(tokens[tokens.length - 1]); } return p; } }