Author: kirilla Date: 2011-03-04 12:11:03 +0100 (Fri, 04 Mar 2011) New Revision: 40803 Changeset: http://dev.haiku-os.org/changeset/40803 Modified: haiku/trunk/src/kits/tracker/Utilities.cpp Log: Style fixes. Doxygen comment. Use standard strchr function. Modified: haiku/trunk/src/kits/tracker/Utilities.cpp =================================================================== --- haiku/trunk/src/kits/tracker/Utilities.cpp 2011-03-04 10:42:58 UTC (rev 40802) +++ haiku/trunk/src/kits/tracker/Utilities.cpp 2011-03-04 11:11:03 UTC (rev 40803) @@ -1470,39 +1470,46 @@ } +/*! \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,26 +1520,20 @@ 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; - } - } + char* string = strchr(context, ':'); + if (string) { + string[0] = '\0'; + string++; + } else + return B_ENTRY_NOT_FOUND; - for (; i < bytes; i++) { - if (signature[i] == ':') { - signature[i] = '\0'; - string = &signature[i + 1]; - break; - } - } - BCatalog catalog(signature); const char* temp = catalog.GetString(string, context);