Do not rely on libtextencoding for conversions.
It create two types of problems:
- If the translator is not linked with libtextencoding, it can't be used
in apps that don't link with it
- If the translator is linked with libtextencoding, it deadlocks apps
that don't link with it
Since the conversion from ISO 8859 to UTF8 is simple enough, implement
it manually.
diff --git a/AmigaCatalog.cpp b/AmigaCatalog.cpp
index 9633b89..33defbe 100644
--- a/AmigaCatalog.cpp
+++ b/AmigaCatalog.cpp
@@ -202,8 +202,8 @@
strLen &= ~3;
strLen += 4;
}
- char strBase[strLen];
- char* strVal = strBase;
+ unsigned char strBase[strLen];
+ unsigned char* strVal = strBase;
strings.Read(strBase, strLen);
if (strBase[1] == 0)
@@ -213,19 +213,19 @@
strVal += 2;
}
- char outVal[1024];
- int32 outLen = 1024;
- int32 cookie = 0;
+ unsigned char outVal[1024];
- convert_to_utf8(B_ISO1_CONVERSION, strVal, &strLen,
- outVal, &outLen, &cookie);
+ int j = 0;
+ for (int i = 0; i < strLen && j < 1024; i++) {
+ if (strVal[i] > 0x7F) {
+ outVal[j++] = 0xC0 | ((strVal[i] >> 6) & 0x3);
+ outVal[j++] = 0x80 | (strVal[i] & 0x3f);
+ } else
+ outVal[j++] = strVal[i];
+ }
+ outVal[j] = 0;
- // 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);
+ SetString(strID, (char*)outVal);
}
break;
}