/// <summary>Renames a yaml key preserving any @suffix</summary> public static void RenameKey(this MiniYamlNode node, string newKey, bool preserveSuffix = true, bool includeRemovals = true) { var prefix = includeRemovals && node.IsRemoval() ? "-" : ""; var split = node.Key.IndexOf("@", StringComparison.Ordinal); if (preserveSuffix && split > -1) { node.Key = prefix + newKey + node.Key.Substring(split); } else { node.Key = prefix + newKey; } }
/// <summary>Returns true if the node is of the form <*match*>, <*match*>@arbitrary or <arbitrary>@*match*</summary> public static bool KeyContains(this MiniYamlNode node, string match, bool ignoreSuffix = true, bool includeRemovals = true) { if (node.Key == null) { return(false); } var atPosition = node.Key.IndexOf('@'); var relevantPart = ignoreSuffix && atPosition > 0 ? node.Key.Substring(0, atPosition) : node.Key; if (relevantPart.Contains(match) && (includeRemovals || !node.IsRemoval())) { return(true); } return(false); }
/// <summary>Returns true if the node is of the form <match> or <match>@arbitrary</summary> public static bool KeyMatches(this MiniYamlNode node, string match, bool ignoreSuffix = true, bool includeRemovals = true) { if (node.Key == null) { return(false); } var prefix = includeRemovals && node.IsRemoval() ? "-" : ""; if (node.Key == prefix + match) { return(true); } // If the previous check didn't return true and we wanted the suffix to match, return false unconditionally here if (!ignoreSuffix) { return(false); } var atPosition = node.Key.IndexOf('@'); return(atPosition > 0 && node.Key.Substring(0, atPosition) == prefix + match); }