diff options
Diffstat (limited to 'media/mtp/MtpStringBuffer.cpp')
-rw-r--r-- | media/mtp/MtpStringBuffer.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/media/mtp/MtpStringBuffer.cpp b/media/mtp/MtpStringBuffer.cpp index 8bf6731..fe8cf04 100644 --- a/media/mtp/MtpStringBuffer.cpp +++ b/media/mtp/MtpStringBuffer.cpp @@ -37,6 +37,13 @@ MtpStringBuffer::MtpStringBuffer(const char* src) set(src); } +MtpStringBuffer::MtpStringBuffer(const uint16_t* src) + : mCharCount(0), + mByteCount(1) +{ + set(src); +} + MtpStringBuffer::MtpStringBuffer(const MtpStringBuffer& src) : mCharCount(src.mCharCount), mByteCount(src.mByteCount) @@ -88,6 +95,29 @@ void MtpStringBuffer::set(const char* src) { mCharCount = count; } +void MtpStringBuffer::set(const uint16_t* src) { + int count = 0; + uint16_t ch; + uint8_t* dest = mBuffer; + + while ((ch = *src++) != 0 && count < 255) { + if (ch >= 0x0800) { + *dest++ = (uint8_t)(0xE0 | (ch >> 12)); + *dest++ = (uint8_t)(0x80 | ((ch >> 6) & 0x3F)); + *dest++ = (uint8_t)(0x80 | (ch & 0x3F)); + } else if (ch >= 0x80) { + *dest++ = (uint8_t)(0xC0 | (ch >> 6)); + *dest++ = (uint8_t)(0x80 | (ch & 0x3F)); + } else { + *dest++ = ch; + } + count++; + } + *dest++ = 0; + mCharCount = count; + mByteCount = dest - mBuffer; +} + void MtpStringBuffer::readFromPacket(MtpDataPacket* packet) { int count = packet->getUInt8(); uint8_t* dest = mBuffer; |