Beispiel #1
0
 /// <summary>
 /// Construct a matcher that matches a substring of the given
 /// pattern string.
 /// </summary>
 /// <param name="theString">The pattern to be matched, possibly containing
 /// stand-ins that represent nested <see cref="IUnicodeMatcher"/> objects.</param>
 /// <param name="start">First character of <paramref name="theString"/> to be matched.</param>
 /// <param name="limit">Index after the last character of <paramref name="theString"/> to be matched.</param>
 /// <param name="segmentNum">The segment number from 1..n, or 0 if this is not a segment.</param>
 /// <param name="theData">context object mapping stand-ins to <see cref="IUnicodeMatcher"/> objects.</param>
 public StringMatcher(string theString,
                      int start,
                      int limit,
                      int segmentNum,
                      RuleBasedTransliterator.Data theData)
     : this(theString.Substring(start, limit - start), segmentNum, theData) // ICU4N: Corrected 2nd substring parameter
 {
 }
Beispiel #2
0
 /// <summary>
 /// Construct a matcher that matches the given pattern string.
 /// </summary>
 /// <param name="theString">The pattern to be matched, possibly containing
 /// stand-ins that represent nested <see cref="IUnicodeMatcher"/> objects.</param>
 /// <param name="segmentNum">The segment number from 1..n, or 0 if this is
 /// not a segment.</param>
 /// <param name="theData">Context object mapping stand-ins to <see cref="IUnicodeMatcher"/> objects.</param>
 public StringMatcher(string theString,
                      int segmentNum,
                      RuleBasedTransliterator.Data theData)
 {
     data          = theData;
     pattern       = theString;
     matchStart    = matchLimit = -1;
     segmentNumber = segmentNum;
 }
Beispiel #3
0
 /// <summary>
 /// Construct a <see cref="StringReplacer"/> that sets the emits the given output
 /// text and does not modify the cursor.
 /// </summary>
 /// <param name="theOutput">Text that will replace input text when the
 /// <see cref="Replace(IReplaceable, int, int, out int[])"/> method is called.
 /// May contain stand-in characters that represent nested replacers.</param>
 /// <param name="theData">Transliterator context object that translates
 /// stand-in characters to <see cref="IUnicodeReplacer"/> objects.</param>
 public StringReplacer(string theOutput,
                       RuleBasedTransliterator.Data theData)
 {
     output    = theOutput;
     cursorPos = 0;
     hasCursor = false;
     data      = theData;
     isComplex = true;
 }
Beispiel #4
0
        /// <summary>
        /// Construct a matcher that matches a substring of the given
        /// pattern string.
        /// </summary>
        /// <param name="theString">The pattern to be matched, possibly containing
        /// stand-ins that represent nested <see cref="IUnicodeMatcher"/> objects.</param>
        /// <param name="start">First character of <paramref name="theString"/> to be matched.</param>
        /// <param name="limit">Index after the last character of <paramref name="theString"/> to be matched.</param>
        /// <param name="segmentNum">The segment number from 1..n, or 0 if this is not a segment.</param>
        /// <param name="theData">context object mapping stand-ins to <see cref="IUnicodeMatcher"/> objects.</param>
        public StringMatcher(string theString,
                             int start,
                             int limit,
                             int segmentNum,
#pragma warning disable 612, 618
                             RuleBasedTransliterator.Data theData)
#pragma warning restore 612, 618
            : this(theString.Substring(start, limit - start), segmentNum, theData) // ICU4N: Corrected 2nd substring parameter
        {
        }
Beispiel #5
0
        /// <summary>
        /// Construct a <see cref="StringReplacer"/> that sets the emits the given output
        /// text and does not modify the cursor.
        /// </summary>
        /// <param name="theOutput">Text that will replace input text when the
        /// <see cref="Replace(IReplaceable, int, int, int[])"/> method is called.
        /// May contain stand-in characters that represent nested replacers.</param>
        /// <param name="theData">Transliterator context object that translates
        /// stand-in characters to <see cref="IUnicodeReplacer"/> objects.</param>
        public StringReplacer(string theOutput,
#pragma warning disable 612, 618
                              RuleBasedTransliterator.Data theData)
#pragma warning restore 612, 618
        {
            output    = theOutput;
            cursorPos = 0;
            hasCursor = false;
            data      = theData;
            isComplex = true;
        }
Beispiel #6
0
#pragma warning restore 612, 618

        /// <summary>
        /// Construct a matcher that matches the given pattern string.
        /// </summary>
        /// <param name="theString">The pattern to be matched, possibly containing
        /// stand-ins that represent nested <see cref="IUnicodeMatcher"/> objects.</param>
        /// <param name="segmentNum">The segment number from 1..n, or 0 if this is
        /// not a segment.</param>
        /// <param name="theData">Context object mapping stand-ins to <see cref="IUnicodeMatcher"/> objects.</param>
        public StringMatcher(string theString,
                             int segmentNum,
#pragma warning disable 612, 618
                             RuleBasedTransliterator.Data theData)
#pragma warning restore 612, 618
        {
            data          = theData;
            pattern       = theString;
            matchStart    = matchLimit = -1;
            segmentNumber = segmentNum;
        }
Beispiel #7
0
#pragma warning restore 612, 618


        /**
         * 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 cursorPos 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 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.
         * @param segs array of UnicodeMatcher corresponding to input pattern
         * segments, or null if there are none
         * @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
         */
        public TransliterationRule(string input,
                                   int anteContextPos, int postContextPos,
                                   string output,
                                   int cursorPos, int cursorOffset,
                                   IUnicodeMatcher[] segs,
                                   bool anchorStart, bool anchorEnd,
#pragma warning disable 612, 618
                                   RuleBasedTransliterator.Data theData)
#pragma warning restore 612, 618
        {
            data = theData;

            // Do range checks only when warranted to save time
            if (anteContextPos < 0)
            {
                anteContextLength = 0;
            }
            else
            {
                if (anteContextPos > input.Length)
                {
                    throw new ArgumentException("Invalid ante context");
                }
                anteContextLength = anteContextPos;
            }
            if (postContextPos < 0)
            {
                keyLength = input.Length - anteContextLength;
            }
            else
            {
                if (postContextPos < anteContextLength ||
                    postContextPos > input.Length)
                {
                    throw new ArgumentException("Invalid post context");
                }
                keyLength = postContextPos - anteContextLength;
            }
            if (cursorPos < 0)
            {
                cursorPos = output.Length;
            }
            else if (cursorPos > output.Length)
            {
                throw new ArgumentException("Invalid cursor position");
            }

            // 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;

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

            anteContext = null;
            if (anteContextLength > 0)
            {
                anteContext = new StringMatcher(pattern.Substring(0, anteContextLength), // ICU4N: Checked 2nd parameter
                                                0, data);
            }

            key = null;
            if (keyLength > 0)
            {
                key = new StringMatcher(pattern.Substring(anteContextLength, keyLength), // ICU4N: (anteContextLength + keyLength) - anteContextLength == keyLength
                                        0, data);
            }

            int postContextLength = pattern.Length - keyLength - anteContextLength;

            postContext = null;
            if (postContextLength > 0)
            {
                postContext = new StringMatcher(pattern.Substring(anteContextLength + keyLength),
                                                0, data);
            }

            this.output = new StringReplacer(output, cursorPos + cursorOffset, data);
        }