PIString::fromUTF8 BOM support
This commit is contained in:
@@ -341,14 +341,31 @@ PIString PIString::fromSystem(const char * s) {
|
|||||||
PIString PIString::fromUTF8(const char * s) {
|
PIString PIString::fromUTF8(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, -1, __utf8name__);
|
if (s[0] != '\0') {
|
||||||
|
if ((uchar)s[0] == 0xEF && (uchar)s[1] == 0xBB && (uchar)s[2] == 0xBF) {
|
||||||
|
s += 3;
|
||||||
|
if (s[0] == '\0') return ret;
|
||||||
|
}
|
||||||
|
ret.appendFromChars(s, -1, __utf8name__);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIString PIString::fromUTF8(const PIByteArray & ba) {
|
PIString PIString::fromUTF8(const PIByteArray & ba) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (ba.isNotEmpty()) ret.appendFromChars((const char*)ba.data(), ba.size(), __utf8name__);
|
if (ba.isNotEmpty()) {
|
||||||
|
const char * data = (const char*)ba.data();
|
||||||
|
int size = ba.size();
|
||||||
|
if (ba.size() >= 3) {
|
||||||
|
if (ba[0] == 0xEF && ba[1] == 0xBB && ba[2] == 0xBF) {
|
||||||
|
data += 3;
|
||||||
|
size -= 3;
|
||||||
|
if (size == 0) return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.appendFromChars(data, size, __utf8name__);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user