XMLTreeUtil { public static int indexOfAttributeName(byte[] src, byte[] target, int fromIdx) { final int idx = indexOf(src, target, fromIdx); if (idx == -1) { return -1; } final int next = idx + target.length; if (next == src.length || isWhitespace(src[next]) || src[next] == '=') { return idx; } return indexOfAttributeName(src, target, idx + 1); } private  XMLTreeUtil(); static byte[] insertBetween(byte[] src, int left, int right, String content); static byte[] insertInto(byte[] src, int pos, String content); static T single(List<T> target); static int lastIndexOf(byte[] src, char c, int fromIdx); static int level(Element element); static int openTagLength(NewElement element); static int closeTagLength(NewElement element); static int attributeLength(NewAttribute attribute); static String tabulate(String src, int tabsCount); static Element asElement(Node node); static List<Element> asElements(NodeList list); static List<R> asElements(NodeList list, ElementMapper<? extends R> mapper); static int indexOf(byte[] src, byte[] target, int fromIdx); static int indexOfAttributeName(byte[] src, byte[] target, int fromIdx); static byte[] replaceAll(byte[] src, byte[] target, byte[] replacement); static int rootStart(byte[] xml); static final Charset UTF_8; static final int SPACES_IN_TAB; }
@Test public void shouldReturnMinusOneIfAttributeNameBytesWereNotFound() { final String src = "<element attribute12=\"value1\"/>"; final byte[] byteSrc = src.getBytes(); assertEquals(indexOfAttributeName(byteSrc, "attribute1".getBytes(), 0), -1); }