本文整理汇总了C++中ErrorCode::errorName方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorCode::errorName方法的具体用法?C++ ErrorCode::errorName怎么用?C++ ErrorCode::errorName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorCode
的用法示例。
在下文中一共展示了ErrorCode::errorName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestErrorCode
void ErrorCodeTest::TestErrorCode() {
ErrorCode errorCode;
if(errorCode.get()!=U_ZERO_ERROR || !errorCode.isSuccess() || errorCode.isFailure()) {
errln("ErrorCode did not initialize properly");
return;
}
errorCode.assertSuccess();
if(errorCode.errorName()!=u_errorName(U_ZERO_ERROR)) {
errln("ErrorCode did not format error message string properly");
}
RefPlusOne(errorCode);
if(errorCode.get()!=U_ILLEGAL_ARGUMENT_ERROR || errorCode.isSuccess() || !errorCode.isFailure()) {
errln("ErrorCode did not yield a writable reference");
}
PtrPlusTwo(errorCode);
if(errorCode.get()!=U_INVALID_FORMAT_ERROR || errorCode.isSuccess() || !errorCode.isFailure()) {
errln("ErrorCode did not yield a writable pointer");
}
errorCode.set(U_PARSE_ERROR);
if(errorCode.get()!=U_PARSE_ERROR || errorCode.isSuccess() || !errorCode.isFailure()) {
errln("ErrorCode.set() failed");
}
if( errorCode.reset()!=U_PARSE_ERROR || errorCode.get()!=U_ZERO_ERROR ||
!errorCode.isSuccess() || errorCode.isFailure()
) {
errln("ErrorCode did not reset properly");
}
}
示例2: GetWordBoundaryPositions
void GetWordBoundaryPositions(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() != 2) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "must supply locale and text")));
return;
}
if (!args[0]->IsString()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "text is not specified")));
return;
}
if (!args[1]->IsString()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "locale is not specified")));
return;
}
// convert v8 locale to ICU
String::Utf8Value locale(args[1]->ToString());
const char* country = strtok(*locale, "_"), *language = strtok(NULL, "_");
Locale icuLocale(language, country);
// create the BreakIterator instance
UErrorCode err = U_ZERO_ERROR;
BreakIterator *iterator = BreakIterator::createWordInstance(icuLocale, err);
if (U_FAILURE(err)) {
ErrorCode errCode;
errCode.set(err);
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, errCode.errorName())));
return;
}
// Convert v8 text to ICU Unicode value
Local<String> textStr = args[0]->ToString();
String::Utf8Value textValue(textStr);
UnicodeString uTextValue(*textValue, "UTF-8");
if (uTextValue.isBogus()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "unable to create unicode string")));
return;
}
iterator->setText(uTextValue);
// populate boundaries
Local<Array> results = Array::New(isolate);
int32_t arrayPosition = 0;
int32_t currentBoundary = iterator->first();
int32_t previousBoundary = 0;
while (currentBoundary != BreakIterator::DONE) {
if (currentBoundary > 0) {
Local<Object> boundaryResult = Object::New(isolate);
boundaryResult->Set(String::NewFromUtf8(isolate, "start"), Number::New(isolate, previousBoundary));
boundaryResult->Set(String::NewFromUtf8(isolate, "end"), Number::New(isolate, currentBoundary));
results->Set(arrayPosition++, boundaryResult);
}
previousBoundary = currentBoundary;
currentBoundary = iterator->next();
}
// cleanup
delete iterator;
args.GetReturnValue().Set(results);
}