public static bool ContainsAny(FlagSet a, FlagSet b)
        {
            if (a != null && !a.IsEmpty && b != null && !b.IsEmpty)
            {
                if (a.Count == 1)
                {
                    return(b.Contains(a[0]));
                }
                if (b.Count == 1)
                {
                    return(a.Contains(b[0]));
                }

                if (a.Count > b.Count)
                {
                    ReferenceHelpers.Swap(ref a, ref b);
                }

                foreach (var item in a)
                {
                    if (b.Contains(item))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#2
0
        internal List <Affix <SuffixEntry> > GetMatchingAffixes(string word, FlagSet groupFlagFilter = null)
        {
            if (string.IsNullOrEmpty(word))
            {
                return(new List <Affix <SuffixEntry> >(0));
            }

            var results = new List <Affix <SuffixEntry> >();

            if (AffixesByIndexedByKey.TryGetValue(word[word.Length - 1], out AffixEntryGroupCollection <SuffixEntry> indexedGroups))
            {
                foreach (var group in indexedGroups)
                {
                    if (groupFlagFilter == null || groupFlagFilter.Contains(group.AFlag))
                    {
                        foreach (var entry in group.Entries)
                        {
                            if (HunspellTextFunctions.IsReverseSubset(entry.Key, word))
                            {
                                results.Add(Affix <SuffixEntry> .Create(entry, group));
                            }
                        }
                    }
                }
            }

            if (AffixesWithDots.HasItems)
            {
                results.AddRange(GetMatchingWithDotAffixes(word, HunspellTextFunctions.IsReverseSubset));
            }

            return(results);
        }
示例#3
0
        private bool AddWordCapitalized(string word, FlagSet flags, MorphSet morphs, CapitalizationType capType)
        {
            // add inner capitalized forms to handle the following allcap forms:
            // Mixed caps: OpenOffice.org -> OPENOFFICE.ORG
            // Allcaps with suffixes: CIA's -> CIA'S

            if (
                (
                    capType == CapitalizationType.Huh ||
                    capType == CapitalizationType.HuhInit ||
                    (capType == CapitalizationType.All && flags.HasItems)
                )
                &&
                !flags.Contains(Affix.ForbiddenWord)
                )
            {
                flags = Builder.Dedup(FlagSet.Union(flags, SpecialFlags.OnlyUpcaseFlag));

                var textInfo       = Affix.Culture.TextInfo;
                var initCapBuilder = StringBuilderPool.Get(word);
                if (initCapBuilder.Length > 0)
                {
                    initCapBuilder[0] = textInfo.ToUpper(initCapBuilder[0]);

                    for (var i = 1; i < initCapBuilder.Length; i++)
                    {
                        initCapBuilder[i] = textInfo.ToLower(initCapBuilder[i]);
                    }
                }

                return(AddWord(StringBuilderPool.GetStringAndReturn(initCapBuilder), flags, morphs, true));
            }

            return(false);
        }
示例#4
0
        internal List <AffixEntryGroup <TEntry> > GetAffixesWithEmptyKeysAndFlag(FlagSet flags)
        {
#if DEBUG
            if (flags == null)
            {
                throw new ArgumentNullException(nameof(flags));
            }
#endif

            var results = new List <AffixEntryGroup <TEntry> >(flags.Count);
            foreach (var group in AffixesWithEmptyKeys)
            {
                if (flags.Contains(group.AFlag))
                {
                    results.Add(group);
                }
            }

            return(results);
        }