/* Given a wmem scope, a pointer, and a length, treat the string of bytes referred to by the pointer and length as an ISO 8859/1 string, and return a pointer to a UTF-8 string, allocated using the wmem scope.  */
guint8* get_8859_1_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
/* Given a wmem scope, a pointer, and a length, treat the string of bytes referred to by the pointer and length as an ISO 8859/1 string, and return a pointer to a UTF-8 string, allocated using the wmem scope.  */
guint8* get_8859_1_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
{
    wmem_strbuf_t *str;
    str = wmem_strbuf_sized_new(scope, length+1, 0);
    while (length > 0) {
        guint8 ch = *ptr;
        if (ch < 0x80)
            wmem_strbuf_append_c(str, ch);
        else {
            wmem_strbuf_append_unichar(str, ch);
        }
        ptr++;
        length--;
    }
    return (guint8 *) wmem_strbuf_finalize(str);
}