Ejemplo n.º 1
0
/* {{{ grapheme_intl_case_fold: convert string to lowercase */
void
grapheme_intl_case_fold(UChar** ptr_to_free, UChar **str, int32_t *str_len, UErrorCode *pstatus )
{
    UChar *dest;
    int32_t dest_len, size_required;

    /* allocate a destination string that is a bit larger than the src, hoping that is enough */
#ifdef FULL_CASE_FOLDING
    dest_len = (*str_len) + ( *str_len / 10 );
#else
	dest_len = (*str_len) + ( *str_len / 10 ) + 1; // assume we have enough for '\0'
#endif /* FULL_CASE_FOLDING */
    dest = (UChar*) eumalloc(dest_len);

    *pstatus = U_ZERO_ERROR;
#ifdef FULL_CASE_FOLDING
    size_required = u_strFoldCase(dest, dest_len, *str, *str_len, INTL_G(turkic_casefolding) ? U_FOLD_CASE_EXCLUDE_SPECIAL_I : U_FOLD_CASE_DEFAULT, pstatus);
#else
	size_required = utf16_simple_case_folding(dest, dest_len, *str, *str_len, pstatus);
#endif /* FULL_CASE_FOLDING */

    dest_len = size_required;

    if ( U_BUFFER_OVERFLOW_ERROR == *pstatus ) {

        dest = (UChar*) eurealloc(dest, dest_len);

        *pstatus = U_ZERO_ERROR;
#ifdef FULL_CASE_FOLDING
        size_required = u_strFoldCase(dest, dest_len, *str, *str_len, INTL_G(turkic_casefolding) ? U_FOLD_CASE_EXCLUDE_SPECIAL_I : U_FOLD_CASE_DEFAULT, pstatus);
#else
		size_required = utf16_simple_case_folding(dest, dest_len, *str, *str_len, pstatus);
#endif /* FULL_CASE_FOLDING */
    }

    if ( U_FAILURE(*pstatus) ) {
        return;
    }

    if ( NULL != ptr_to_free) {
        efree(*ptr_to_free);
        *ptr_to_free = dest;
    }

    *str = dest;
    *str_len = dest_len;

    return;
}
Ejemplo n.º 2
0
/* {{{ grapheme_intl_case_fold: convert string to lowercase */
void
grapheme_intl_case_fold(UChar** ptr_to_free, UChar **str, int32_t *str_len, UErrorCode *pstatus )
{
    UChar *dest;
    int32_t dest_len, size_required;

    /* allocate a destination string that is a bit larger than the src, hoping that is enough */
    dest_len = (*str_len) + ( *str_len / 10 );
    dest = (UChar*) eumalloc(dest_len);

    *pstatus = U_ZERO_ERROR;
    size_required = u_strFoldCase(dest, dest_len, *str, *str_len, U_FOLD_CASE_DEFAULT, pstatus);

    dest_len = size_required;

    if ( U_BUFFER_OVERFLOW_ERROR == *pstatus ) {

        dest = (UChar*) eurealloc(dest, dest_len);

        *pstatus = U_ZERO_ERROR;
        size_required = u_strFoldCase(dest, dest_len, *str, *str_len, U_FOLD_CASE_DEFAULT, pstatus);
    }

    if ( U_FAILURE(*pstatus) ) {
        return;
    }

    if ( NULL != ptr_to_free) {
        efree(*ptr_to_free);
        *ptr_to_free = dest;
    }

    *str = dest;
    *str_len = dest_len;

    return;
}