Logo Search packages:      
Sourcecode: inkscape version File versions

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.

Parameters:
a_in_start a pointer to the beginning of the input buffer.
a_in_end a pointer to the end of the input buffer.
a_len out parameter. The computed length.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 187 of file cr-utils.c.

{
        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) {
                        /*the utf-8 char would take 1 byte */
                        len += 1;
                } else if (*char_ptr <= 0x7FF) {
                        /*the utf-8 char would take 2 bytes */
                        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;
}


Generated by  Doxygen 1.6.0   Back to index