/** * Parse a dot separated name. * * @param s the sequence * @param from the from index * @param end the end index * @return the parsed identifiers * @throws IllegalArgumentException */ public static String[] parseName(CharSequence s, int from, int end) throws IllegalArgumentException { if (from < 0) { throw new IllegalArgumentException("From bound " + from + " cannot be negative"); } if (from > end) { throw new IllegalArgumentException("From bound " + from + " cannot be greater than the end bound " + end); } if (from == end) { return Name.EMPTY_STRING_ARRAY; } else { return parseName(0, s, from, end); } }
/** * Parse a dot separated name. * * @param s the sequence * @param from the from index * @param end the end index * @return the parsed identifiers * @throws IllegalArgumentException */ public static String[] parseName(CharSequence s, int from, int end) throws IllegalArgumentException { if (from < 0) { throw new IllegalArgumentException("From bound " + from + " cannot be negative"); } if (from > end) { throw new IllegalArgumentException("From bound " + from + " cannot be greater than the end bound " + end); } if (from == end) { return Name.EMPTY_STRING_ARRAY; } else { return parseName(0, s, from, end); } }
private static String[] parseName(int size, CharSequence s, int from, int end) { int next = Tools.indexOf(s, '.', from, end); String[] identifiers; if (next < 0) { if (from == end) { throw new IllegalArgumentException("Empty segment"); } identifiers = new String[size + 1]; identifiers[size] = s.subSequence(from, end).toString(); } else { if (next == from) { throw new IllegalArgumentException("Empty segment"); } identifiers = parseName(size + 1, s, next + 1, end); identifiers[size] = s.subSequence(from, next).toString(); } return identifiers; }
/** * Parse the name. * * @param s the char sequence to parse * @param from the index of the first char of the name * @param end the index of the char after the last char of the name * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s, int from, int end) throws IllegalArgumentException { if (end > s.length()) { throw new IllegalArgumentException("End bound " + end + " cannot be greater than the sequence length " + s.length()); } String[] segments = Lexers.parseName(s, from, end); if (segments.length == 0) { return EMPTY; } else { return new Name(s.subSequence(from, end).toString(), segments); } }
private static String[] parseName(int size, CharSequence s, int from, int end) { int next = Tools.indexOf(s, '.', from, end); String[] identifiers; if (next < 0) { if (from == end) { throw new IllegalArgumentException("Empty segment"); } identifiers = new String[size + 1]; identifiers[size] = s.subSequence(from, end).toString(); } else { if (next == from) { throw new IllegalArgumentException("Empty segment"); } identifiers = parseName(size + 1, s, next + 1, end); identifiers[size] = s.subSequence(from, next).toString(); } return identifiers; }
/** * Parse the name. * * @param s the char sequence to parse * @param from the index of the first char of the name * @param end the index of the char after the last char of the name * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s, int from, int end) throws IllegalArgumentException { if (end > s.length()) { throw new IllegalArgumentException("End bound " + end + " cannot be greater than the sequence length " + s.length()); } String[] segments = Lexers.parseName(s, from, end); if (segments.length == 0) { return EMPTY; } else { return new Name(s.subSequence(from, end).toString(), segments); } }