예제 #1
0
        public int Compare(object o1, object o2)
        {
            TailoringStore t1 = (TailoringStore)o1;
            TailoringStore t2 = (TailoringStore)o2;

            return(t1.Culture.LCID - t2.Culture.LCID);
        }
예제 #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;
		}
예제 #3
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);
        }
예제 #4
0
        void Run(string [] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("specify arguments: path_to_ldml_files config_file");
                return;
            }
            string dirname        = args [0];
            string configFileName = args [1];
            string config         = null;

            using (StreamReader sr = new StreamReader(configFileName)) {
                config = sr.ReadToEnd();
            }
            foreach (string configLine in config.Split('\n'))
            {
                int    idx  = configLine.IndexOf('#');
                string line = idx < 0 ? configLine : configLine.Substring(0, idx);
                if (line.StartsWith("ignore: "))
                {
                    ignoredFiles.Add(line.Substring(8).Trim());
                }
            }

            XmlTextReader  rng = new XmlTextReader("ldml-limited.rng");
            RelaxngPattern p   = RelaxngPattern.Read(rng);

            rng.Close();

            foreach (FileInfo fi in new DirectoryInfo(dirname).GetFiles("*.xml"))
            {
                if (ignoredFiles.Contains(fi.Name))
                {
                    continue;                     // skip
                }
                XmlTextReader inst = null;
                try {
                    inst             = new XmlTextReader(fi.FullName);
                    inst.XmlResolver = null;
                    RelaxngValidatingReader rvr = new
                                                  RelaxngValidatingReader(inst, p);
                    rvr.ReportDetails = true;
                    XmlDocument doc = new XmlDocument();
                    doc.XmlResolver = null;
                    doc.Load(rvr);
                    TailoringStore ts = ProcessLdml(doc);
                    if (ts != null)
                    {
                        tailorings.Add(ts);
                    }
                } finally {
                    if (inst != null)
                    {
                        inst.Close();
                    }
                }
            }

            tailorings.Sort(TailoringStoreComparer.Instance);

            using (TextWriter tw = new StreamWriter("create-tailoring.out", false, System.Text.Encoding.UTF8)) {
                Serialize(tw);
            }
        }