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

U_NAMESPACE_BEGIN TransliterationRule::TransliterationRule ( const UnicodeString input,
int32_t  anteContextPos,
int32_t  postContextPos,
const UnicodeString outputStr,
int32_t  cursorPosition,
int32_t  cursorOffset,
UnicodeFunctor **  segs,
int32_t  segsCount,
UBool  anchorStart,
UBool  anchorEnd,
const TransliterationRuleData theData,
UErrorCode status 
)

Construct a new rule with the given input, output text, and other attributes. A cursor position may be specified for the output text.

Parameters:
input input string, including key and optional ante and post context.
anteContextPos offset into input to end of ante context, or -1 if none. Must be <= input.length() if not -1.
postContextPos offset into input to start of post context, or -1 if none. Must be <= input.length() if not -1, and must be >= anteContextPos.
outputStr output string.
cursorPosition offset into output at which cursor is located, or -1 if none. If less than zero, then the cursor is placed after the output; that is, -1 is equivalent to output.length(). If greater than output.length() then an exception is thrown.
cursorOffset an offset to be added to cursorPos to position the cursor either in the ante context, if < 0, or in the post context, if > 0. For example, the rule "abc{def} > | @@@ xyz;" changes "def" to "xyz" and moves the cursor to before "a". It would have a cursorOffset of -3.
segs array of UnicodeMatcher corresponding to input pattern segments, or null if there are none. The array itself is adopted, but the pointers within it are not.
segsCount number of elements in segs[].
anchorStart TRUE if the the rule is anchored on the left to the context start.
anchorEnd TRUE if the rule is anchored on the right to the context limit.
data the rule data.
status Output parameter filled in with success or failure status.
Construct a new rule with the given input, output text, and other attributes. A cursor position may be specified for the output text.
Parameters:
input input string, including key and optional ante and post context
anteContextPos offset into input to end of ante context, or -1 if none. Must be <= input.length() if not -1.
postContextPos offset into input to start of post context, or -1 if none. Must be <= input.length() if not -1, and must be >= anteContextPos.
output output string
cursorPosition offset into output at which cursor is located, or -1 if none. If less than zero, then the cursor is placed after the output; that is, -1 is equivalent to output.length(). If greater than output.length() then an exception is thrown.
segs array of UnicodeFunctors corresponding to input pattern segments, or null if there are none. The array itself is adopted, but the pointers within it are not.
segsCount number of elements in segs[]
anchorStart TRUE if the the rule is anchored on the left to the context start
anchorEnd TRUE if the rule is anchored on the right to the context limit

Definition at line 55 of file rbt_rule.cpp.

References anteContext, anteContextLength, data, FALSE, flags, key, keyLength, UnicodeString::length(), NULL, output, pattern, postContext, segments, segmentsCount, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, and U_MEMORY_ALLOCATION_ERROR.

                                                             :
    UMemory(),
    segments(0),
    data(theData) {

    if (U_FAILURE(status)) {
        return;
    }
    // Do range checks only when warranted to save time
    if (anteContextPos < 0) {
        anteContextLength = 0;
    } else {
        if (anteContextPos > input.length()) {
            // throw new IllegalArgumentException("Invalid ante context");
            status = U_ILLEGAL_ARGUMENT_ERROR;
            return;
        }
        anteContextLength = anteContextPos;
    }
    if (postContextPos < 0) {
        keyLength = input.length() - anteContextLength;
    } else {
        if (postContextPos < anteContextLength ||
            postContextPos > input.length()) {
            // throw new IllegalArgumentException("Invalid post context");
            status = U_ILLEGAL_ARGUMENT_ERROR;
            return;
        }
        keyLength = postContextPos - anteContextLength;
    }
    if (cursorPosition < 0) {
        cursorPosition = outputStr.length();
    } else if (cursorPosition > outputStr.length()) {
        // throw new IllegalArgumentException("Invalid cursor position");
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return;
    }
    // We don't validate the segments array.  The caller must
    // guarantee that the segments are well-formed (that is, that
    // all $n references in the output refer to indices of this
    // array, and that no array elements are null).
    this->segments = segs;
    this->segmentsCount = segsCount;

    pattern = input;
    flags = 0;
    if (anchorStart) {
        flags |= ANCHOR_START;
    }
    if (anchorEnd) {
        flags |= ANCHOR_END;
    }

    anteContext = NULL;
    if (anteContextLength > 0) {
        anteContext = new StringMatcher(pattern, 0, anteContextLength,
                                        FALSE, *data);
        /* test for NULL */
        if (anteContext == 0) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return;
        }
    }
    
    key = NULL;
    if (keyLength > 0) {
        key = new StringMatcher(pattern, anteContextLength, anteContextLength + keyLength,
                                FALSE, *data);
        /* test for NULL */
        if (key == 0) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return;
        }
    }
    
    int32_t postContextLength = pattern.length() - keyLength - anteContextLength;
    postContext = NULL;
    if (postContextLength > 0) {
        postContext = new StringMatcher(pattern, anteContextLength + keyLength, pattern.length(),
                                        FALSE, *data);
        /* test for NULL */
        if (postContext == 0) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return;
        }
    }

    this->output = new StringReplacer(outputStr, cursorPosition + cursorOffset, data);
    /* test for NULL */
    if (this->output == 0) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }
}


Generated by  Doxygen 1.6.0   Back to index