Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Calculates the width of the phonetic search result for the specified cache entry.
        /// Then it compares it to those already saved up to this point and saves it if it's
        /// wider.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void CalculatePhoneticSrchResultWidth(WordListCacheEntry cacheEntry)
        {
            int beforeEnvTextWidth = TextWidthInTwips(cacheEntry.EnvironmentBefore, m_phoneticColFont) +
                                     kExtraTwipsForPhoneticSrchRsltCol;

            string srchItemAftEnv          = " " + cacheEntry.SearchItem + cacheEntry.EnvironmentAfter;
            int    srchItemAftEnvTextWidth = TextWidthInTwips(srchItemAftEnv, m_phoneticColFont);

            m_beforeEnvTwipWidth          = Math.Max(m_beforeEnvTwipWidth, beforeEnvTextWidth);
            m_maxSrchItemAftEnvTwipsWidth = Math.Max(m_maxSrchItemAftEnvTwipsWidth, srchItemAftEnvTextWidth);
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        private static string GetHeadingTextFromEntry(WordListCacheEntry entry, bool matchBefore,
                                                      bool rightToLeft, int numberPhonesToMatch)
        {
            int phonesToInclude = numberPhonesToMatch;
            int start;

            if (matchBefore)
            {
                if (string.IsNullOrEmpty(entry.EnvironmentBefore))
                {
                    return("#");
                }

                // Figure out how many phones to include in the returned string and
                // which one will be the first one from the phones collection.
                phonesToInclude = Math.Min(phonesToInclude, entry.SearchItemOffset);
                start           = (rightToLeft ? entry.SearchItemOffset - phonesToInclude : 0);
            }
            else
            {
                if (string.IsNullOrEmpty(entry.EnvironmentAfter))
                {
                    return("#");
                }

                int phonesInEnvAfter = entry.Phones.Length -
                                       (entry.SearchItemOffset + entry.SearchItemLength);

                // Figure out how many phones to include in the returned string.
                phonesToInclude = Math.Min(phonesToInclude, phonesInEnvAfter);

                // Figure out which phone is the first phone in the returned string.
                start = (rightToLeft ? entry.Phones.Length - phonesToInclude :
                         entry.SearchItemOffset + entry.SearchItemLength);
            }

            var heading = new StringBuilder();

            for (int i = start; phonesToInclude > 0; i++, phonesToInclude--)
            {
                heading.Append(entry.Phones[i]);
            }

            return((rightToLeft ? "..." : string.Empty) + heading +
                   (!rightToLeft ? "..." : string.Empty));
        }
Пример #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// For the phonetic data in the specified entry, this method gets a pattern
        /// appropriate to the CIE options.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static string GetCIESimilarPattern(WordListCacheEntry entry, CIEOptions cieOptions)
        {
            if (cieOptions.Type == CIEOptions.IdenticalType.After)
            {
                string env = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentAfter, cieOptions), CIEOptions.IdenticalType.After);
                return("*__" + (string.IsNullOrEmpty(env) ? "#" : env));
            }

            if (cieOptions.Type == CIEOptions.IdenticalType.Before)
            {
                string env = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentBefore, cieOptions), CIEOptions.IdenticalType.Before);
                return((string.IsNullOrEmpty(env) ? "#" : env) + "__*");
            }

            string before = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentBefore, cieOptions), CIEOptions.IdenticalType.Before);
            string after  = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentAfter, cieOptions), CIEOptions.IdenticalType.After);

            return((string.IsNullOrEmpty(before) ? "#" : before) + "__" +
                   (string.IsNullOrEmpty(after) ? "#" : after));
        }
Пример #4
0
        /// ------------------------------------------------------------------------------------
        private static string CompareEnvironments(WordListCacheEntry prevEntry,
                                                  WordListCacheEntry currEntry, bool matchBefore, bool rightToLeft,
                                                  int numberPhonesToMatch)
        {
            int x, y;
            int endP, endC;
            int inc     = (rightToLeft ? -1 : 1);
            var phonesP = prevEntry.Phones;
            var phonesC = currEntry.Phones;

            if (matchBefore)
            {
                if (string.IsNullOrEmpty(prevEntry.EnvironmentBefore) &&
                    string.IsNullOrEmpty(currEntry.EnvironmentBefore))
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(prevEntry.EnvironmentBefore))
                {
                    return("#");
                }

                x    = (rightToLeft ? prevEntry.SearchItemOffset - 1 : 0);
                endP = (rightToLeft ? -1 : prevEntry.SearchItemOffset);
                y    = (rightToLeft ? currEntry.SearchItemOffset - 1 : 0);
                endC = (rightToLeft ? -1 : currEntry.SearchItemOffset);
            }
            else
            {
                if (string.IsNullOrEmpty(prevEntry.EnvironmentAfter) &&
                    string.IsNullOrEmpty(currEntry.EnvironmentAfter))
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(prevEntry.EnvironmentAfter))
                {
                    return("#");
                }

                x = (rightToLeft ? phonesP.Length - 1 :
                     prevEntry.SearchItemOffset + prevEntry.SearchItemLength);

                endP = (rightToLeft ?
                        prevEntry.SearchItemOffset + prevEntry.SearchItemLength - 1 :
                        phonesP.Length);

                y = (rightToLeft ? phonesC.Length - 1 :
                     currEntry.SearchItemOffset + currEntry.SearchItemLength);

                endC = (rightToLeft ?
                        currEntry.SearchItemOffset + currEntry.SearchItemLength - 1 :
                        phonesC.Length);
            }

            bool match = false;
            int  count = numberPhonesToMatch;

            while (x != endP && y != endC && count > 0)
            {
                if (phonesP[x] != phonesC[y])
                {
                    match = false;
                    break;
                }

                match = true;
                x    += inc;
                y    += inc;
                count--;
            }

            return(match ? null : GetHeadingTextFromEntry(prevEntry, matchBefore,
                                                          rightToLeft, numberPhonesToMatch));
        }