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;
		}
Example #2
0
        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);
        }