DCL 4.0
Loading...
Searching...
No Matches
UTF16Decoder Class Reference

#include <Charset.h>

Inheritance diagram for UTF16Decoder:
CharsetDecoder Object

Protected Member Functions

virtual int toWideChar (const byte_t *_mbs, size_t _mbslen, ucs4_t *_uc)
Protected Member Functions inherited from CharsetDecoder
 CharsetDecoder ()
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Additional Inherited Members

Public Member Functions inherited from CharsetDecoder
virtual int decode (const byte_t *_in, size_t &_inCount, wchar_t *_out, size_t &_outCount)
size_t getDecodedLength (const char *_mbs, size_t _mbslen) __DCL_THROWS1(CharsetConvertException *)
String decode (const char *_mbs, size_t _mbslen=(size_t) -1) __DCL_THROWS1(CharsetConvertException *)
String decode (const ByteString &_str) __DCL_THROWS1(CharsetConvertException *)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Detailed Description

Definition at line 234 of file Charset.h.

Member Function Documentation

◆ toWideChar()

int UTF16Decoder::toWideChar ( const byte_t * _mbs,
size_t _mbslen,
ucs4_t * _uc )
protectedvirtual

Implements CharsetDecoder.

Definition at line 303 of file CharsetDecoder.cpp.

304{
305 int count = 0;
306 while(_mbslen >= 2) {
307 ucs4_t uc = __bigEndian ? (_mbs[0] << 8) + _mbs[1] : _mbs[0] + (_mbs[1] << 8);
308 if (uc == 0xFEFF) {
309 __hasBOM = true;
310 }
311 else if (uc == 0xFFFE) {
312 __hasBOM = true;
313 __bigEndian = !__bigEndian;
314 }
315 else if (uc >= 0xD800 && uc < 0xDC00) {
316 if (_mbslen >= 4) {
317 ucs4_t uc2 = __bigEndian ? (_mbs[2] << 8) + _mbs[3] : _mbs[2] + (_mbs[3] << 8);
318 if (!(uc2 >= 0xdc00 && uc2 < 0xe000))
319 return ILLEGAL_SEQUENCE;
320 *_uc = 0x10000 + ((uc - 0xd800) << 10) + (uc2 - 0xdc00);
321 return count + 4;
322 }
323 else
324 break;
325 }
326 else if (uc >= 0xdc00 && uc < 0xe000) {
327 return ILLEGAL_SEQUENCE;
328 }
329 else {
330 *_uc = uc;
331 return count + 2;
332 }
333 _mbs += 2; _mbslen -= 2; count += 2;
334 }
335 return SOURCE_FEW_N(count);
336}
__DCL_BEGIN_NAMESPACE typedef uint32_t ucs4_t
Definition Charset.h:29
#define ILLEGAL_SEQUENCE
#define SOURCE_FEW_N(_mbslen)

The documentation for this class was generated from the following files: