问题描述
我觉得ICU文档有点挑战性。
I find the ICU docs somewhat challenging.
我的问题是:我如何使用ICU4C正常化字符串
My question is: How do I normalize a string using ICU4C?
我看着unorm2_normalize,但如果缓冲区不够大呢?我怎么会知道之前呢?当然,我想正常化整个字符串。
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.
谢谢! :>
P.S。下面是该函数的API文档:的
P.S. Here is the API doc on that function: http://icu-project.org/apiref/icu4c/unorm2_8h.html#a0a596802db767da410b4b04cb75cbc53
推荐答案
您得到一个错误code从PERROR code参数所有这些函数调用回来。这是你如何把这种功能:
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...
}
下面是错误codeS:的
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...
}
这篇关于我如何使用ICU4C正常化的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!