public int Compare(object o1, object o2) { Tailoring t1 = (Tailoring)o1; Tailoring t2 = (Tailoring)o2; return(String.CompareOrdinal(t1.TargetString, t2.TargetString)); }
void ProcessTailoringLine (ref Tailoring t, string s) { int idx = s.IndexOf ('#'); if (idx > 0) s = s.Substring (0, idx).Trim (); if (s.Length == 0 || s [0] == '#') return; if (s [0] == '@') { idx = s.IndexOf ('='); if (idx > 0) t = new Tailoring ( int.Parse (s.Substring (1, idx - 1)), int.Parse (s.Substring (idx + 1))); else t = new Tailoring (int.Parse (s.Substring (1))); tailorings.Add (t); return; } if (s.StartsWith ("*FrenchSort")) { t.FrenchSort = true; return; } string d = "*Diacritical"; if (s.StartsWith (d)) { idx = s.IndexOf ("->"); t.AddDiacriticalMap ( byte.Parse (s.Substring (d.Length, idx - d.Length).Trim (), NumberStyles.HexNumber), byte.Parse (s.Substring (idx + 2).Trim (), NumberStyles.HexNumber)); return; } idx = s.IndexOf (':'); if (idx > 0) { string source = s.Substring (0, idx).Trim (); string [] l = s.Substring (idx + 1).Trim ().Split (' '); byte [] b = new byte [4]; for (int i = 0; i < 4; i++) { if (l [i] == "*") b [i] = 0; else b [i] = byte.Parse (l [i], NumberStyles.HexNumber); } t.AddSortKeyMap (ParseTailoringSourceValue (source), b); } idx = s.IndexOf ('='); if (idx > 0) t.AddReplacementMap ( ParseTailoringSourceValue ( s.Substring (0, idx).Trim ()), ParseTailoringSourceValue ( s.Substring (idx + 1).Trim ())); }
TailoringStore ProcessLdml (XmlDocument doc) { XmlElement langElem = doc.SelectSingleNode ( "/ldml/identity/language") as XmlElement; string lang = langElem.GetAttribute ("type"); XmlElement terr = doc.SelectSingleNode ( "/ldml/identity/territory") as XmlElement; string lcid = lang + (terr != null ? "-" + terr.GetAttribute ("type") : null); TailoringStore ts = null; try { ts = new TailoringStore (lcid); } catch (ArgumentException) { Console.Error.WriteLine ("WARNING: culture " + lcid + " is not supported in the runtime."); return null; } // Console.Error.WriteLine ("Processing " + lcid); XmlNode vn = doc.SelectSingleNode ("/ldml/collations/alias/@source"); if (vn != null) { ts.Alias = vn.Value; return ts; } XmlElement collation = doc.SelectSingleNode ("/ldml/collations/collation[@type='standard']") as XmlElement; XmlElement settings = collation.SelectSingleNode ("settings") as XmlElement; if (settings != null) ts.FrenchSort = settings.GetAttribute ("backwards") == "on"; Tailoring t = null; int before = 0; string contraction = null; foreach (XmlNode n in collation.SelectNodes ("rules/*")) { XmlElement el = n as XmlElement; if (el == null) continue; switch (el.LocalName) { case "reset": switch (el.GetAttribute ("before")) { case "primary": before = 1; break; case "secondary": before = 2; break; } switch (el.FirstChild.LocalName) { case "last_primary_ignorable": case "last_secondary_ignorable": Console.Error.WriteLine ("WARNING: {0} is not supported for now.", el.FirstChild.LocalName); continue; } XmlElement cpElem = el.SelectSingleNode ("cp") as XmlElement; string v = ""; if (cpElem != null) v = new string ((char) (int.Parse ( cpElem.GetAttribute ("hex"), NumberStyles.HexNumber)), 1); else v = el.FirstChild.Value; t = new Tailoring (v, before); before = 0; contraction = null; ts.Add (t); break; case "p": case "pc": t.Add (1, el.InnerText); break; case "s": case "sc": t.Add (2, el.InnerText); break; case "t": case "tc": t.Add (3, el.InnerText); break; case "q": case "qc": t.Add (4, el.InnerText); break; case "i": case "ic": t.Add (5, el.InnerText); break; case "x": int contLevel = 0; switch (el.FirstChild.LocalName) { case "s": contLevel = 2; break; case "t": contLevel = 3; break; default: throw new Exception ("Not expected first child of 'x': " + el.Name); } if (contraction != null && el.LastChild.InnerText != contraction) throw new Exception ("When there are sequential 'x' elements for single tailoring, those 'extend' text must be identical."); bool exists = contraction != null; contraction = el.LastChild.InnerText; t.Contraction (contLevel, el.FirstChild.InnerText, exists ? "" : contraction); break; default: throw new Exception ("Support this element: " + el.Name); } } return ts; }
public void Add (Tailoring t) { tailorings.Add (t); }
TailoringStore ProcessLdml(XmlDocument doc) { XmlElement langElem = doc.SelectSingleNode( "/ldml/identity/language") as XmlElement; string lang = langElem.GetAttribute("type"); XmlElement terr = doc.SelectSingleNode( "/ldml/identity/territory") as XmlElement; string lcid = lang + (terr != null ? "-" + terr.GetAttribute("type") : null); TailoringStore ts = null; try { ts = new TailoringStore(lcid); } catch (ArgumentException) { Console.Error.WriteLine("WARNING: culture " + lcid + " is not supported in the runtime."); return(null); } // Console.Error.WriteLine ("Processing " + lcid); XmlNode vn = doc.SelectSingleNode("/ldml/collations/alias/@source"); if (vn != null) { ts.Alias = vn.Value; return(ts); } XmlElement collation = doc.SelectSingleNode("/ldml/collations/collation[@type='standard']") as XmlElement; XmlElement settings = collation.SelectSingleNode("settings") as XmlElement; if (settings != null) { ts.FrenchSort = settings.GetAttribute("backwards") == "on"; } Tailoring t = null; int before = 0; string contraction = null; foreach (XmlNode n in collation.SelectNodes("rules/*")) { XmlElement el = n as XmlElement; if (el == null) { continue; } switch (el.LocalName) { case "reset": switch (el.GetAttribute("before")) { case "primary": before = 1; break; case "secondary": before = 2; break; } switch (el.FirstChild.LocalName) { case "last_primary_ignorable": case "last_secondary_ignorable": Console.Error.WriteLine("WARNING: {0} is not supported for now.", el.FirstChild.LocalName); continue; } XmlElement cpElem = el.SelectSingleNode("cp") as XmlElement; string v = ""; if (cpElem != null) { v = new string ((char)(int.Parse( cpElem.GetAttribute("hex"), NumberStyles.HexNumber)), 1); } else { v = el.FirstChild.Value; } t = new Tailoring(v, before); before = 0; contraction = null; ts.Add(t); break; case "p": case "pc": t.Add(1, el.InnerText); break; case "s": case "sc": t.Add(2, el.InnerText); break; case "t": case "tc": t.Add(3, el.InnerText); break; case "q": case "qc": t.Add(4, el.InnerText); break; case "i": case "ic": t.Add(5, el.InnerText); break; case "x": int contLevel = 0; switch (el.FirstChild.LocalName) { case "s": contLevel = 2; break; case "t": contLevel = 3; break; default: throw new Exception("Not expected first child of 'x': " + el.Name); } if (contraction != null && el.LastChild.InnerText != contraction) { throw new Exception("When there are sequential 'x' elements for single tailoring, those 'extend' text must be identical."); } bool exists = contraction != null; contraction = el.LastChild.InnerText; t.Contraction(contLevel, el.FirstChild.InnerText, exists ? "" : contraction); break; default: throw new Exception("Support this element: " + el.Name); } } return(ts); }
public void Add(Tailoring t) { tailorings.Add(t); }