in resources/src/main/java/org/robolectric/res/android/ResXMLParser.java [393:479]
public int indexOfAttribute(final String ns, int nsLen,
final String attr, int attrLen)
{
if (mEventCode == START_TAG) {
if (attr == null) {
return NAME_NOT_FOUND;
}
final int N = getAttributeCount();
if (mTree.mStrings.isUTF8()) {
String8 ns8 = null, attr8;
if (ns != null) {
ns8 = new String8(ns, nsLen);
}
attr8 = new String8(attr, attrLen);
if (kDebugStringPoolNoisy) {
ALOGI("indexOfAttribute UTF8 %s (0x%x) / %s (0x%x)", ns8.string(), nsLen,
attr8.string(), attrLen);
}
for (int i=0; i<N; i++) {
final Ref<Integer> curNsLen = new Ref<>(0), curAttrLen = new Ref<>(0);
final String curNs = getAttributeNamespace8(i, curNsLen);
final String curAttr = getAttributeName8(i, curAttrLen);
if (kDebugStringPoolNoisy) {
ALOGI(" curNs=%s (0x%x), curAttr=%s (0x%x)", curNs, curNsLen, curAttr, curAttrLen);
}
if (curAttr != null && curNsLen.get() == nsLen && curAttrLen.get() == attrLen
&& memcmp(attr8.string(), curAttr, attrLen) == 0) {
if (ns == null) {
if (curNs == null) {
if (kDebugStringPoolNoisy) {
ALOGI(" FOUND!");
}
return i;
}
} else if (curNs != null) {
//printf(" -. ns=%s, curNs=%s\n",
// String8(ns).string(), String8(curNs).string());
if (memcmp(ns8.string(), curNs, nsLen) == 0) {
if (kDebugStringPoolNoisy) {
ALOGI(" FOUND!");
}
return i;
}
}
}
}
} else {
if (kDebugStringPoolNoisy) {
ALOGI("indexOfAttribute UTF16 %s (0x%x) / %s (0x%x)",
ns /*String8(ns, nsLen).string()*/, nsLen,
attr /*String8(attr, attrLen).string()*/, attrLen);
}
for (int i=0; i<N; i++) {
final Ref<Integer> curNsLen = new Ref<>(0), curAttrLen = new Ref<>(0);
final String curNs = getAttributeNamespace(i, curNsLen);
final String curAttr = getAttributeName(i, curAttrLen);
if (kDebugStringPoolNoisy) {
ALOGI(" curNs=%s (0x%x), curAttr=%s (0x%x)",
curNs /*String8(curNs, curNsLen).string()*/, curNsLen,
curAttr /*String8(curAttr, curAttrLen).string()*/, curAttrLen);
}
if (curAttr != null && curNsLen.get() == nsLen && curAttrLen.get() == attrLen
&& (memcmp(attr, curAttr, attrLen*SIZEOF_CHAR/*sizeof(char16_t)*/) == 0)) {
if (ns == null) {
if (curNs == null) {
if (kDebugStringPoolNoisy) {
ALOGI(" FOUND!");
}
return i;
}
} else if (curNs != null) {
//printf(" -. ns=%s, curNs=%s\n",
// String8(ns).string(), String8(curNs).string());
if (memcmp(ns, curNs, nsLen*SIZEOF_CHAR/*sizeof(char16_t)*/) == 0) {
if (kDebugStringPoolNoisy) {
ALOGI(" FOUND!");
}
return i;
}
}
}
}
}
}
return NAME_NOT_FOUND;
}