Question

I find the ICU docs somewhat challenging.

My question is: How do I normalize a string using ICU4C?

I'm looking at unorm2_normalize, but what if the buffer isn't large enough? How would I know this before? Naturally, I want to normalize the entire string.

Thanks! :>

P.S. Here is the API doc on that function: http://icu-project.org/apiref/icu4c/unorm2_8h.html#a0a596802db767da410b4b04cb75cbc53

Was it helpful?

Solution

You get a error code back from all these function call in the pErrorCode parameter. This is how you call such a function:

UErrorCode error = U_ZERO_ERROR;
unorm2_normalize( ... &error );
....
if( !U_SUCCESS( error ) )
{
    // handle error...
}

Here are the error codes: http://icu-project.org/apiref/icu4c/utypes_8h.html#a3343c1c8a8377277046774691c98d78c

In your case you might want to do something like this:

if( error == U_STRING_NOT_TERMINATED_WARNING
   || error == U_BUFFER_OVERFLOW_ERROR )
{
    // enlarge the buffer...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top