Skip \0 marker in strings
Apparently used to tag keyboard shortcuts for menus or something? But it
doesn't survive utf-8 conversion so let's avoid it.
diff --git a/AmigaCatalog.cpp b/AmigaCatalog.cpp
index 42014b9..ce5ce77 100644
--- a/AmigaCatalog.cpp
+++ b/AmigaCatalog.cpp
@@ -186,7 +186,6 @@
{
BMemoryIO strings(chunkData, chunkSize);
int32 strID, strLen;
- puts("");
while (strings.Position() < chunkSize) {
strings.Read(&strID, sizeof(strID));
@@ -197,8 +196,16 @@
strLen &= ~3;
strLen += 4;
}
- char strVal[strLen];
- strings.Read(strVal, strLen);
+ char strBase[strLen];
+ char* strVal = strBase;
+ strings.Read(strBase, strLen);
+
+ if (strBase[1] == 0)
+ {
+ // Skip the \0 marker for menu entries…
+ strLen -= 2;
+ strVal += 2;
+ }
char outVal[1024];
int32 outLen = 1024;
@@ -207,7 +214,12 @@
convert_to_utf8(B_ISO1_CONVERSION, strVal, &strLen,
outVal, &outLen, &cookie);
- SetString(strID, outVal);
+ // If the UTF-8 version is shorter, it's likely that
+ // something went wrong. Keep the original string.
+ if (outLen > strLen)
+ SetString(strID, outVal);
+ else
+ SetString(strID, strVal);
}
break;
}