diff --git a/src/kits/tracker/Utilities.cpp b/src/kits/tracker/Utilities.cpp index 8949bbc45a..aaf079a340 100644 --- a/src/kits/tracker/Utilities.cpp +++ b/src/kits/tracker/Utilities.cpp @@ -1470,39 +1470,46 @@ GetFileIconFromAttr(BNode *file, BBitmap *result, icon_size size) } +/*! \fn status_t GetLocalizedFileName(entry_ref& ref, + BString& localizedFileName, bool traverse) + \brief Looks up a localized filename in a catalog, using attribute data + on the entry. + \param ref An entry_ref with an attribute holding data for catalog lookup. + \param localizedFileName A pre-allocated BString object for the result + of the lookup. + \param traverse A boolean to decide if symlinks are to be traversed. + \return + - \c B_OK: success + - \c B_ENTRY_NOT_FOUND: failure. Attribute not found, entry not found + in catalog, etc + - other error codes: failure + + Attribute format: "signature:context:string" + (no colon in any of signature, context and string) + + Lookup is done for the top preferred language, only. + Lookup fails if a comment is present in the catalog entry. +*/ status_t GetLocalizedFileName(entry_ref& ref, BString& localizedFileName, bool traverse) { - // Looks up a localized filename, by reading a catalog signature, - // context and string to be translated, from an attribute on the - // entry_ref, and using these to look up a translation in the catalog - // of the top preferred language. - - // Attribute format: "signature:context:string" - // (no colon in any of signature, context and string) - - // It fails when a comment is present in the catalog. - - status_t status; - BEntry entry(&ref, traverse); if (!entry.Exists()) return B_ENTRY_NOT_FOUND; BNode node(&entry); - status = node.InitCheck(); + status_t status = node.InitCheck(); if (status != B_OK) return status; attr_info attr; - ssize_t bytes = 0; - status = node.GetAttrInfo("SYS:NAME", &attr); if (status != B_OK) return status; char attribute[attr.size + 1]; - bytes = node.ReadAttr("SYS:NAME", B_MIME_TYPE, 0, &attribute, attr.size); + ssize_t bytes = node.ReadAttr("SYS:NAME", B_MIME_TYPE, 0, &attribute, + attr.size); if (bytes < 0) return bytes; @@ -1513,25 +1520,19 @@ GetLocalizedFileName(entry_ref& ref, BString& localizedFileName, bool traverse) attribute[bytes] = '\0'; char* signature = attribute; - char* context = NULL; - char* string = NULL; + char* context = strchr(signature, ':'); + if (context) { + context[0] = '\0'; + context++; + } else + return B_ENTRY_NOT_FOUND; - ssize_t i = 0; - for (; i < bytes; i++) { - if (signature[i] == ':') { - signature[i] = '\0'; - context = &signature[i + 1]; - break; - } - } - - for (; i < bytes; i++) { - if (signature[i] == ':') { - signature[i] = '\0'; - string = &signature[i + 1]; - break; - } - } + char* string = strchr(context, ':'); + if (string) { + string[0] = '\0'; + string++; + } else + return B_ENTRY_NOT_FOUND; BCatalog catalog(signature);