Advertisement
ultiprosan

Equals functies

May 7th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. /**
  2.  * xml_equal
  3.  * Params: Two XML objects
  4.  * Returns: 1 => Objects are equal, 0 => Objects are NOT equal
  5.  */
  6. int xml_equal(xml *elem1, xml *elem2) {
  7.     // Objects of same type?
  8.     if (elem1->tag == elem2->tag) {
  9.         if (isText(elem1)) {
  10.             // Compare Text contents
  11.             return (strcmp(textVal(elem1),textVal(elem2)) == 0);
  12.         }
  13.         if (isElem(elem1)) {
  14.             // Compare both tags and Lists
  15.             if (strcmp(tag(elem1),tag(elem2)) == 0) {
  16.                 return xml_list_equal(children(elem1), children(elem2));
  17.             }
  18.         }
  19.     }
  20.     return 0;
  21. }
  22.  
  23. /**
  24.  * xml_list_equal
  25.  * Params: Two XML Lists
  26.  * Returns:
  27.  */
  28. int xml_list_equal(xml_list *list1, xml_list *list2) {
  29.     // Compare types
  30.     if (list1->tag == list2->tag) {
  31.         // Both empty list? -> Equal!
  32.         if (isEmpty(list1)) {
  33.             return 1;
  34.         }
  35.         // Both Cons? -> Check their tails for equality
  36.         if (isCons(list1)) {
  37.             return (xml_equal(head(list1),head(list2)) && xml_list_equal(tail(list1),tail(list2)));
  38.         }
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement