void HFSCatalogBTree::dumpTree(int nodeIndex, int depth) const { HFSBTreeNode node(m_reader, nodeIndex, be(m_header.nodeSize)); switch (node.kind()) { case NodeKind::kBTIndexNode: { for (size_t i = 0; i < node.recordCount(); i++) { UErrorCode error = U_ZERO_ERROR; HFSPlusCatalogKey* key = node.getRecordKey<HFSPlusCatalogKey>(i); UnicodeString keyName((char*)key->nodeName.string, be(key->nodeName.length)*2, g_utf16be, error); std::string str; keyName.toUTF8String(str); // recurse down uint32_t* childIndex = node.getRecordData<uint32_t>(i); #ifdef DEBUG printf("Index Node(%4d,%4zd) %s %s(%d) ->child %d\n", nodeIndex, i, std::string(depth, ' ').c_str(), str.c_str(), be(key->parentID), be(*childIndex)); // std::cout << "Index node(" << nodeIndex << "): " << std::string(depth, ' ') << str << "(" << be(key->parentID) << ")\n"; #endif dumpTree(be(*childIndex), depth+2); } break; } case NodeKind::kBTLeafNode: { for (size_t i = 0; i < node.recordCount(); i++) { HFSPlusCatalogKey* recordKey; UErrorCode error = U_ZERO_ERROR; UnicodeString keyName; std::string str; recordKey = node.getRecordKey<HFSPlusCatalogKey>(i); keyName = UnicodeString((char*)recordKey->nodeName.string, be(recordKey->nodeName.length)*2, g_utf16be, error); keyName.toUTF8String(str); #ifdef DEBUG printf("Leaf Node(%4d,%4zd) %s %s(%d)\n", nodeIndex, i, std::string(depth, ' ').c_str(), str.c_str(), be(recordKey->parentID)); // std::cout << "dumpTree(l): " << std::string(depth, ' ') << str << "(" << be(recordKey->parentID) << ")\n"; #endif } break; } case NodeKind::kBTHeaderNode: case NodeKind::kBTMapNode: break; default: std::cerr << "Invalid node kind! Kind: " << int(node.kind()) << std::endl; } }
int HFSCatalogBTree::caseInsensitiveComparator(const Key* indexKey, const Key* desiredKey) { const HFSPlusCatalogKey* catIndexKey = reinterpret_cast<const HFSPlusCatalogKey*>(indexKey); const HFSPlusCatalogKey* catDesiredKey = reinterpret_cast<const HFSPlusCatalogKey*>(desiredKey); UnicodeString desiredName, indexName; UErrorCode error = U_ZERO_ERROR; //std::cout << "desired: " << be(catDesiredKey->parentID) << ", index: " << be(catIndexKey->parentID) << "\n"; if (be(catDesiredKey->parentID) < be(catIndexKey->parentID)) { //std::cout << "\t -> bigger\n"; return 1; } else if (be(catDesiredKey->parentID) > be(catIndexKey->parentID)) { //std::cout << "\t -> smaller\n"; return -1; } desiredName = UnicodeString((char*)catDesiredKey->nodeName.string, be(catDesiredKey->nodeName.length)*2, g_utf16be, error); indexName = UnicodeString((char*)catIndexKey->nodeName.string, be(catIndexKey->nodeName.length)*2, g_utf16be, error); // Hack for "\0\0\0\0HFS+ Private Data" which should come as last in ordering (issue #11) if (indexName.charAt(0) == 0) return 1; else if (desiredName.charAt(0) == 0) return -1; { //std::string des, idx; //desiredName.toUTF8String(des); //indexName.toUTF8String(idx); int r = indexName.caseCompare(desiredName, 0); //std::cout << "desired: " << des << " - index: " << idx << " -> r=" << r << std::endl; return r; } return 0; }
/* {{{ timezone_convert_datetimezone * The timezone in DateTime and DateTimeZone is not unified. */ U_CFUNC TimeZone *timezone_convert_datetimezone(int type, void *object, int is_datetime, intl_error *outside_error, const char *func) { char *id = NULL, offset_id[] = "GMT+00:00"; int32_t id_len = 0; char *message; TimeZone *timeZone; switch (type) { case TIMELIB_ZONETYPE_ID: id = is_datetime ? ((php_date_obj*)object)->time->tz_info->name : ((php_timezone_obj*)object)->tzi.tz->name; id_len = strlen(id); break; case TIMELIB_ZONETYPE_OFFSET: { int offset_mins = is_datetime ? ((php_date_obj*)object)->time->z / 60 : (int)((php_timezone_obj*)object)->tzi.utc_offset / 60, hours = offset_mins / 60, minutes = offset_mins - hours * 60; minutes *= minutes > 0 ? 1 : -1; if (offset_mins <= -24 * 60 || offset_mins >= 24 * 60) { spprintf(&message, 0, "%s: object has an time zone offset " "that's too large", func); intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1); efree(message); return NULL; } id = offset_id; id_len = slprintf(id, sizeof(offset_id), "GMT%+03d:%02d", hours, minutes); break; } case TIMELIB_ZONETYPE_ABBR: id = is_datetime ? ((php_date_obj*)object)->time->tz_abbr : ((php_timezone_obj*)object)->tzi.z.abbr; id_len = strlen(id); break; } UnicodeString s = UnicodeString(id, id_len, US_INV); timeZone = TimeZone::createTimeZone(s); if (*timeZone == TimeZone::getUnknown()) { spprintf(&message, 0, "%s: time zone id '%s' " "extracted from ext/date DateTimeZone not recognized", func, id); intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1); efree(message); delete timeZone; return NULL; } return timeZone; }