static int catalogCompare()

in hfs/catalog.c [128:182]


static int catalogCompare(BTKey* vLeft, BTKey* vRight) {
  HFSPlusCatalogKey* left;
  HFSPlusCatalogKey* right;
  uint16_t i;

  uint16_t cLeft;
  uint16_t cRight;
  
  left = (HFSPlusCatalogKey*) vLeft;
  right =(HFSPlusCatalogKey*) vRight;
   
  if(left->parentID < right->parentID) {
    return -1;
  } else if(left->parentID > right->parentID) {
    return 1;
  } else {
    for(i = 0; i < left->nodeName.length; i++) {
      if(i >= right->nodeName.length) {
        return 1;
      } else {
		/* ugly hack to support weird : to / conversion on iPhone */
	    if(left->nodeName.unicode[i] == ':') {
			cLeft = '/';
		} else {
			cLeft = left->nodeName.unicode[i] ;
		}
		
		if(right->nodeName.unicode[i] == ':') {
			cRight = '/';
		} else {
			cRight = right->nodeName.unicode[i];
		}
		
        if(cLeft < cRight)
          return -1;
        else if(cLeft > cRight)
          return 1;
      }
    }
    
    if(i < right->nodeName.length) {
      return -1;
    } else {
      /* do a safety check on key length. Otherwise, bad things may happen later on when we try to add or remove with this key */
      /*if(left->keyLength == right->keyLength) {
        return 0;
      } else if(left->keyLength < right->keyLength) {
        return -1;
      } else {
        return 1;
      }*/
      return 0;
    }
  }
}