/* Given an ucs4 string, this function returns the size (in bytes) this string would have occupied if it was encoded in utf-8.  */
enum CRStatus cr_utils_ucs4_str_len_as_utf8(const guint32 *a_in_start, const guint32 *a_in_end, gulong *a_len)
/* Given an ucs4 string, this function returns the size (in bytes) this string would have occupied if it was encoded in utf-8.  */
enum CRStatus cr_utils_ucs4_str_len_as_utf8(const guint32 *a_in_start, const guint32 *a_in_end, gulong *a_len)
{
        gint len = 0;
        guint32 *char_ptr = NULL;
        g_return_val_if_fail (a_in_start && a_in_end && a_len,
                              CR_BAD_PARAM_ERROR);
        for (char_ptr = (guint32 *) a_in_start;
             char_ptr <= a_in_end; char_ptr++) {
                if (*char_ptr <= 0x7F) {
                        len += 1;
                } else if (*char_ptr <= 0x7FF) {
                        len += 2;
                } else if (*char_ptr <= 0xFFFF) {
                        len += 3;
                } else if (*char_ptr <= 0x1FFFFF) {
                        len += 4;
                } else if (*char_ptr <= 0x3FFFFFF) {
                        len += 5;
                } else if (*char_ptr <= 0x7FFFFFFF) {
                        len += 6;
                }
        }
        *a_len = len;
        return CR_OK;
}