当前位置: 首页>>代码示例>>C++>>正文


C++ ErrorCode::set方法代码示例

本文整理汇总了C++中ErrorCode::set方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorCode::set方法的具体用法?C++ ErrorCode::set怎么用?C++ ErrorCode::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ErrorCode的用法示例。


在下文中一共展示了ErrorCode::set方法的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");
    }
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:28,代码来源:itutil.cpp

示例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);
}
开发者ID:imojiengineering,项目名称:node-icu-tokenizer,代码行数:68,代码来源:node-icu-tokenizer.cpp


注:本文中的ErrorCode::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。