/// <summary> /// If the first key of <see cref="sequences"/> matches a known child, /// return that child. Otherwise, return null. /// If <see cref="flags"/> has the <see cref="Search.Prefixes"/> flag /// and we are a rule with no children, we return null. This lets us /// check for strict prefixes. /// If <see cref="flags"/> has the <see cref="Search.Sequences"/> flag /// and we are not a rule (just a node in the tree), we do not return /// the current node (but we do return children sequences). /// </summary> private SequenceNode GetSubtree(KeySequence sequence, Search flags) { if (sequence.Count == 0) { if ((flags & Search.Prefixes) != 0 && m_children.Count == 0) { return(null); } if ((flags & Search.Sequences) != 0 && m_results.Count == 0) { return(null); } return(this); } KeySequence keys = new KeySequence { sequence[0] }; if ((flags & Search.IgnoreCase) != 0 && sequence[0].IsPrintable) { Key upper = new Key(sequence[0].PrintableResult.ToUpper()); if (upper != sequence[0]) { keys.Add(upper); } Key lower = new Key(sequence[0].PrintableResult.ToLower()); if (lower != sequence[0]) { keys.Add(lower); } } foreach (Key k in keys) { if (!m_children.ContainsKey(k)) { continue; } var subsequence = sequence.GetRange(1, sequence.Count - 1); var subtree = m_children[k].GetSubtree(subsequence, flags); if (subtree != null) { return(subtree); } } return(null); }
private void InsertSequence(KeySequence path, SequenceDescription item) { if (path.Count == 0) { m_results.Add(item); return; } if (!m_children.TryGetValue(path[0], out var child)) { m_children.Add(path[0], child = new SequenceNode()); } child.InsertSequence(path.GetRange(1, path.Count - 1), item); }
public void InsertSequence(KeySequence sequence, string result, int utf32, string desc) { if (sequence.Count == 0) { m_result = result; m_utf32 = utf32; m_description = desc; return; } if (!m_children.ContainsKey(sequence[0])) { m_children.Add(sequence[0], new SequenceNode()); } var subsequence = sequence.GetRange(1, sequence.Count - 1); m_children[sequence[0]].InsertSequence(subsequence, result, utf32, desc); }
private void InsertSequence(KeySequence path, SequenceDescription item) { if (path.Count == 0) { // If this is a conflict, warn about it if (m_results.Count > 0 && m_results[0].Result != item.Result) { Logger.Warn($"Conflicting sequence for {item.Sequence.FriendlyName}: had {m_results[0].Result}, got {item.Result}"); } // Insert sequence at index 0 to give precedence to user sequences m_results.Insert(0, item); return; } if (!m_children.TryGetValue(path[0], out var child)) { m_children.Add(path[0], child = new SequenceNode()); } child.InsertSequence(path.GetRange(1, path.Count - 1), item); }