Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

enum CRStatus cr_utils_ucs1_to_utf8 ( const guchar *  a_in,
gulong *  a_in_len,
guchar *  a_out,
gulong *  a_out_len 
)

Converts an ucs1 buffer into an utf8 buffer. The caller must know the size of the resulting buffer and allocate it prior to calling this function.

Parameters:
a_in the input ucs1 buffer.
a_in_len in/out parameter. The length of the input buffer. After return, points to the number of bytes actually consumed even in case of encoding error.
a_out out parameter. The output utf8 converted buffer.
a_out_len in/out parameter. The size of the output buffer. If the output buffer size is shorter than the actual needed size, this function just convert what it can.
Returns:
CR_OK upon successfull completion, an error code otherwise.

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

Referenced by cr_utils_ucs1_str_to_utf8().

{
        gulong out_index = 0,
                in_index = 0,
                in_len = 0,
                out_len = 0;
        enum CRStatus status = CR_OK;

        g_return_val_if_fail (a_in && a_in_len
                              && a_out_len, 
                              CR_BAD_PARAM_ERROR);

        if (*a_in_len == 0) {
                *a_out_len = 0 ;
                return CR_OK ;
        }
        g_return_val_if_fail (a_out, CR_BAD_PARAM_ERROR) ;

        if (*a_in_len < 1) {
                status = CR_OK;
                goto end;
        }

        in_len = *a_in_len;
        out_len = *a_out_len;

        for (in_index = 0, out_index = 0;
             (in_index < in_len) && (out_index < out_len); in_index++) {
                /*
                 *FIXME: return whenever we encounter forbidden char values.
                 */

                if (a_in[in_index] <= 0x7F) {
                        a_out[out_index] = a_in[in_index];
                        out_index++;
                } else {
                        a_out[out_index] = (0xC0 | (a_in[in_index] >> 6));
                        a_out[out_index + 1] =
                                (0x80 | (a_in[in_index] & 0x3F));
                        out_index += 2;
                }
        }                       /*end for */

      end:
        *a_in_len = in_index;
        *a_out_len = out_index;

        return CR_OK;
}


Generated by  Doxygen 1.6.0   Back to index