I am trying to use ICU libraries to test if a string has invalid UTF-8 characters. I created a UTF-8 converter but no invalid data gives me an error on conversion. Appreciate your help.
Thanks, Prashanth
int main()
{
string str ("AP1120 CorNet-IP v5.0 v5.0.1.22 òÀ MIB 1.5.3.50 Profile EN-C5000");
// string str ("example string here");
// string str (" ����������" );
UErrorCode status = U_ZERO_ERROR;
UConverter *cnv;
const char *sourceLimit;
const char * source = str.c_str();
cnv = ucnv_open("utf-8", &status);
assert(U_SUCCESS(status));
UChar *target;
int sourceLength = str.length();
int targetLimit = 2 * sourceLength;
target = new UChar[targetLimit];
ucnv_toUChars(cnv, target, targetLimit, source, sourceLength, &status);
cout << u_errorName(status) << endl;
assert(U_SUCCESS(status));
}