private void OnOptionVariableTop(object sender, ActionEventArgs args) { IcuDataObject attr = IcuDataObject.CreateAttribute("variableTop"); IcuDataObject previousNode = _currentNodes[_currentNodes.Count - 1]; if (previousNode.Name == "x") { throw new ApplicationException("[variable top] cannot follow an extended node (prefix, expasion, or both)."); } if (previousNode.InnerText.Length == 0) { throw new ApplicationException("[variable top] cannot follow an indirect position"); } string unescapedValue = previousNode.InnerText; string escapedValue = string.Empty; for (int i = 0; i < unescapedValue.Length; i++) { escapedValue += String.Format("u{0:X}", Char.ConvertToUtf32(unescapedValue, i)); // if we had a surogate, that means that two "char"s were encoding one code point, // so skip the next "char" as it was already handled in this iteration if (Char.IsSurrogate(unescapedValue, i)) { i++; } } attr.Value = escapedValue; AddSettingsAttribute(attr); }
private void OnOptionStrength(object sender, ActionEventArgs args) { IcuDataObject attr = IcuDataObject.CreateAttribute("strength"); switch (args.Value[args.Value.Length - 1]) { case '1': attr.Value = "primary"; break; case '2': attr.Value = "secondary"; break; case '3': attr.Value = "tertiary"; break; case '4': attr.Value = "quaternary"; break; case '5': case 'I': case 'i': attr.Value = "identical"; break; default: Debug.Assert(false, "Unhandled strength option."); break; } AddSettingsAttribute(attr); }
private void OnOptionHiraganaQ(object sender, ActionEventArgs args) { IcuDataObject attr = IcuDataObject.CreateAttribute("hiraganaQuaternary"); attr.Value = args.Value.EndsWith("on") ? "on" : "off"; AddSettingsAttribute(attr); }
// The extended element is the trickiest one becuase the operator gets nested in an extended tag, and // can be preceded by another element as well. Here's a simple rule: // &a < b => <reset>a</reset><p>b</p> // And the extended one for comparison: // &a < b | c / d => <reset>a</reset><x><context>b</context><p>c</p><extend>d</extend></x> // The operator tag is inserted inside the "x" tag, and comes after the "context" tag (represented by '|') private void OnExtendedDifference(object sender, ActionEventArgs args) { // There should always at least be 2 nodes by this point - reset and either prefix or expansion Debug.Assert(_currentNodes.Count >= 2); IcuDataObject differenceNode = IcuDataObject.CreateElement("x"); IcuDataObject dataNode = IcuDataObject.CreateElement(_currentOperators.Pop()); dataNode.AppendChild(_currentDataObjects.Pop()); IcuDataObject prefixNode = _currentNodes[_currentNodes.Count - 2]; IcuDataObject expansionNode = _currentNodes[_currentNodes.Count - 1]; int deleteCount = 0; if (expansionNode.Name != "extend") { prefixNode = expansionNode; expansionNode = null; } if (prefixNode.Name == "context") { differenceNode.AppendChild(prefixNode); deleteCount++; } differenceNode.AppendChild(dataNode); if (expansionNode != null) { differenceNode.AppendChild(expansionNode); deleteCount++; } _currentNodes.RemoveRange(_currentNodes.Count - deleteCount, deleteCount); _currentNodes.Add(differenceNode); }
private void AddXmlNodeWithData(string name) { IcuDataObject ido = IcuDataObject.CreateElement(name); ido.AppendChild(_currentDataObjects.Pop()); _currentNodes.Add(ido); }
private void OnOptionOptimize(object sender, ActionEventArgs args) { Debug.Assert(_currentCharacterSet != null); var element = IcuDataObject.CreateElement("optimize"); element.AppendChild(IcuDataObject.CreateText(_currentCharacterSet)); _optionElements.Add(element); _currentCharacterSet = null; }
private void OnOptionNormal(object sender, ActionEventArgs args) { Regex regex = new Regex("(\\S+)\\s+(\\S+)"); Match match = regex.Match(args.Value); Debug.Assert(match.Success); IcuDataObject attr = IcuDataObject.CreateAttribute(match.Groups[1].Value, match.Groups[2].Value); AddSettingsAttribute(attr); }
private void OnReset(object sender, ActionEventArgs args) { IcuDataObject ido = IcuDataObject.CreateElement(((Spart.Parsers.NonTerminal.Rule)sender).ID); foreach (IcuDataObject attr in _attributesForReset) { ido.AppendChild(attr); } ido.AppendChild(_currentDataObjects.Pop()); _currentNodes.Add(ido); _attributesForReset = new Queue <IcuDataObject>(); }
private void AddSettingsAttribute(IcuDataObject attr) { IcuDataObject settings = null; foreach (var option in _optionElements) { if (option.Name == "settings") { settings = option; break; } } if (settings == null) { settings = IcuDataObject.CreateElement("settings"); _optionElements.Insert(0, settings); } settings.InsertChild(attr); }
private IcuDataObject CreateOptimizedNode(List <IcuDataObject> nodeGroup) { Debug.Assert(nodeGroup != null); Debug.Assert(nodeGroup.Count > 0); // one node is already optimized if (nodeGroup.Count == 1) { return(nodeGroup[0]); } // luckily the optimized names are the same as the unoptimized with 'c' appended // so <p> becomes <pc>, <s> to <sc>, et al. IcuDataObject optimizedNode = IcuDataObject.CreateElement(nodeGroup[0].Name + "c"); foreach (IcuDataObject node in nodeGroup) { optimizedNode.AppendChild(IcuDataObject.CreateText(node.InnerText)); } return(optimizedNode); }
private void OnOptionBackwards(object sender, ActionEventArgs args) { IcuDataObject attr = IcuDataObject.CreateAttribute("backwards"); switch (args.Value[args.Value.Length - 1]) { case '1': attr.Value = "off"; break; case '2': attr.Value = "on"; break; default: Debug.Assert(false, "Unhandled backwards option."); break; } AddSettingsAttribute(attr); }
private void OnTop(object sender, ActionEventArgs args) { // [top] is deprecated in ICU and not directly allowed in LDML // [top] is probably best rendered the same as [last regular] _currentDataObjects.Push(IcuDataObject.CreateElement("last_non_ignorable")); }
private void OnIndirectPosition(object sender, ActionEventArgs args) { _currentDataObjects.Push(IcuDataObject.CreateElement(_currentIndirectPosition.ToString())); _currentIndirectPosition = new StringBuilder(); }
private void OnDataString(object sender, ActionEventArgs args) { _currentDataObjects.Push(IcuDataObject.CreateText(_currentDataString.ToString())); _currentDataString = new StringBuilder(); }
private void AddAttributeForReset(string name, string value) { IcuDataObject attr = IcuDataObject.CreateAttribute(name, value); _attributesForReset.Enqueue(attr); }