Beispiel #1
0
        // virtual void SCI_METHOD Lex(Sci_PositionU startPos, i64 lengthDoc, int initStyle, IDocument *pAccess) = 0;
        public static void Lex(IntPtr instance, UIntPtr start_pos, IntPtr length_doc, int init_style, IntPtr p_access)
        {
            /* main lexing method.
             * start_pos is always the startposition of a line
             * length_doc is NOT the total length of a document but the size of the text to be styled
             * init_style is the style of last styled byte
             * p_access is the pointer of the IDocument cpp class
             */
            int    start     = (int)start_pos;
            int    length    = (int)length_doc;
            IntPtr range_ptr = editor.GetRangePointer(start, length);
            string content   = Marshal.PtrToStringAnsi(range_ptr, length);

            for (int i = 0; i < length; i++)
            {
                int    start_position = i;
                string tag            = "";
                int    idx            = 0;

                if (i + 2 < length)
                {
                    tag = content.Substring(i, 3);
                }

                if (Segs1.Contains(tag))
                {
                    idx = 3;
                }
                else if (Segs2.Contains(tag))
                {
                    idx = 5;
                }
                else if (Segs3.Contains(tag))
                {
                    idx = 6;
                }
                else if (Segs4.Contains(tag))
                {
                    idx = 7;
                }

                while (i < length)
                {
                    // read rest of the line
                    if (content[i] == '\n')
                    {
                        break;
                    }
                    i++;
                }
                // style this line
                editor.StartStyling(start + start_position, 0);
                editor.SetStyling(i - start_position, idx);
            }
        }