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

U_STABLE int32_t U_EXPORT2 uregex_group ( URegularExpression regexp,
int32_t  groupNum,
UChar *  dest,
int32_t  destCapacity,
UErrorCode status 
)

Extract the string for the specified matching expression or subexpression. Group #0 is the complete string of matched text. Group #1 is the text matched by the first set of capturing parentheses.

Parameters:
regexp The compiled regular expression.
groupNum The capture group to extract. Group 0 is the complete match. The value of this parameter must be less than or equal to the number of capture groups in the pattern.
dest Buffer to receive the matching string data
destCapacity Capacity of the dest buffer.
status A reference to a UErrorCode to receive any errors.
Returns:
Length of matching data, or -1 if no applicable match. ICU 3.0

Definition at line 596 of file uregex.cpp.

References FALSE, NULL, U_BUFFER_OVERFLOW_ERROR, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, and U_STRING_NOT_TERMINATED_WARNING.

                                           {
    RegularExpression *regexp = (RegularExpression*)regexp2;
    if (validateRE(regexp, status) == FALSE) {
        return 0;
    }
    if (destCapacity < 0 || (destCapacity > 0 && dest == NULL)) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }
    
    if (destCapacity == 0 || regexp->fText != NULL) {
        // If preflighting or if we already have the text as UChars,
        // this is a little cheaper than going through uregex_groupUText()
        
        //
        // Pick up the range of characters from the matcher
        //
        int32_t  startIx = regexp->fMatcher->start(groupNum, *status);
        int32_t  endIx   = regexp->fMatcher->end  (groupNum, *status);
        if (U_FAILURE(*status)) {
            return 0;
        }

        //
        // Trim length based on buffer capacity
        // 
        int32_t fullLength = endIx - startIx;
        int32_t copyLength = fullLength;
        if (copyLength < destCapacity) {
            dest[copyLength] = 0;
        } else if (copyLength == destCapacity) {
            *status = U_STRING_NOT_TERMINATED_WARNING;
        } else {
            copyLength = destCapacity;
            *status = U_BUFFER_OVERFLOW_ERROR;
        }
        
        //
        // Copy capture group to user's buffer
        //
        if (copyLength > 0) {
            u_memcpy(dest, &regexp->fText[startIx], copyLength);
        }
        return fullLength;
    } else {
        UText *groupText = uregex_groupUText(regexp2, groupNum, NULL, status);
        int32_t result = utext_extract(groupText, 0, utext_nativeLength(groupText), dest, destCapacity, status);
        utext_close(groupText);
        return result;
    }
}


Generated by  Doxygen 1.6.0   Back to index