예제 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Load.
        /// </summary>
        /// <param name="buffer"> The buffer to read from.</param>
        /// <returns>
        ///  True if successful
        /// </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool Load(IBuffer buffer)
        {
            if (_scanner == null)
            {
                _scanner = new InfoScanner(buffer);
            }

            _scanner.Initialize(buffer, this);

            FilePath = buffer.Path;

            string type;

            while ((type = _scanner.ParseType()) != null)
            {
                switch (type)
                {
                case "KeyStart":
                    KeyStart = _scanner.ParseString(true);
                    break;

                case "KeyContinue":
                    KeyContinue = _scanner.ParseString(true);
                    break;

                case "Name":
                    Name = _scanner.ParseString(true);
                    break;

                case "Ext":
                    Extensions = _scanner.ParseArray();
                    break;

                case "Delimiter":
                {
                    if (Delimiters == null)
                    {
                        Delimiters = new List <Delimiter>();
                    }

                    var d = new Delimiter();
                    d.Name   = _scanner.ParseText();
                    d.Start  = _scanner.ParseString(true);
                    d.Escape = _scanner.ParseString(true);
                    d.End    = _scanner.ParseString(true);
                    if (string.IsNullOrEmpty(d.Escape))
                    {
                        d.Escape = "\0";
                    }
                    Delimiters.Add(d);
                }
                break;

                case "Operators":
                    Operators = _scanner.ParseString(true);
                    break;

                case "Punctuation":
                    Punctuation = _scanner.ParseString(true);
                    break;

                case "LineComment":
                    LineComment = _scanner.ParseString(true);
                    break;

                case "BlockComment":
                    BlockComment = _scanner.ParseArray();
                    break;

                case "Keyword":

                    KeyWords = _scanner.ParseMap();
                    break;

                case "Group":
                    Groups = _scanner.ParseArray();
                    break;

                default:
                    break;
                }
                _scanner.NextLine();
            }

            if (KeyWords != null)
            {
                KeyWords.Sort((x, y) => x.Text.CompareTo(y.Text));
            }

            return(true);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Load.
        ///  format:
        ///  Name="Pallete Name"
        ///  TypeName = 0xffffff FontStyle
        ///
        ///  Styles are : Regular = 0,
        ///  Bold = 1,Italic = 2,Underline = 4, Strikeout = 8,
        /// </summary>
        /// <param name="buffer">       The buffer to read from.</param>
        /// <returns>
        ///  True if successful
        /// </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Palette Load(IBuffer buffer)
        {
            string typeName;
            var    p = new Palette();

            var styles   = Enum.GetNames(typeof(FontStyle));
            var _scanner = new InfoScanner();

            _scanner.Initialize(buffer, null);

            // Get name

            p.FilePath = buffer.Path;
            p.Name     = _scanner.ParseString("Name", true);
            int count = 0;

            _scanner.NextLine();

            // Get color pallete slot names and font style BGR order of bytes.
            //    Name       = "Default.palette"
            //    Default    = 0xffffff Regular
            //    Background = 0x000000 Regular
            //    LineNumber = 0xED9564 Regular
            //    End        = 0xD3D3D3 Regular
            //    EOL        = 0xD3D3D3 Regular
            //    Whitespace = 0xD3D3D3 Regular

            while ((typeName = _scanner.ParseText()) != null)
            {
                ++count;
                uint color = 0;
                if (_scanner.Accept('='))
                {
                    var ctxt = _scanner.ParseText();
                    int n    = (ctxt.StartsWith("0x")) ? 2 : 0;

                    while (n < ctxt.Length)
                    {
                        color = color * 16 + (uint)Scanner.HEX_DIGITS.IndexOf(char.ToUpper(ctxt[n++]));
                    }
                }
                var style = _scanner.ParseText();
                _scanner.NextLine();
                var fontId = Array.IndexOf(styles, style);
                if (fontId < 0)
                {
                    fontId = 0;
                }


                // now we have, color, typeName, and style.
                // see if name is in the TypeTable.
                int id;
                for (id = 0; id < TypeTable.Count; ++id)
                {
                    if (TypeTable[id].Equals(typeName, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }

                // id is the type id, so set the current palette color and font style for that id.
                if (id >= TypeTable.Count)
                {
                    TypeTable.Add(typeName);
                }

                p.Colors[id] = new ColorMap(id, color, fontId);
            }

            return(p);
        }