VirtualBox

Changeset 49028 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Oct 10, 2013 12:55:06 PM (11 years ago)
Author:
vboxsync
Message:

iprt/cpp/xml: Fixed attribute lookup with namespace by doing the same way as for elements. Also renamed the two methods with namespace prefix and name in the 'logical' order so they can safely be changed to the order dictated C++ default parameter value handling (name first, then optionally ns-prefix), like the rest.

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/zip/xarvfs.cpp

    r48868 r49028  
    19261926                    xml::ElementNode const *pTocElem  = NULL;
    19271927                    if (pRootElem && pRootElem->nameEquals("xar"))
    1928                         pTocElem = pRootElem ? pRootElem->findChildElement(NULL, "toc") : NULL;
     1928                        pTocElem = pRootElem ? pRootElem->findChildElement("toc") : NULL;
    19291929                    if (pTocElem)
    19301930                    {
  • trunk/src/VBox/Runtime/r3/xml.cpp

    r48935 r49028  
    484484 * @return
    485485 */
    486 bool Node::nameEquals(const char *pcszNamespace, const char *pcsz) const
     486bool Node::nameEqualsNS(const char *pcszNamespace, const char *pcsz) const
    487487{
    488488    if (m_pcszName == pcsz)
     
    508508 * Variant of nameEquals that checks the namespace as well.
    509509 *
    510  * @return  true if equal, false if not.
    511  * @param   pcszNamespace   The name space prefix or NULL.
     510 * @returns true if equal, false if not.
    512511 * @param   pcsz            The element name.
    513512 * @param   cchMax          The maximum number of character from @a pcsz to
    514513 *                          match.
    515  */
    516 bool Node::nameEqualsN(const char *pcszNamespace, const char *pcsz, size_t cchMax) const
     514 * @param   pcszNamespace   The name space prefix or NULL (default).
     515 */
     516bool Node::nameEqualsN(const char *pcsz, size_t cchMax, const char *pcszNamespace /* = NULL*/) const
    517517{
    518518    /* Match the name. */
     
    793793 * @return
    794794 */
    795 const ElementNode *ElementNode::findChildElement(const char *pcszNamespace, const char *pcszMatch) const
     795const ElementNode *ElementNode::findChildElementNS(const char *pcszNamespace, const char *pcszMatch) const
    796796{
    797797    Node *p;
     
    801801        {
    802802            ElementNode *pelm = static_cast<ElementNode*>(p);
    803             if (pelm->nameEquals(pcszNamespace, pcszMatch))
     803            if (pelm->nameEqualsNS(pcszNamespace, pcszMatch))
    804804                return pelm;
    805805        }
     
    834834    size_t cchThis = strchr(pcszPath, '/') - pcszPath;
    835835    if (cchThis == (size_t)((const char *)0 - pcszPath))
    836         return this->findChildElement(pcszNamespace, pcszPath);
     836        return findChildElementNS(pcszNamespace, pcszPath);
    837837
    838838    /** @todo Can be done without recursion as we have both sibling lists and parent
     
    844844        {
    845845            const ElementNode *pElm = static_cast<const ElementNode *>(p);
    846             if (pElm->nameEqualsN(pcszNamespace, pcszPath, cchThis))
     846            if (pElm->nameEqualsN(pcszPath, cchThis, pcszNamespace))
    847847            {
    848848                pElm = findChildElementP(pcszPath + cchThis, pcszNamespace);
     
    921921        {
    922922            const ElementNode *pElem = static_cast<const ElementNode *>(pSibling);
    923             if (pElem->nameEquals(pcszNamespace, pcszMatch))
     923            if (pElem->nameEqualsNS(pcszNamespace, pcszMatch))
    924924                return pElem;
    925925        }
     
    940940        {
    941941            const ElementNode *pElem = static_cast<const ElementNode *>(pSibling);
    942             if (pElem->nameEquals(pcszNamespace, pcszMatch))
     942            if (pElem->nameEqualsNS(pcszNamespace, pcszMatch))
    943943                return pElem;
    944944        }
     
    950950 * Looks up the given attribute node in this element's attribute map.
    951951 *
    952  * With respect to namespaces, the internal attributes map stores namespace
    953  * prefixes with attribute names only if the attribute uses a non-default
    954  * namespace. As a result, the following rules apply:
    955  *
    956  *  -- To find attributes from a non-default namespace, pcszMatch must not
    957  *     be prefixed with a namespace.
    958  *
    959  *  -- To find attributes from the default namespace (or if the document does
    960  *     not use namespaces), pcszMatch must be prefixed with the namespace
    961  *     prefix and a colon.
    962  *
    963  * For example, if the document uses the "vbox:" namespace by default, you
    964  * must omit "vbox:" from pcszMatch to find such attributes, whether they
    965  * are specifed in the xml or not.
    966  *
    967  * @param pcszMatch
    968  * @return
    969  */
    970 const AttributeNode *ElementNode::findAttribute(const char *pcszMatch) const
     952 * @param   pcszMatch       The name of the attribute to find.
     953 * @param   pcszNamespace   The attribute name space prefix or NULL.
     954 */
     955const AttributeNode *ElementNode::findAttribute(const char *pcszMatch, const char *pcszNamespace /*= NULL*/) const
    971956{
    972957    AttributeNode *p;
    973958    RTListForEachCpp(&m_attributes, p, AttributeNode, m_listEntry)
    974959    {
    975         if (p->nameEquals(pcszMatch))
     960        if (p->nameEqualsNS(pcszNamespace, pcszMatch))
    976961            return p;
    977962    }
     
    983968 * name and returns its value as a string.
    984969 *
    985  * @param   pcszMatch   Name of attribute to find (see findAttribute() for
    986  *                      namespace remarks).
    987  * @param   ppcsz       Where to return the attribute.
     970 * @param   pcszMatch       Name of attribute to find.
     971 * @param   ppcsz           Where to return the attribute.
     972 * @param   pcszNamespace   The attribute name space prefix or NULL.
    988973 * @returns Boolean success indicator.
    989974 */
    990 bool ElementNode::getAttributeValue(const char *pcszMatch, const char **ppcsz) const
    991 {
    992     const AttributeNode *pAttr = findAttribute(pcszMatch);
     975bool ElementNode::getAttributeValue(const char *pcszMatch, const char **ppcsz, const char *pcszNamespace /*= NULL*/) const
     976{
     977    const AttributeNode *pAttr = findAttribute(pcszMatch, pcszNamespace);
    993978    if (pAttr)
    994979    {
     
    1003988 * name and returns its value as a string.
    1004989 *
    1005  * @param   pcszMatch   Name of attribute to find (see findAttribute() for
    1006  *                      namespace remarks).
    1007  * @param   rStr        Reference to the string object that should receive the
    1008  *                      attribute value.
     990 * @param   pcszMatch       Name of attribute to find.
     991 * @param   pStr            Pointer to the string object that should receive the
     992 *                          attribute value.
     993 * @param   pcszNamespace   The attribute name space prefix or NULL.
    1009994 * @returns Boolean success indicator.
    1010995 *
    1011996 * @throws  Whatever the string class may throw on assignment.
    1012997 */
    1013 bool ElementNode::getAttributeValue(const char *pcszMatch, RTCString &rStr) const
    1014 {
    1015     const AttributeNode *pAttr = findAttribute(pcszMatch);
     998bool ElementNode::getAttributeValue(const char *pcszMatch, RTCString *pStr, const char *pcszNamespace /*= NULL*/) const
     999{
     1000    const AttributeNode *pAttr = findAttribute(pcszMatch, pcszNamespace);
    10161001    if (pAttr)
    10171002    {
    1018         rStr = pAttr->getValue();
     1003        *pStr = pAttr->getValue();
    10191004        return true;
    10201005    }
     
    10261011 * Like getAttributeValue (ministring variant), but makes sure that all backslashes
    10271012 * are converted to forward slashes.
    1028  * @param pcszMatch
    1029  * @param str
    1030  * @return
    1031  */
    1032 bool ElementNode::getAttributeValuePath(const char *pcszMatch, RTCString &str) const
    1033 {
    1034     if (getAttributeValue(pcszMatch, str))
    1035     {
    1036         str.findReplace('\\', '/');
     1013 *
     1014 * @param   pcszMatch       Name of attribute to find.
     1015 * @param   pStr            Pointer to the string object that should
     1016 *                          receive the attribute path value.
     1017 * @param   pcszNamespace   The attribute name space prefix or NULL.
     1018 * @returns Boolean success indicator.
     1019 */
     1020bool ElementNode::getAttributeValuePath(const char *pcszMatch, RTCString *pStr, const char *pcszNamespace /*= NULL*/) const
     1021{
     1022    if (getAttributeValue(pcszMatch, pStr, pcszNamespace))
     1023    {
     1024        pStr->findReplace('\\', '/');
    10371025        return true;
    10381026    }
     
    10431031/**
    10441032 * Convenience method which attempts to find the attribute with the given
    1045  * name and returns its value as a signed integer. This calls
    1046  * RTStrToInt32Ex internally and will only output the integer if that
    1047  * function returns no error.
    1048  *
    1049  * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)
    1050  * @param i out: attribute value; overwritten only if attribute was found
    1051  * @return TRUE if attribute was found and str was thus updated.
    1052  */
    1053 bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t &i) const
    1054 {
    1055     const char *pcsz;
    1056     if (    (getAttributeValue(pcszMatch, pcsz))
    1057          && (VINF_SUCCESS == RTStrToInt32Ex(pcsz, NULL, 0, &i))
    1058        )
    1059         return true;
    1060 
     1033 * name and returns its value as a signed 32-bit integer.
     1034 *
     1035 * @param   pcszMatch       Name of attribute to find.
     1036 * @param   piValue         Where to return the value.
     1037 * @param   pcszNamespace   The attribute name space prefix or NULL.
     1038 * @returns Boolean success indicator.
     1039 */
     1040bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t *piValue, const char *pcszNamespace /*= NULL*/) const
     1041{
     1042    const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace);
     1043    if (pcsz)
     1044    {
     1045        int rc = RTStrToInt32Ex(pcsz, NULL, 0, piValue);
     1046        if (rc == VINF_SUCCESS)
     1047            return true;
     1048    }
    10611049    return false;
    10621050}
     
    10641052/**
    10651053 * Convenience method which attempts to find the attribute with the given
    1066  * name and returns its value as an unsigned integer.This calls
    1067  * RTStrToUInt32Ex internally and will only output the integer if that
    1068  * function returns no error.
    1069  *
    1070  * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)
    1071  * @param i out: attribute value; overwritten only if attribute was found
    1072  * @return TRUE if attribute was found and str was thus updated.
    1073  */
    1074 bool ElementNode::getAttributeValue(const char *pcszMatch, uint32_t &i) const
    1075 {
    1076     const char *pcsz;
    1077     if (    (getAttributeValue(pcszMatch, pcsz))
    1078          && (VINF_SUCCESS == RTStrToUInt32Ex(pcsz, NULL, 0, &i))
    1079        )
    1080         return true;
    1081 
     1054 * name and returns its value as an unsigned 32-bit integer.
     1055 *
     1056 * @param   pcszMatch       Name of attribute to find.
     1057 * @param   puValue         Where to return the value.
     1058 * @param   pcszNamespace   The attribute name space prefix or NULL.
     1059 * @returns Boolean success indicator.
     1060 */
     1061bool ElementNode::getAttributeValue(const char *pcszMatch, uint32_t *puValue, const char *pcszNamespace /*= NULL*/) const
     1062{
     1063    const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace);
     1064    if (pcsz)
     1065    {
     1066        int rc = RTStrToUInt32Ex(pcsz, NULL, 0, puValue);
     1067        if (rc == VINF_SUCCESS)
     1068            return true;
     1069    }
    10821070    return false;
    10831071}
     
    10851073/**
    10861074 * Convenience method which attempts to find the attribute with the given
    1087  * name and returns its value as a signed long integer. This calls
    1088  * RTStrToInt64Ex internally and will only output the integer if that
    1089  * function returns no error.
    1090  *
    1091  * @param   pcszMatch   Name of attribute to find (see findAttribute() for
    1092  *                      namespace remarks).
    1093  * @param   i           Where to return the attribute value on success.
     1075 * name and returns its value as a signed 64-bit integer.
     1076 *
     1077 * @param   pcszMatch       Name of attribute to find.
     1078 * @param   piValue         Where to return the value.
     1079 * @param   pcszNamespace   The attribute name space prefix or NULL.
    10941080 * @returns Boolean success indicator.
    10951081 */
    1096 bool ElementNode::getAttributeValue(const char *pcszMatch, int64_t *piValue) const
    1097 {
    1098     const char *pcsz = findAttributeValue(pcszMatch);
     1082bool ElementNode::getAttributeValue(const char *pcszMatch, int64_t *piValue, const char *pcszNamespace /*= NULL*/) const
     1083{
     1084    const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace);
    10991085    if (pcsz)
    11001086    {
     
    11081094/**
    11091095 * Convenience method which attempts to find the attribute with the given
    1110  * name and returns its value as an unsigned long integer.This calls
    1111  * RTStrToUInt64Ex internally and will only output the integer if that
    1112  * function returns no error.
    1113  *
    1114  * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)
    1115  * @param i out: attribute value; overwritten only if attribute was found
    1116  * @return TRUE if attribute was found and str was thus updated.
    1117  */
    1118 bool ElementNode::getAttributeValue(const char *pcszMatch, uint64_t &i) const
    1119 {
    1120     const char *pcsz;
    1121     if (    (getAttributeValue(pcszMatch, pcsz))
    1122          && (VINF_SUCCESS == RTStrToUInt64Ex(pcsz, NULL, 0, &i))
    1123        )
    1124         return true;
    1125 
     1096 * name and returns its value as an unsigned 64-bit integer.
     1097 *
     1098 * @param   pcszMatch       Name of attribute to find.
     1099 * @param   puValue         Where to return the value.
     1100 * @param   pcszNamespace   The attribute name space prefix or NULL.
     1101 * @returns Boolean success indicator.
     1102 */
     1103bool ElementNode::getAttributeValue(const char *pcszMatch, uint64_t *puValue, const char *pcszNamespace /*= NULL*/) const
     1104{
     1105    const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace);
     1106    if (pcsz)
     1107    {
     1108        int rc = RTStrToUInt64Ex(pcsz, NULL, 0, puValue);
     1109        if (rc == VINF_SUCCESS)
     1110            return true;
     1111    }
    11261112    return false;
    11271113}
     
    11321118 * "yes", "no", "1" or "0" as valid values.
    11331119 *
    1134  * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)
    1135  * @param f out: attribute value; overwritten only if attribute was found
    1136  * @return TRUE if attribute was found and str was thus updated.
    1137  */
    1138 bool ElementNode::getAttributeValue(const char *pcszMatch, bool &f) const
    1139 {
    1140     const char *pcsz;
    1141     if (getAttributeValue(pcszMatch, pcsz))
     1120 * @param   pcszMatch       Name of attribute to find.
     1121 * @param   pfValue         Where to return the value.
     1122 * @param   pcszNamespace   The attribute name space prefix or NULL.
     1123 * @returns Boolean success indicator.
     1124 */
     1125bool ElementNode::getAttributeValue(const char *pcszMatch, bool *pfValue, const char *pcszNamespace /*= NULL*/) const
     1126{
     1127    const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace);
     1128    if (pcsz)
    11421129    {
    11431130        if (   !strcmp(pcsz, "true")
     
    11461133           )
    11471134        {
    1148             f = true;
     1135            *pfValue = true;
    11491136            return true;
    11501137        }
     
    11541141           )
    11551142        {
    1156             f = false;
     1143            *pfValue = false;
    11571144            return true;
    11581145        }
     
    14831470        m_pcszNamespacePrefix = (const char *)pLibAttr->ns->prefix;
    14841471        m_pcszNamespaceHref   = (const char *)pLibAttr->ns->href;
    1485 
    1486         if (   !pElmRoot->m_pcszNamespaceHref
    1487             || strcmp(m_pcszNamespaceHref, pElmRoot->m_pcszNamespaceHref))
    1488         {
    1489             // not default namespace:
    1490             m_strKey = m_pcszNamespacePrefix;
    1491             m_strKey.append(':');
    1492             m_strKey.append(m_pcszName);
    1493         }
    14941472    }
    14951473}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette