/// <summary> /// Find the source and target sets, subject to the input filter. /// There is a known issue with filters containing multiple characters. /// </summary> // TODO: Problem: the rule is [{ab}]c > x // The filter is [a{bc}]. // If the input is abc, then the rule will work. // However, following code applying the filter won't catch that case. internal void AddSourceTargetSet(UnicodeSet filter, UnicodeSet sourceSet, UnicodeSet targetSet, UnicodeSet revisiting) { int limit = anteContextLength + keyLength; UnicodeSet tempSource = new UnicodeSet(); UnicodeSet temp = new UnicodeSet(); // We need to walk through the pattern. // Iff some of the characters at ALL of the the positions are matched by the filter, then we add temp to toUnionTo for (int i = anteContextLength; i < limit;) { int ch = UTF16.CharAt(pattern, i); i += UTF16.GetCharCount(ch); IUnicodeMatcher matcher = data.LookupMatcher(ch); if (matcher == null) { if (!filter.Contains(ch)) { return; } tempSource.Add(ch); } else { try { if (!filter.ContainsSome((UnicodeSet)matcher)) { return; } matcher.AddMatchSetTo(tempSource); } catch (InvalidCastException) { // if the matcher is not a UnicodeSet temp.Clear(); matcher.AddMatchSetTo(temp); if (!filter.ContainsSome(temp)) { return; } tempSource.AddAll(temp); } } } // if we made our way through the gauntlet, add to source/target sourceSet.AddAll(tempSource); output.AddReplacementSetTo(targetSet); }
/// <seealso cref="UnicodeSet.ContainsSome(UnicodeSet)"/> /// <draft>ICU4N 60.1</draft> /// <provisional>This API might change or be removed in a future release.</provisional> public static bool ContainsSome <T>(this UnicodeSet set, IEnumerable <T> collection) where T : ICharSequence { if (set == null) { throw new ArgumentNullException(nameof(set)); } return(set.ContainsSome(collection)); }
/// <seealso cref="UnicodeSet.ContainsSome(UnicodeSet)"/> /// <draft>ICU4N 60.1</draft> /// <provisional>This API might change or be removed in a future release.</provisional> public static bool ContainsSome(this UnicodeSet set, IEnumerable <char[]> collection) { if (set == null) { throw new ArgumentNullException(nameof(set)); } return(set.ContainsSome(collection)); }
/// <summary> /// Returns true if this set contains one or more of the characters /// of the given string. /// </summary> /// <param name="set">This set.</param> /// <param name="s">String containing characters to be checked for containment.</param> /// <returns>true if the condition is met.</returns> /// <draft>ICU4N 60.1</draft> /// <provisional>This API might change or be removed in a future release.</provisional> public static bool ContainsSome(this UnicodeSet set, ICharSequence s) { if (set == null) { throw new ArgumentNullException(nameof(set)); } return(set.ContainsSome(s)); }
/// <summary> /// Returns true if this set contains one or more of the characters /// of the given string. /// </summary> /// <param name="set">This set.</param> /// <param name="s">String containing characters to be checked for containment.</param> /// <returns>true if the condition is met.</returns> /// <draft>ICU4N 60.1</draft> /// <provisional>This API might change or be removed in a future release.</provisional> public static bool ContainsSome(this UnicodeSet set, StringBuilder s) { if (set == null) { throw new ArgumentNullException(nameof(set)); } return(set.ContainsSome(s)); }