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:
parent
8a99b1dc31
commit
ec3ead230b
@ -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
|
status_t
|
||||||
GetLocalizedFileName(entry_ref& ref, BString& localizedFileName, bool traverse)
|
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);
|
BEntry entry(&ref, traverse);
|
||||||
if (!entry.Exists())
|
if (!entry.Exists())
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
BNode node(&entry);
|
BNode node(&entry);
|
||||||
status = node.InitCheck();
|
status_t status = node.InitCheck();
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
attr_info attr;
|
attr_info attr;
|
||||||
ssize_t bytes = 0;
|
|
||||||
|
|
||||||
status = node.GetAttrInfo("SYS:NAME", &attr);
|
status = node.GetAttrInfo("SYS:NAME", &attr);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
char attribute[attr.size + 1];
|
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)
|
if (bytes < 0)
|
||||||
return bytes;
|
return bytes;
|
||||||
@ -1513,25 +1520,19 @@ GetLocalizedFileName(entry_ref& ref, BString& localizedFileName, bool traverse)
|
|||||||
attribute[bytes] = '\0';
|
attribute[bytes] = '\0';
|
||||||
|
|
||||||
char* signature = attribute;
|
char* signature = attribute;
|
||||||
char* context = NULL;
|
char* context = strchr(signature, ':');
|
||||||
char* string = NULL;
|
if (context) {
|
||||||
|
context[0] = '\0';
|
||||||
|
context++;
|
||||||
|
} else
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
ssize_t i = 0;
|
char* string = strchr(context, ':');
|
||||||
for (; i < bytes; i++) {
|
if (string) {
|
||||||
if (signature[i] == ':') {
|
string[0] = '\0';
|
||||||
signature[i] = '\0';
|
string++;
|
||||||
context = &signature[i + 1];
|
} else
|
||||||
break;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i < bytes; i++) {
|
|
||||||
if (signature[i] == ':') {
|
|
||||||
signature[i] = '\0';
|
|
||||||
string = &signature[i + 1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BCatalog catalog(signature);
|
BCatalog catalog(signature);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user