Style fixes. Doxygen comment. Use standard strchr function.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40803 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström 2011-03-04 11:11:03 +00:00
parent 8a99b1dc31
commit ec3ead230b

View File

@ -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);