/* XXX - should map lead and trail surrogate values to REPLACEMENT CHARACTERs (0xFFFD)? XXX - if there are an odd number of bytes, should put a REPLACEMENT CHARACTER at the end.  */
guint8* get_ucs_2_string(wmem_allocator_t *scope, const guint8 *ptr, gint length, const guint encoding)
/* XXX - should map lead and trail surrogate values to REPLACEMENT CHARACTERs (0xFFFD)? XXX - if there are an odd number of bytes, should put a REPLACEMENT CHARACTER at the end.  */
guint8* get_ucs_2_string(wmem_allocator_t *scope, const guint8 *ptr, gint length, const guint encoding)
{
    gunichar2      uchar;
    gint           i;
    wmem_strbuf_t *strbuf;
    strbuf = wmem_strbuf_sized_new(scope, length+1, 0);
    for(i = 0; i + 1 < length; i += 2) {
        if (encoding == ENC_BIG_ENDIAN){
            uchar = pntoh16(ptr + i);
        }else{
            uchar = pletoh16(ptr + i);
        }
        wmem_strbuf_append_unichar(strbuf, uchar);
    }
    return (guint8 *) wmem_strbuf_finalize(strbuf);
}