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

U_STABLE UText* U_EXPORT2 utext_close ( UText ut  ) 

Close function for UText instances. Cleans up, releases any resources being held by an open UText.

If the UText was originally allocated by one of the utext_open functions, the storage associated with the utext will also be freed. If the UText storage originated with the application, as it would with a local or static instance, the storage will not be deleted.

An open UText can be reset to refer to new string by using one of the utext_open() functions without first closing the UText.

ut The UText to be closed.
NULL if the UText struct was deleted by the close. If the UText struct was originally provided by the caller to the open function, it is returned by this function, and may be safely used again in a subsequent utext_open.
ICU 3.4

Definition at line 1004 of file utext.cpp.

References UTextFuncs::close, UText::extraSize, UText::flags, UText::magic, NULL, UText::pExtra, and UText::pFuncs.

    if (ut==NULL ||
        ut->magic != UTEXT_MAGIC ||
        (ut->flags & UTEXT_OPEN) == 0)
        // The supplied ut is not an open UText.
        // Do nothing.
        return ut;

    // If the provider gave us a close function, call it now.
    // This will clean up anything allocated specifically by the provider.
    if (ut->pFuncs->close != NULL) {
    ut->flags &= ~UTEXT_OPEN;

    // If we (the framework) allocated the UText or subsidiary storage,
    //   delete it.
    if (ut->flags & UTEXT_EXTRA_HEAP_ALLOCATED) {
        ut->pExtra = NULL;
        ut->flags &= ~UTEXT_EXTRA_HEAP_ALLOCATED;
        ut->extraSize = 0;

    // Zero out function table of the closed UText.  This is a defensive move,
    //   inteded to cause applications that inadvertantly use a closed
    //   utext to crash with null pointer errors.
    ut->pFuncs        = NULL;

    if (ut->flags & UTEXT_HEAP_ALLOCATED) {
        // This UText was allocated by UText setup.  We need to free it.
        // Clear magic, so we can detect if the user messes up and immediately
        //  tries to reopen another UText using the deleted storage.
        ut->magic = 0;
        ut = NULL;
    return ut;

Generated by  Doxygen 1.6.0   Back to index