internal void Add(int locale, CldrTreePath path, int value) { // that's the node we've been looking for! if (path.IsEmpty()) { this.LocaleValues.Add(locale, value); return; } // we need to go deeper CldrTreeNode child; var pathSegment = path.Dequeue(); if (pathSegment.IsDictionaryKey) { if (this.PropertyChildren.TryGetValue(pathSegment.Key, out child) == false) { child = new CldrTreeNode(this.Tree, this); this.PropertyChildren.Add(pathSegment.Key, child); } } else { if (this.ArrayChildren.TryGetElement(pathSegment.Index, out child) == false) { child = new CldrTreeNode(this.Tree, this); this.ArrayChildren.Add(child); } } child.Add(locale, path, value); }
private CldrTreeNode SelectNode(CldrTreePath path) { // that's the node we've been looking for! if (path.IsEmpty()) { return(this); } // we need to go deeper CldrTreeNode child; var pathSegment = path.Dequeue(); if (pathSegment.IsDictionaryKey) { if (this.PropertyChildren.TryGetValue(pathSegment.Key, out child) == false) { return(null); } } else { if (this.ArrayChildren.TryGetElement(pathSegment.Index, out child) == false) { return(null); } } return(child.SelectNode(path)); }
public void Add(CldrLocale locale, string path, int valueId) { var treePath = CldrTreePath.Parse(path); var localeId = this.Locales.GetId(locale ?? CldrLocale.None); this.Root.Add(localeId, treePath, valueId); }
public static CldrTreePath Parse(string path) { var match = PathRegex.Match(path); var keys = match.Groups["key"].Captures.Cast <Capture>().Select(x => new { x.Index, x.Value, IsKey = true }); var indexes = match.Groups["index"].Captures.Cast <Capture>().Select(x => new { x.Index, x.Value, IsKey = false }); var merged = keys.Concat(indexes).OrderBy(x => x.Index); var result = new CldrTreePath(); //if (!match.Success) // throw new FormatException($"Path segment expected to match '{pattern}' but was '{potentialSegment}'."); foreach (var capture in merged) { if (capture.IsKey) { result.Enqueue(new CldrTreePathSegment(capture.Value)); } else { result.Enqueue(new CldrTreePathSegment(int.Parse(capture.Value))); } } return(result); }
/// <summary> /// Selects a tree node using a dot-separated expression. /// </summary> /// <param name="path">The dot-separated expression.</param> public CldrTreeNode SelectNode(string path) { return(SelectNode(CldrTreePath.Parse(path))); }