Changeset 22173 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 11, 2009 3:38:59 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50951
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/xml.cpp
r21428 r22173 497 497 } 498 498 499 bool Node::nameEquals(const char *pcsz) const 500 { 501 if (m->pcszName == pcsz) 502 return true; 503 if (m->pcszName == NULL) 504 return false; 505 if (pcsz == NULL) 506 return false; 507 return !strcmp(m->pcszName, pcsz); 508 } 509 510 499 511 /** 500 512 * Returns the value of a node. If this node is an attribute, returns … … 732 744 /** 733 745 * Convenience method which attempts to find the attribute with the given 746 * name and returns its value as a string. 747 * 748 * @param pcszMatch name of attribute to find. 749 * @param str out: attribute value 750 * @return TRUE if attribute was found and str was thus updated. 751 */ 752 bool ElementNode::getAttributeValue(const char *pcszMatch, iprt::MiniString &str) const 753 { 754 const Node* pAttr; 755 if ((pAttr = findAttribute(pcszMatch))) 756 { 757 str = pAttr->getValue(); 758 return true; 759 } 760 761 return false; 762 } 763 764 /** 765 * Convenience method which attempts to find the attribute with the given 766 * name and returns its value as a signed integer. This calls 767 * RTStrToInt32Ex internally and will only output the integer if that 768 * function returns no error. 769 * 770 * @param pcszMatch name of attribute to find. 771 * @param i out: attribute value 772 * @return TRUE if attribute was found and str was thus updated. 773 */ 774 bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t &i) const 775 { 776 const char *pcsz; 777 if ( (getAttributeValue(pcszMatch, pcsz)) 778 && (VINF_SUCCESS == RTStrToInt32Ex(pcsz, NULL, 0, &i)) 779 ) 780 return true; 781 782 return false; 783 } 784 785 /** 786 * Convenience method which attempts to find the attribute with the given 787 * name and returns its value as an unsigned integer.This calls 788 * RTStrToUInt32Ex internally and will only output the integer if that 789 * function returns no error. 790 * 791 * @param pcszMatch name of attribute to find. 792 * @param i out: attribute value 793 * @return TRUE if attribute was found and str was thus updated. 794 */ 795 bool ElementNode::getAttributeValue(const char *pcszMatch, uint32_t &i) const 796 { 797 const char *pcsz; 798 if ( (getAttributeValue(pcszMatch, pcsz)) 799 && (VINF_SUCCESS == RTStrToUInt32Ex(pcsz, NULL, 0, &i)) 800 ) 801 return true; 802 803 return false; 804 } 805 806 /** 807 * Convenience method which attempts to find the attribute with the given 734 808 * name and returns its value as a signed long integer. This calls 735 809 * RTStrToInt64Ex internally and will only output the integer if that … … 744 818 const char *pcsz; 745 819 if ( (getAttributeValue(pcszMatch, pcsz)) 746 && (VINF_SUCCESS == RTStrToInt64Ex(pcsz, NULL, 10, &i))820 && (VINF_SUCCESS == RTStrToInt64Ex(pcsz, NULL, 0, &i)) 747 821 ) 748 822 return true; … … 765 839 const char *pcsz; 766 840 if ( (getAttributeValue(pcszMatch, pcsz)) 767 && (VINF_SUCCESS == RTStrToUInt64Ex(pcsz, NULL, 10, &i))841 && (VINF_SUCCESS == RTStrToUInt64Ex(pcsz, NULL, 0, &i)) 768 842 ) 769 843 return true; 844 845 return false; 846 } 847 848 /** 849 * Convenience method which attempts to find the attribute with the given 850 * name and returns its value as a boolean. This accepts "true", "false", 851 * "yes", "no", "1" or "0" as valid values. 852 * 853 * @param pcszMatch name of attribute to find. 854 * @param i out: attribute value 855 * @return TRUE if attribute was found and str was thus updated. 856 */ 857 bool ElementNode::getAttributeValue(const char *pcszMatch, bool &f) const 858 { 859 const char *pcsz; 860 if (getAttributeValue(pcszMatch, pcsz)) 861 { 862 if ( (!strcmp(pcsz, "true")) 863 || (!strcmp(pcsz, "yes")) 864 || (!strcmp(pcsz, "1")) 865 ) 866 { 867 f = true; 868 return true; 869 } 870 if ( (!strcmp(pcsz, "false")) 871 || (!strcmp(pcsz, "no")) 872 || (!strcmp(pcsz, "0")) 873 ) 874 { 875 f = false; 876 return true; 877 } 878 } 770 879 771 880 return false; … … 870 979 } 871 980 981 AttributeNode* ElementNode::setAttribute(const char *pcszName, int32_t i) 982 { 983 char *psz = NULL; 984 RTStrAPrintf(&psz, "%RI32", i); 985 AttributeNode *p = setAttribute(pcszName, psz); 986 RTStrFree(psz); 987 return p; 988 } 989 990 AttributeNode* ElementNode::setAttribute(const char *pcszName, uint32_t i) 991 { 992 char *psz = NULL; 993 RTStrAPrintf(&psz, "%RU32", i); 994 AttributeNode *p = setAttribute(pcszName, psz); 995 RTStrFree(psz); 996 return p; 997 } 998 999 AttributeNode* ElementNode::setAttribute(const char *pcszName, int64_t i) 1000 { 1001 char *psz = NULL; 1002 RTStrAPrintf(&psz, "%RI64", i); 1003 AttributeNode *p = setAttribute(pcszName, psz); 1004 RTStrFree(psz); 1005 return p; 1006 } 1007 1008 AttributeNode* ElementNode::setAttribute(const char *pcszName, uint64_t i) 1009 { 1010 char *psz = NULL; 1011 RTStrAPrintf(&psz, "%RU64", i); 1012 AttributeNode *p = setAttribute(pcszName, psz); 1013 RTStrFree(psz); 1014 return p; 1015 } 1016 1017 AttributeNode* ElementNode::setAttributeHex(const char *pcszName, uint32_t i) 1018 { 1019 char *psz = NULL; 1020 RTStrAPrintf(&psz, "0x%RX32", i); 1021 AttributeNode *p = setAttribute(pcszName, psz); 1022 RTStrFree(psz); 1023 return p; 1024 } 1025 1026 AttributeNode* ElementNode::setAttribute(const char *pcszName, bool f) 1027 { 1028 return setAttribute(pcszName, (f) ? "true" : "false"); 1029 } 872 1030 873 1031 AttributeNode::AttributeNode() … … 910 1068 * NULL, like this: 911 1069 * <code> 912 * xml:: Node node;// should point to an element1070 * xml::ElementNode node; // should point to an element 913 1071 * xml::NodesLoop loop(node, "child"); // find all "child" elements under node 914 * const xml:: Node *pChild = NULL;1072 * const xml::ElementNode *pChild = NULL; 915 1073 * while (pChild = loop.forAllNodes()) 916 1074 * ...; … … 1018 1176 /** 1019 1177 * Returns the root element of the document, or NULL if the document is empty. 1178 * Const variant. 1020 1179 * @return 1021 1180 */ 1022 1181 const ElementNode* Document::getRootElement() const 1182 { 1183 return m->pRootElement; 1184 } 1185 1186 /** 1187 * Returns the root element of the document, or NULL if the document is empty. 1188 * Non-const variant. 1189 * @return 1190 */ 1191 ElementNode* Document::getRootElement() 1023 1192 { 1024 1193 return m->pRootElement; … … 1151 1320 * @param doc out: document to be reset and filled with data according to file contents. 1152 1321 */ 1153 void XmlFileParser::read(const char *pcszFilename,1322 void XmlFileParser::read(const iprt::MiniString &strFilename, 1154 1323 Document &doc) 1155 1324 { … … 1157 1326 // global.setExternalEntityLoader(ExternalEntityLoader); 1158 1327 1159 m->strXmlFilename = pcszFilename; 1328 m->strXmlFilename = strFilename; 1329 const char *pcszFilename = strFilename.c_str(); 1160 1330 1161 1331 ReadContext context(pcszFilename);
Note:
See TracChangeset
for help on using the changeset viewer.