// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** * Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description * 11/17/99 aliu Creation. ********************************************************************** */ #include "unicode/utypes.h" #if !UCONFIG_NO_TRANSLITERATION #include "unicode/rep.h" #include "unicode/unifilt.h" #include "unicode/uniset.h" #include "unicode/utf16.h" #include "rbt_rule.h" #include "rbt_data.h" #include "cmemory.h" #include "strmatch.h" #include "strrepl.h" #include "util.h" #include "putilimp.h" static const char16_t FORWARD_OP[] = …; // " > " U_NAMESPACE_BEGIN /** * Construct a new rule with the given input, output text, and other * attributes. A cursor position may be specified for the output text. * @param input input string, including key and optional ante and * post context * @param anteContextPos offset into input to end of ante context, or -1 if * none. Must be <= input.length() if not -1. * @param postContextPos offset into input to start of post context, or -1 * if none. Must be <= input.length() if not -1, and must be >= * anteContextPos. * @param output output string * @param cursorPosition offset into output at which cursor is located, or -1 if * none. If less than zero, then the cursor is placed after the * <code>output</code>; that is, -1 is equivalent to * <code>output.length()</code>. If greater than * <code>output.length()</code> then an exception is thrown. * @param 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. * @param segsCount number of elements in segs[] * @param anchorStart true if the the rule is anchored on the left to * the context start * @param anchorEnd true if the rule is anchored on the right to the * context limit */ 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) : … { … } /** * Copy constructor. */ TransliterationRule::TransliterationRule(TransliterationRule& other) : … { … } TransliterationRule::~TransliterationRule() { … } /** * Return the preceding context length. This method is needed to * support the <code>Transliterator</code> method * <code>getMaximumContextLength()</code>. Internally, this is * implemented as the anteContextLength, optionally plus one if * there is a start anchor. The one character anchor gap is * needed to make repeated incremental transliteration with * anchors work. */ int32_t TransliterationRule::getContextLength() const { … } /** * Internal method. Returns 8-bit index value for this rule. * This is the low byte of the first character of the key, * unless the first character of the key is a set. If it's a * set, or otherwise can match multiple keys, the index value is -1. */ int16_t TransliterationRule::getIndexValue() const { … } /** * Internal method. Returns true if this rule matches the given * index value. The index value is an 8-bit integer, 0..255, * representing the low byte of the first character of the key. * It matches this rule if it matches the first character of the * key, or if the first character of the key is a set, and the set * contains any character with a low byte equal to the index * value. If the rule contains only ante context, as in foo)>bar, * then it will match any key. */ UBool TransliterationRule::matchesIndexValue(uint8_t v) const { … } /** * Return true if this rule masks another rule. If r1 masks r2 then * r1 matches any input string that r2 matches. If r1 masks r2 and r2 masks * r1 then r1 == r2. Examples: "a>x" masks "ab>y". "a>x" masks "a[b]>y". * "[c]a>x" masks "[dc]a>y". */ UBool TransliterationRule::masks(const TransliterationRule& r2) const { … } static inline int32_t posBefore(const Replaceable& str, int32_t pos) { … } static inline int32_t posAfter(const Replaceable& str, int32_t pos) { … } /** * Attempt a match and replacement at the given position. Return * the degree of match between this rule and the given text. The * degree of match may be mismatch, a partial match, or a full * match. A mismatch means at least one character of the text * does not match the context or key. A partial match means some * context and key characters match, but the text is not long * enough to match all of them. A full match means all context * and key characters match. * * If a full match is obtained, perform a replacement, update pos, * and return U_MATCH. Otherwise both text and pos are unchanged. * * @param text the text * @param pos the position indices * @param incremental if true, test for partial matches that may * be completed by additional text inserted at pos.limit. * @return one of <code>U_MISMATCH</code>, * <code>U_PARTIAL_MATCH</code>, or <code>U_MATCH</code>. If * incremental is false then U_PARTIAL_MATCH will not be returned. */ UMatchDegree TransliterationRule::matchAndReplace(Replaceable& text, UTransPosition& pos, UBool incremental) const { … } /** * Create a source string that represents this rule. Append it to the * given string. */ UnicodeString& TransliterationRule::toRule(UnicodeString& rule, UBool escapeUnprintable) const { … } void TransliterationRule::setData(const TransliterationRuleData* d) { … } /** * Union the set of all characters that may be modified by this rule * into the given set. */ void TransliterationRule::addSourceSetTo(UnicodeSet& toUnionTo) const { … } /** * Union the set of all characters that may be emitted by this rule * into the given set. */ void TransliterationRule::addTargetSetTo(UnicodeSet& toUnionTo) const { … } U_NAMESPACE_END #endif /* #if !UCONFIG_NO_TRANSLITERATION */ //eof