Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.30 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3.  
  4.  
  5. // 0 == name
  6. // 1 == val
  7. // -1== invalid
  8. class Constant {
  9.     string[,] data;
  10.  
  11.     //int getName(string s) {
  12.         //om nom nom
  13.     //}
  14.  
  15.     int getIndex(string s) {
  16.         switch (s) {
  17.             case "name":
  18.                 return 0;
  19.                 //break;
  20.             case "val":
  21.                 return 1;
  22.                 //break;
  23.             default:
  24.                 return -1; //Bad
  25.         }
  26.     }
  27.  
  28.     public string this[int pos, string field]{
  29.         get{
  30.             return data[pos, getIndex(field)];
  31.         }
  32.         set{
  33.             data[pos, getIndex(field)] = value;
  34.         }
  35.     }
  36.  
  37.     public Constant(int size) {
  38.         data = new String[size, 2];
  39.     }
  40. }
  41.  
  42. /*
  43.  * 0 == name
  44.  * 1 == font
  45.  * 2 == vjustify
  46.  * 3 == hjustify
  47.  * 4 == fontflags
  48.  * 5 == styleflags
  49.  * 6 == textcolor
  50.  * 7 == disabledcolor
  51.  * 8 == highlightcolor
  52.  * 9 == hotkeycolor
  53.  * 10== hyperlinkcolor
  54.  * 11== shadowcolor
  55.  * 12== shadowoffset
  56.  */
  57. class Style {
  58.     string[,] data;
  59.  
  60.     int getIndex(string s) {
  61.         switch (s) {
  62.             case "name":
  63.                 return 0;
  64.                 //break;
  65.             case "val":
  66.                 return 1;
  67.                 //break;
  68.             default:
  69.                 return -1; //Bad
  70.         }
  71.     }
  72.  
  73.     public string this[int pos, string field]{
  74.         get{
  75.             return data[pos, getIndex(field)];
  76.         }
  77.         set{
  78.             data[pos, getIndex(field)] = value;
  79.         }
  80.     }
  81.  
  82.     public Style(int size) {
  83.         data = new String[size, 2];
  84.     }
  85. }
  86.  
  87. class StyleFile {
  88.     private int styleCount;
  89.     private int constCount;
  90.  
  91.     public Constant constants;
  92.     public Style[] styles;
  93.  
  94.  
  95.     public int appendConstant() {
  96.         return ++constCount;
  97.     }
  98.  
  99.     public void setAppended(string field, string value) {
  100.         constants[constCount, field] = value;
  101.         constants[constCount, field] = value;
  102.     }
  103.  
  104.     public void getConstant(int i){ //dummy, only for console out
  105.         Console.WriteLine("<Constant out>");
  106.         Console.WriteLine("   " + constants[i, "name"]);
  107.         Console.WriteLine("   " + constants[i, "val"]);
  108.     }
  109.  
  110.     public StyleFile()
  111.     {
  112.         styleCount=-1;
  113.         constCount=-1;
  114.  
  115.         constants = new Constant(10);
  116.         styles = new Style[5];
  117.  
  118.     }
  119. }
  120.  
  121.  
  122.  
  123.     class Class1
  124.     {
  125.         static void Main(string[] args)
  126.         {
  127.             //XmlTextReader reader = new XmlTextReader("Fonts\\FontStyles.Sc2Style");
  128.             XmlTextReader reader = new XmlTextReader("Fonts\\test.xml");
  129.             StyleFile f = new StyleFile();
  130.  
  131.             while (reader.Read())
  132.             {
  133.                  if(reader.NodeType == XmlNodeType.Element){
  134.                     if (reader.Name == "Constant"){ //If element is a Constant
  135.  
  136.                         Console.WriteLine("<" + reader.Name + ">");
  137.  
  138.                         f.appendConstant();
  139.  
  140.                         reader.MoveToFirstAttribute();
  141.  
  142.                         for (int i = 1; i <= reader.AttributeCount; i++){
  143.                             Console.WriteLine("  " + reader.Name + "=" + reader.Value); //only for console out
  144.                             f.setAppended(reader.Name, reader.Value);
  145.                             reader.MoveToNextAttribute();
  146.                         }
  147.  
  148.                         Console.WriteLine(" ");
  149.                     }
  150.                     else if (reader.Name == "Style") { //if element is a Style
  151.  
  152.                         Console.WriteLine("<" + reader.Name + ">");
  153.  
  154.                         reader.MoveToFirstAttribute();
  155.  
  156.                         for (int i = 1; i <= reader.AttributeCount; i++){ //Only console out for the time being
  157.                             Console.WriteLine("  " + reader.Name + "=" + reader.Value);
  158.                             //f.setAppended(reader.Name, reader.Value);
  159.                             reader.MoveToNextAttribute();
  160.                         }
  161.                    
  162.                     } //disregard other element types
  163.                 }
  164.             }
  165.  
  166.             Console.WriteLine(" ");
  167.             Console.WriteLine(" ");
  168.             Console.WriteLine(" ");
  169.             f.getConstant(0);
  170.             f.getConstant(1);
  171.  
  172.             Console.ReadLine();
  173.         }
  174.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement