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

U_STABLE int32_t U_EXPORT2 uregex_replaceAll ( URegularExpression regexp,
const UChar *  replacementText,
int32_t  replacementLength,
UChar *  destBuf,
int32_t  destCapacity,
UErrorCode status 
)

Replaces every substring of the input that matches the pattern with the given replacement string. This is a convenience function that provides a complete find-and-replace-all operation.

This method scans the input string looking for matches of the pattern. Input that is not part of any match is copied unchanged to the destination buffer. Matched regions are replaced in the output buffer by the replacement string. The replacement string may contain references to capture groups; these take the form of $1, $2, etc.

Parameters:
regexp The compiled regular expression.
replacementText A string containing the replacement text.
replacementLength The length of the replacement string, or -1 if it is NUL terminated.
destBuf A (UChar *) buffer that will receive the result.
destCapacity The capacity of the desitnation buffer.
status A reference to a UErrorCode to receive any errors.
Returns:
The length of the string resulting from the find and replace operation. In the event that the destination capacity is inadequate, the return value is still the full length of the untruncated string. ICU 3.0

Definition at line 1006 of file uregex.cpp.

References FALSE, NULL, U_FAILURE, and U_ILLEGAL_ARGUMENT_ERROR.

                                                  {
    RegularExpression *regexp = (RegularExpression*)regexp2;
    if (validateRE(regexp, status) == FALSE) {
        return 0;
    }
    if (replacementText == NULL || replacementLength < -1 ||
        destBuf == NULL && destCapacity > 0 ||
        destCapacity < 0) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }

    int32_t   len = 0;

    uregex_reset(regexp2, 0, status);

    // Note: Seperate error code variables for findNext() and appendReplacement()
    //       are used so that destination buffer overflow errors
    //       in appendReplacement won't stop findNext() from working.
    //       appendReplacement() and appendTail() special case incoming buffer
    //       overflow errors, continuing to return the correct length.
    UErrorCode  findStatus = *status;
    while (uregex_findNext(regexp2, &findStatus)) {
        len += uregex_appendReplacement(regexp2, replacementText, replacementLength,
                                        &destBuf, &destCapacity, status);
    }
    len += uregex_appendTail(regexp2, &destBuf, &destCapacity, status);
    
    if (U_FAILURE(findStatus)) {
        // If anything went wrong with the findNext(), make that error trump
        //   whatever may have happened with the append() operations.
        //   Errors in findNext() are not expected.
        *status = findStatus;
    }

    return len;
}


Generated by  Doxygen 1.6.0   Back to index