Преглед на файлове

cmXml.h/c : Added cmXmlHasChild() and cmXmlNodeDouble().

master
Kevin Larke преди 8 години
родител
ревизия
dd03627898
променени са 2 файла, в които са добавени 38 реда и са изтрити 13 реда
  1. 26
    6
      cmXml.c
  2. 12
    7
      cmXml.h

+ 26
- 6
cmXml.c Целия файл

@@ -169,6 +169,7 @@ cmXmlNode_t* _cmXmlNodeAlloc( cmXml_t* p, unsigned flags, const cmChar_t* label,
169 169
   if( label != NULL )
170 170
     np->label = cmLhAllocStrN(p->heapH,label,labelN);
171 171
 
172
+  np->line  = p->line;
172 173
   np->flags = flags;
173 174
 
174 175
   return np;
@@ -992,14 +993,33 @@ cmXmlRC_t          cmXmlNodeDouble(const cmXmlNode_t* np, double* retRef, ...)
992 993
 
993 994
 }
994 995
 
995
-bool    cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label )
996
+bool    cmXmlNodeHasChildV( const cmXmlNode_t* np, const cmChar_t* label, va_list vl )
996 997
 {
997
-  const cmXmlNode_t* cnp = np->children;
998
-  for(; cnp!=NULL; cnp=cnp->sibling)
999
-    if( cmTextCmp(cnp->label,label) == 0 )
1000
-      return true;
998
+  const cmChar_t* str = NULL;
999
+
1000
+  // get next label to match
1001
+  while( (str = va_arg(vl,const cmChar_t*)) == NULL )
1002
+  {
1003
+    np = np->children;
1004
+    for(; np!=NULL; np=np->sibling)
1005
+      if( cmTextCmp(np->label,label) == 0 )
1006
+        break;
1007
+
1008
+    // if the end of the child list was encountered - with no match
1009
+    if( np == NULL )
1010
+      return false;
1011
+  }
1001 1012
 
1002
-  return false;
1013
+  return true;
1014
+}
1015
+
1016
+bool    cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label, ... )
1017
+{
1018
+  va_list vl;
1019
+  va_start(vl,label);
1020
+  bool fl = cmXmlNodeHasChildV(np,label,vl);
1021
+  va_end(vl);
1022
+  return fl;
1003 1023
 }
1004 1024
 
1005 1025
 

+ 12
- 7
cmXml.h Целия файл

@@ -35,6 +35,7 @@ extern "C" {
35 35
   
36 36
   typedef struct cmXmlNode_str
37 37
   {
38
+    unsigned              line;     // line number
38 39
     unsigned              flags;    // See k???XmlFl
39 40
     
40 41
     const cmChar_t*       label;    // node label
@@ -62,26 +63,30 @@ extern "C" {
62 63
   const cmXmlNode_t* cmXmlRoot(  cmXmlH_t h );
63 64
   void               cmXmlPrint( cmXmlH_t h, cmRpt_t* rpt );
64 65
 
65
-  const cmXmlNode_t* cmXmlSearch( const cmXmlNode_t* np, const cmChar_t* label, const cmXmlAttr_t* attrV, unsigned attrN );
66
+  const cmXmlNode_t* cmXmlSearch(     const cmXmlNode_t* np, const cmChar_t* label, const cmXmlAttr_t* attrV, unsigned attrN );
66 67
   const cmXmlAttr_t* cmXmlFindAttrib( const cmXmlNode_t* np, const cmChar_t* label );
67 68
 
68 69
   cmXmlRC_t          cmXmlAttrInt(  const cmXmlNode_t* np, const cmChar_t* attrLabel, int* retRef );
69 70
   cmXmlRC_t          cmXmlAttrUInt( const cmXmlNode_t* np, const cmChar_t* attrLabel, unsigned* retRef );
70 71
   
71 72
   // Return the data value for a node or attributes.
72
-  // List Syntax: node-label-0, node-label-1, NULL, attr-label-0 attr-label-1 
73
+  // Terminate node label list with NULL.
73 74
   const cmChar_t*    cmXmlNodeValueV( const cmXmlNode_t* np, va_list vl );
74 75
   const cmChar_t*    cmXmlNodeValue( const cmXmlNode_t* np, ... );
75 76
 
76
-  cmXmlRC_t          cmXmlNodeIntV(    const cmXmlNode_t* np, int* retRef, va_list vl );
77
+  // Terminate node label list with NULL.
78
+  cmXmlRC_t          cmXmlNodeIntV(    const cmXmlNode_t* np, int*      retRef, va_list vl );
77 79
   cmXmlRC_t          cmXmlNodeUIntV(   const cmXmlNode_t* np, unsigned* retRef, va_list vl );
78 80
   cmXmlRC_t          cmXmlNodeDoubleV( const cmXmlNode_t* np, double*   retRef, va_list vl );
79 81
 
80
-  cmXmlRC_t          cmXmlNodeInt(   const cmXmlNode_t* np, int* retRef, ... );
82
+  // Terminate node label list with NULL.
83
+  cmXmlRC_t          cmXmlNodeInt(   const cmXmlNode_t* np, int*      retRef, ... );
81 84
   cmXmlRC_t          cmXmlNodeUInt(  const cmXmlNode_t* np, unsigned* retRef, ... );
82
-  cmXmlRC_t          cmXmlNodeDouble(const cmXmlNode_t* np, double* retRef, ...);
83
-  
84
-  bool               cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label );
85
+  cmXmlRC_t          cmXmlNodeDouble(const cmXmlNode_t* np, double*   retRef, ... );
86
+
87
+  // Terminate node label list with NULL.
88
+  bool               cmXmlNodeHasChildV(const cmXmlNode_t* np, const cmChar_t* label, va_list vl );
89
+  bool               cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label, ... );
85 90
 
86 91
   
87 92
   cmXmlRC_t cmXmlTest( cmCtx_t* ctx, const cmChar_t* fn );

Loading…
Отказ
Запис