Unicorn XML Toolkit
Version 1.50.00

Namespace Unicode
Class CUtf16Encoding

class CUtf16Encoding: public CEncoding {
public:
    CUtf16Encoding(bool bBigEndian=true);
    ~CUtf16Encoding();
public:
    const WCHAR *GetName();
    int Get(
        const BYTE *pSource,
        int nSourceLength,
        int &nSourceAdvance,
        WCHAR *chBuffer,
        int nBufferLimit,
        bool &bUnderflow);
    int Put(
        const WCHAR *chSource,
        int nSourceLength,
        BYTE *pBuffer,
        int nBufferLimit,
        int &nBufferAdvance,
        bool &bUnsupported);
    int Skip(
        const WCHAR *chSource,
        int nSourceLength);
    const WCHAR *Signature(int &nLength);
    };

The implementation of UTF-16 encoding.

Since:
1.00.00
Version:
1.50.00
Author:
Alexey Gokhberg
Constructor/Destructor Summary
CUtf16Encoding (bool bBigEndian=true);
����������Constructs the encoding.
~CUtf16Encoding ();
����������Destroys the encoding.

Function Summary
const�WCHAR�* GetName ();
����������Returns a name of this encoding.
int Get (const BYTE *pSource, int nSourceLength, int &nSourceAdvance, WCHAR *chBuffer, int nBufferLimit, bool &bUnderflow);
����������Converts (decodes) an array of bytes into an array of Unicode characters according to this character encoding.
int Put (const WCHAR *chSource, int nSourceLength, BYTE *pBuffer, int nBufferLimit, int &nBufferAdvance, bool &bUnsupported);
����������Converts (encodes) an array of characters into an array of bytes according to this character encoding.
int Skip (const WCHAR *chSource, int nSourceLength);
����������Skips a contiguous group of characters, unsupported by this encoding.
const�WCHAR�* Signature (int &nLength);
����������Returns an array of characters which is used as a signature by this encoding.

Constructor/Destructor Detail

CUtf16Encoding

CUtf16Encoding(bool bBigEndian=true);

Constructs the encoding.

Parameters:
bBigEndian - true to construct the big-endian version of encoding; false to construct the little-endian version

~CUtf16Encoding

~CUtf16Encoding();

Destroys the encoding.

Function Detail

GetName

const WCHAR *GetName();

Returns a name of this encoding.

Returns:
the name of this encoding (that is, "UTF-16" )

Get

int Get(
    const BYTE *pSource,
    int nSourceLength,
    int &nSourceAdvance,
    WCHAR *chBuffer,
    int nBufferLimit,
    bool &bUnderflow);

Converts (decodes) an array of bytes into an array of Unicode characters according to this character encoding.

This function tries to convert as many bytes from the input array as possible. However, conversion of the entire input array may be impossible, if either the end of the result buffer is reached, or if the last few bytes of the input array do not provide a full representation of a valid Unicode character (the latter case may be encountered when the large byte array is processed in smaller buffers, and a sequence of bytes representing a particular character is split at the buffer boundary).

Parameters:
pSource - the input array of bytes
nSourceLength - the number of bytes in the input array
nSourceAdvance - on return, the number of bytes in the input array actually converted
chBuffer - the result buffer; on return, contains the result of conversion
nBufferLimit - the capacity of the result buffer, in characters
bUnderflow - on return, true if the few last bytes if the input array do not provide the full representation of a valid Unicode character; false otherwise
Returns:
the number of characters placed into the result buffer

Put

int Put(
    const WCHAR *chSource,
    int nSourceLength,
    BYTE *pBuffer,
    int nBufferLimit,
    int &nBufferAdvance,
    bool &bUnsupported);

Converts (encodes) an array of characters into an array of bytes according to this character encoding.

This function tries to convert as many characters from the input array as possible. However, conversion of the entire input array may be impossible, if either the end of the result buffer is reached, or a character not supported by this encoding is encountered in the input buffer.

Parameters:
chSource - the input array of characters
nSourceLength - the number of characters in the input array
pBuffer - the result buffer; on return, contains the result of conversion
nBufferLimit - the capacity of the result buffer, in bytes
nBufferAdvance - on return, the number of bytes placed into the result buffer
bUnsupported - on return, true if a character not supported by this encoding was encountered in the input buffer
Returns:
the number of characters in the input array actually converted

Skip

int Skip(
    const WCHAR *chSource,
    int nSourceLength);

Skips a contiguous group of characters, unsupported by this encoding.

If the first character in the specified input buffer is supported by this encoding, this function returns 0 . If the first character in the input buffer is not supported by this encoding, this function returns the length of the longest contiguous group of input characters unsupported by this encoding, started with the first character in the buffer.

Parameters:
chSource - the input buffer
nSourceLength - the number of characters in the input buffer
Returns:
the number of characters skipped

Signature

const WCHAR *Signature(int &nLength);

Returns an array of characters which is used as a signature by this encoding.

The UTF-16 encoding employs a single character with the hexadecimal code FEFF as a signature to specify the byte order (the byte order mark).

Parameters:
nLength - on return, the number of characters in the signature ( 1 for UTF-16)
Returns:
the signature array (contains a single character with the hexadecimal code FEFF for UTF-16)

Unicorn XML Toolkit
Version 1.50.00


This document was created using Unicorn DOC++.

Copyright 1999-2001 Unicorn Enterprises SA.
All Rights Reserved.