예제 #1
0
        /// <summary>
        /// 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.
        /// </summary>
        ///
        internal int GetIndexValue()
        {
            if (anteContextLength == pattern.Length)
            {
                // A pattern with just ante context {such as foo)>bar} can
                // match any key.
                return(-1);
            }
            int c = IBM.ICU.Text.UTF16.CharAt(pattern, anteContextLength);

            return((data.LookupMatcher(c) == null) ? (c & 0xFF) : -1);
        }
예제 #2
0
        /// <summary>
        /// Implement UnicodeMatcher
        /// </summary>
        ///
        public virtual int Matches(Replaceable text, int[] offset, int limit,
                                   bool incremental)
        {
            // Note (1): We process text in 16-bit code units, rather than
            // 32-bit code points. This works because stand-ins are
            // always in the BMP and because we are doing a literal match
            // operation, which can be done 16-bits at a time.
            int i;

            int[] cursor = new int[] { offset[0] };
            if (limit < cursor[0])
            {
                // Match in the reverse direction
                for (i = pattern.Length - 1; i >= 0; --i)
                {
                    char           keyChar = pattern[i]; // OK; see note (1) above
                    UnicodeMatcher subm    = data.LookupMatcher(keyChar);
                    if (subm == null)
                    {
                        if (cursor[0] > limit && keyChar == text.CharAt(cursor[0]))       // OK;
                                                                                          // see
                                                                                          // note
                                                                                          // (1)
                                                                                          // above
                        {
                            --cursor[0];
                        }
                        else
                        {
                            return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MISMATCH);
                        }
                    }
                    else
                    {
                        int m = subm.Matches(text, cursor, limit, incremental);
                        if (m != IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH)
                        {
                            return(m);
                        }
                    }
                }
                // Record the match position, but adjust for a normal
                // forward start, limit, and only if a prior match does not
                // exist -- we want the rightmost match.
                if (matchStart < 0)
                {
                    matchStart = cursor[0] + 1;
                    matchLimit = offset[0] + 1;
                }
            }
            else
            {
                for (i = 0; i < pattern.Length; ++i)
                {
                    if (incremental && cursor[0] == limit)
                    {
                        // We've reached the context limit without a mismatch and
                        // without completing our match.
                        return(IBM.ICU.Text.UnicodeMatcher_Constants.U_PARTIAL_MATCH);
                    }
                    char           keyChar_0 = pattern[i]; // OK; see note (1) above
                    UnicodeMatcher subm_1    = data.LookupMatcher(keyChar_0);
                    if (subm_1 == null)
                    {
                        // Don't need the cursor < limit check if
                        // incremental is true (because it's done above); do need
                        // it otherwise.
                        if (cursor[0] < limit && keyChar_0 == text.CharAt(cursor[0]))       // OK;
                                                                                            // see
                                                                                            // note
                                                                                            // (1)
                                                                                            // above
                        {
                            ++cursor[0];
                        }
                        else
                        {
                            return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MISMATCH);
                        }
                    }
                    else
                    {
                        int m_2 = subm_1.Matches(text, cursor, limit, incremental);
                        if (m_2 != IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH)
                        {
                            return(m_2);
                        }
                    }
                }
                // Record the match position
                matchStart = offset[0];
                matchLimit = cursor[0];
            }

            offset[0] = cursor[0];
            return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH);
        }