/*! \brief Reads the data of the specified attribute into the pre-allocated \a result. \param name the name of the attribute \param result the BString to be set to the value of the attribute \return - \c B_OK: Everything went fine. - \c B_BAD_VALUE: \c NULL \a name or \a result - \c B_FILE_ERROR: The object is not initialized. - \c B_ENTRY_NOT_FOUND: The node has no attribute \a attr. */ status_t BNode::ReadAttrString(const char *name, BString *result) const { if (!name || !result) return B_BAD_VALUE; attr_info info; status_t error; error = GetAttrInfo(name, &info); if (error != B_OK) return error; // Lock the string's buffer so we can meddle with it char *data = result->LockBuffer(info.size+1); if (!data) return B_NO_MEMORY; // Read the attribute ssize_t bytes = ReadAttr(name, B_STRING_TYPE, 0, data, info.size); // Check for failure if (bytes < 0) { error = bytes; bytes = 0; // In this instance, we simply clear the string } else error = B_OK; // Null terminate the new string just to be sure (since it *is* // possible to read and write non-NULL-terminated strings) data[bytes] = 0; result->UnlockBuffer(); return error; }
void HTMLMenuItemElement::WalkRadioGroup(Visitor* aVisitor) { nsIContent* parent = GetParent(); if (!parent) { aVisitor->Visit(this); return; } nsAttrInfo info1(GetAttrInfo(kNameSpaceID_None, nsGkAtoms::radiogroup)); bool info1Empty = !info1.mValue || info1.mValue->IsEmptyString(); for (nsIContent* cur = parent->GetFirstChild(); cur; cur = cur->GetNextSibling()) { HTMLMenuItemElement* menuitem = HTMLMenuItemElement::FromContent(cur); if (!menuitem || menuitem->GetType() != CMD_TYPE_RADIO) { continue; } nsAttrInfo info2(menuitem->GetAttrInfo(kNameSpaceID_None, nsGkAtoms::radiogroup)); bool info2Empty = !info2.mValue || info2.mValue->IsEmptyString(); if (info1Empty != info2Empty || (info1.mValue && info2.mValue && !info1.mValue->Equals(*info2.mValue))) { continue; } if (!aVisitor->Visit(menuitem)) { break; } } }