How do I normalize a string using ICU4C?

点点圈 提交于 2019-12-11 12:18:12

问题


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


回答1:


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...
}


来源:https://stackoverflow.com/questions/10447452/how-do-i-normalize-a-string-using-icu4c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!