Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE UText* U_EXPORT2 utext_openUTF8 ( UText ut,
const char *  s,
int64_t  length,
UErrorCode status 

Open a read-only UText implementation for UTF-8 strings.

Any invalid UTF-8 in the input will be handled in this way: a sequence of bytes that has the form of a truncated, but otherwise valid, UTF-8 sequence will be replaced by a single unicode replacement character, \uFFFD. Any other illegal bytes will each be replaced by a \uFFFD.

ut Pointer to a UText struct. If NULL, a new UText will be created. If non-NULL, must refer to an initialized UText struct, which will then be reset to reference the specified UTF-8 string.
s A UTF-8 string. Must not be NULL.
length The length of the UTF-8 string in bytes, or -1 if the string is zero terminated.
status Errors are returned here.
A pointer to the UText. If a pre-allocated UText was provided, it will always be used and returned. ICU 3.4

Definition at line 1966 of file utext.cpp.

References UText::b, UText::c, UText::context, INT32_MAX, NULL, UText::p, UText::pExtra, UText::pFuncs, UText::providerProperties, UText::q, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, and UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE.

    if(U_FAILURE(*status)) {
        return NULL;
    if(s==NULL && length==0) {
        s = gEmptyString;

    if(s==NULL || length<-1 || length>INT32_MAX) {
        return NULL;

    ut = utext_setup(ut, sizeof(UTF8Buf) * 2, status);
    if (U_FAILURE(*status)) {
        return ut;

    ut->pFuncs  = &utf8Funcs;
    ut->context = s;
    ut->b       = (int32_t)length;
    ut->c       = (int32_t)length;
    if (ut->c < 0) {
        ut->c = 0;
        ut->providerProperties |= I32_FLAG(UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE);
    ut->p = ut->pExtra;
    ut->q = (char *)ut->pExtra + sizeof(UTF8Buf);
    return ut;


Generated by  Doxygen 1.6.0   Back to index