RichTextBox 文本处理:序号,特殊符号处理(持续更新)。

 只放上了部分代码:

          以后有时间我会把全部代码放上来,有兴趣或有疑问的朋友 请留言。

 序号处理

        /// <summary>
        /// 把字符串的数字或者字母加一位,其它非数字或者字母忽略,例: a1 -> a2 , 1ab -> 1ac  19 -> 20, 99-> 100
        /// </summary>
        /// <param name="sText"></param>
        /// <returns></returns>
        /// 创建时间:2022-09-11     最后一次修改时间:2022-09-11
        public static string _TryStrAndOne(this string sText)
        {
           if (sText == "") return "1";             

           int nLast = sText.Length - 1;

           char ch = sText[nLast];

           if(ch._IsDigit())
           {
                if(ch != '9')
                {
                    return sText.Substring(0,nLast) +  (Char) ( (int)ch  + 1);   // 1->2                 
                }
                else //进位,前面字符加1
                {
                    return _TryStrAndOne(sText.Substring(0, nLast)) + '0';
                }
           }
           else if(ch._IsEnglishLetters())
           {
               if (ch != 'z' && ch != 'Z')
               {
                    return sText.Substring(0, nLast) + (Char)((int)ch + 1); // a->b;                     
               }
               else //进位,前面字符加1
               {
                    if(ch == 'z')
                        return _TryStrAndOne(sText.Substring(0, nLast)) + 'a';
                    else
                        return _TryStrAndOne(sText.Substring(0, nLast)) + 'Z';
               }
           }   
           else
           {          
                return _TryStrAndOne(sText.Substring(0, nLast)) + ch;
           }
        }

 效果例子:

   

特殊符号处理

效果例子:

 

  键盘事件

 //----------------------------------------------------------------------------------------------------------键盘事件
        /// <summary>
        /// 按下键盘未释放之前,此时文本框还保持原样
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 创建时间: 2021-10-17      最后一次修改时间:2022-09-12
        private void RichTextBox_KeyDown(object sender, KeyEventArgs e)
        {   

            //-----------------------------------------------------------------------------------------------------------------普通书写
            if (SyntaxAnalysisType == LSyntaxAnalysisType.saBook)
            {

                /*
                  	• Android 简介
	                • Android 版本及其功能集

                    如查检查行开始处有特殊符号,则按下Enter键,下一行会自动出现特殊符号

                    • 
                */
                string sTag = "◆☑•□●*";

                //◆ ---------------------------------------------------------------------------当Keys.Enter按下时发生
                if (e.KeyCode == Keys.Enter)
                {
                    //(1)-----------------------------------------------------------------------处理行号与特殊符号

                    int nPos = CurrentLineText._FindFirstAnyoneChar(sTag).First;
                     
                    if (nPos != -1 && CurrentLineText.Substring(0, nPos)._IsWhiteSpaceOrNotPrintable())  //有特殊字符,且特殊字符前面全是空格或者不可打印字符
                    {
                        int nSelectLength = CurrentLineText._FindFirstPrintable(CurrentLineText[nPos].ToString());
                        
                        if (nSelectLength != -1)
                        {
                             
                            IsLockPaint = true;


                            int nOldSelectionStart = SelectionStart;
                            int nOldSelectionLength = SelectionLength;
                            Font fOldFont = SelectionFont;

                            int nTextPosForLineStart = GetFirstCharIndexOfCurrentLine();


                            SelectionStart = nTextPosForLineStart;
                            SelectionLength = nSelectLength;
                            SelectionFont = new Font(fOldFont, FontStyle.Bold);

                            string sRtf = SelectedRtf;

                            SelectionStart = nOldSelectionStart;
                            SelectionLength = nOldSelectionLength;


                            //在当前位置插入换行符
                            SelectedText = "\n";  //在光标处插入换行符

                            SelectedRtf = sRtf;

                            SelectionFont = fOldFont;

                            e.Handled = true; //已经插入换行符,不需要再换行

                            IsLockPaint = false;
                        }

                    }//-----------------------------------------------------------------------行号和字符End
                    else
                    {
                        //(2)处理章节,例:1.1.1  ????
                        //                1.1.2 
                        IsLockPaint = true;

                        if (SetBook标题样式(CurrentLineText,e))
                        { 
                            SelectionFont = HeadlineStyle.MainBody;
                            SelectedText = "\n";
                        }
                        else if( !m_IsOrderNumberSection)  //1.  2.  3.
                        {                          
                
                            if (SetBook章节样式(CurrentLineText, e))
                            {                               

                                m_IsOrderNumberSection = true;
                                SelectionFont = HeadlineStyle.MainBody;
                            }
                            else //-------------------------------------如果当前行是缩进的,那么下一行也是缩进的        
                            {
                                string sCopy = CurrentLineText._CopyControlAndWhiteSpace();

                                if (sCopy.Length > 0)
                                {
                                    SelectedText = "\n" + sCopy;
                                    e.Handled = true;
                                }
                            }
                            //SelectedText = "\n";
                        }
                        else //---------------------------------------------------------------------------------在序号段落中 
                        {

                            if(SetBook章节样式(CurrentLineText, e))
                            {

                            }
                            else
                            {

                                int n = CurrentLineText._FindLastPrintable();

                                if (n == -1)  //空白行
                                {
                                    //lg.D("111111111111111111111111111111111111");                                 

                                    //如果当前行是缩进的,那么下一行也是缩进的
                                    string sCopy = CurrentLineText._CopyControlAndWhiteSpace();

                                    if (sCopy.Length > 0)
                                    {
                                        SelectedText = Environment.NewLine + sCopy;

                                        e.Handled = true;
                                    }

                                    //lg.D("CurrentLineText2=\"" + CurrentLineText + "\"");
                                }
                                else
                                {
                                    string sCurrLineOrder = CurrentLineText._GetBook_序号标记();


                                    if (sCurrLineOrder == "")  //-------------------------------------------------------------------当前行不含序号
                                    {

                                        if (CurrentLineText[n] == '。') //序号标记以句号和Enter
                                        {
                                            //lg.StartTime();
                                            //查找前面20行内的序号标记,不包含当前行。
                                            StringList_ slBefore = this._GetLineListBeforeOfCursor(CurrentRowNumber - 1);

                                            string sOrder = "";
                                            string sblankSpace = "";

                                            foreach (string s in slBefore)
                                            {
                                                sOrder = s._GetBook_序号标记();
                                                if (sOrder != "")
                                                {
                                                    sblankSpace = s._CopyControlAndWhiteSpace();
                                                    break;
                                                }
                                            }

                                            if (sOrder != "")
                                            {
                                                string sOrderNext = sOrder._TryStrAndOne();

                                                bool bFind = false;
                                                //查找后面二十行的序号标记
                                                StringList_ slBack = this._GetLineListBackOfCursor(CurrentRowNumber - 1);
                                                foreach (string s in slBack)
                                                {
                                                    if (s._GetBook_序号标记()._RemoveUnprintableAndWhitespace() == sOrderNext._RemoveUnprintableAndWhitespace())
                                                    {
                                                        bFind = true;
                                                        break;
                                                    }
                                                }

                                                if (!bFind)
                                                {
                                                    SelectedText = "\n\n" + sOrderNext;
                                                    Font f = SelectionFont;
                                                    this._SetCurrLineFontStyle(sOrderNext, new Font(f, FontStyle.Bold));
                                                    SelectionFont = new Font(f, FontStyle.Regular);
                                                    e.Handled = true;
                                                }
                                            }
                                            else  //-----------------找不到标记
                                            {
                                                //lg.D("222222222222222222222222222222");
                                                //如果当前行是缩进的,那么下一行也是缩进的
                                                string sCopy = CurrentLineText._CopyControlAndWhiteSpace();
                                                if (sCopy.Length > 0)
                                                {
                                                    SelectedText = "\n" + sCopy;
                                                    e.Handled = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            //lg.D("333333333333333333333333333333");
                                            //如果当前行是缩进的,那么下一行也是缩进的
                                            string sCopy = CurrentLineText._CopyControlAndWhiteSpace();
                                            if (sCopy.Length > 0)
                                            {
                                                SelectedText = "\n   " + sCopy;
                                                e.Handled = true;
                                            }
                                        }

                                    }
                                    else //--------------------------------------------当前行含有序号,不用再查找 
                                    {

                                        this._SetCurrLineFontStyle(sCurrLineOrder, new Font(SelectionFont, FontStyle.Bold), CurrentLineText);  //重新设置加粗 或者 加粗重设一遍

                                        SelectionFont = new Font(SelectionFont, FontStyle.Regular);


                                        string sOrderNext = sCurrLineOrder._TryStrAndOne();


                                        bool bFind = false;
                                        //查找后面二十行的序号标记
                                        StringList_ slBack = this._GetLineListBackOfCursor(CurrentRowNumber - 1);
                                        foreach (string s in slBack)
                                        {
                                            if (s._GetBook_序号标记()._RemoveUnprintableAndWhitespace() == sOrderNext._RemoveUnprintableAndWhitespace())
                                            {
                                                bFind = true;
                                                break;
                                            }
                                        }

                                        if (!bFind)
                                        {
                                            SelectedText = "\n\n" + sOrderNext;
                                            Font f = SelectionFont;
                                            this._SetCurrLineFontStyle(sOrderNext, new Font(f, FontStyle.Bold));
                                            SelectionFont = f;
                                            e.Handled = true;
                                        }
                                        else  //序号标记已出现在下面,可能只是修改前面的内容。
                                        {

                                            //缩进 + sCurrLineOrder.Length + 空格
                                            string sCopy = CurrentLineText._CopyControlAndWhiteSpace();
                                            if (sCopy.Length > 0)
                                            {
                                                SelectedText = "\n  " + sCopy + ""._AppendString(" ", sCurrLineOrder.Length);
                                                e.Handled = true;
                                            }
                                        }

                                        //lg.D("1", this);                                  
                                    }
                                }
                            }

                            
       
                
                        }


                        IsLockPaint = false;

                    }
                }
                else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
                {

                    //GetInfo();
                }
                else if (e.KeyCode == Keys.Back)//----------------------------------------------------------------------处理退格键 
                {
                    //退格设置SelectionIndent=0,不设置的话是到不了行开头的。
                    SelectionIndent = 0;

                    if (CurrentLineText.Length == 0) return;

                    int nCurrPos = CurrentColumnNumber - 2; //光标左边的字符

                     
                    
                    if(CurrentLineText.Length == 0) { return; } 

                    if(nCurrPos <= 0 || nCurrPos >= CurrentLineText.Length ) { return; }   

                    string sLeft = CurrentLineText.Substring(0, nCurrPos);
                     
                  
                    //当前行是否全是空格和不可见字符
                    if (CurrentLineText._IsWhiteSpaceOrNotPrintable()) //-----------------------------------------------当前行全是空格和不可见字符
                    {
                        //在序号段落中
                        if (m_IsOrderNumberSection)
                        {
                            
                            //找出最近的 sOrder

                            //如果光标10行以内包括光标行出来序号标记,则认为是在序号段内。
                            StringList_ sl = this._GetLineListBeforeOfCursor(CurrentRowNumber, 10);
                            string sLast = "";
                            DListNote_<string> dn = sl.First;
                            while (dn != null)
                            {
                                sLast = dn.Data._GetBook_序号标记();

                                if (sLast != "") { break; }

                                dn = dn.Next;
                            }

                    

                            //lg.D("在序号段落中,且 sLast = " + sLast, "e.KeyCode == Keys.Back");

                            if (sLast.Length > 0  &&  m_KeyeventStack.ContinuationKeyCount(Keys.Back) <= 2)    
                            {
                                IsLockPaint = true;

                                Font oldFont = this.SelectionFont;

                                SelectionStart = GetFirstCharIndexOfCurrentLine();
                                SelectionLength = CurrentLineText.Length;

                                SelectionFont = new Font(oldFont, FontStyle.Bold);

                                SelectedText = sLast._TryStrAndOne();
                                SelectionFont = new Font(oldFont, FontStyle.Regular);
                              
                                IsLockPaint = false;
                                e.Handled = true;                                 
                            }
                            else //直接删除所有空格和控制字符
                            {
                                IsLockPaint = true;
                                SelectionStart = GetFirstCharIndexOfCurrentLine();
                                SelectionLength = CurrentLineText.Length;
                                SelectedText = "";
                                SelectionFont = new Font(SelectionFont, FontStyle.Regular);
                                IsLockPaint = false;
                                e.Handled = true;
                            }
                        }
                        else  //直接删除所有空格和控制字符
                        {
                            IsLockPaint = true;
                            SelectionStart = GetFirstCharIndexOfCurrentLine();
                            SelectionLength = CurrentLineText.Length;
                            SelectedText = "";
                            SelectionFont = new Font(SelectionFont, FontStyle.Regular);
                            IsLockPaint = false;
                            e.Handled = true;
                        }
                    }
                    else //--------------------------------------------------------------------------光标前面有字符
                    { 

                         
                        string sOrder = CurrentLineText._GetBook_序号标记();

                        //lg.D("在序号段落中sOrder=" + sOrder,"e.KeyCode == Keys.Back");

                        if (sOrder != "")  //-------------------------------------------当臆行有序号标记
                        {
                            if (sOrder._RemoveWCPrintable()  ==  CurrentLineText._RemoveWCPrintable()) //----------删除序号标记
                            {

                                if( m_KeyeventStack.ContinuationKeyCount(Keys.Back) >= 3)  //3次Back或者以上
                                {
                                    e.Handled = true;


                                    IsLockPaint = true;


                                    SelectionStart = GetFirstCharIndexOfCurrentLine();
                                    SelectionLength = CurrentLineText.Length;

                                    SelectedText = "";

                                    SelectionFont = new Font(SelectionFont, FontStyle.Regular);

                                    IsLockPaint = false;
                                }
                                else
                                {
                                    e.Handled = true;


                                    IsLockPaint = true;


                                    SelectionStart = GetFirstCharIndexOfCurrentLine();
                                    SelectionLength = CurrentLineText.Length;

                                    string s = sOrder._RemoveWCPrintable();
                                     
                                    //其它字符用两个空格,. 用一个空格。

                                    SelectedText = sOrder.Replace(s, ""._AppendString(" ", (s.Length - 1 )* 2 + 1) );

                                    SelectionFont = new Font(SelectionFont, FontStyle.Regular);

                                    IsLockPaint = false;

                                }   

                                //m_IsOrderNumberSection = false; 这里不要去设置,在鼠标点击事件中去设置 m_IsOrderNumberSection标记  2022-09-11
                            }
                            else  //--------------------------------------------什么也不做
                            {
                                //lg.D("selft=" + sLeft, this);
                                //lg.D("sOrder=" + sOrder, this);
                                //lg.ShowInfo(CurrentLineText[nCurrPos]);
                            }
                        }
                        else  //-----------------------------------------------------当前行没有序号标记
                        {
                            //找出最近的 sOrder

                            //如果光标10行以内包括光标行出来序号标记,则认为是在序号段内。
                            StringList_ sl = this._GetLineListBeforeOfCursor(CurrentRowNumber, 10);
                            string sLast = "";
                            DListNote_<string> dn = sl.First;
                            while (dn != null)
                            {
                                sLast = dn.Data._GetBook_序号标记();

                                if (sLast != "") { break; }

                                dn = dn.Next;
                            }

                            //lg.D("在序号段落中,且 sLast = " + sLast, "e.KeyCode == Keys.Back");

                            if (sLast.Length > 0 && CurrentColumnNumber > sLast.Length + 2 && CurrentLineText._IsWhiteSpaceOrNotPrintable())  //2 个 空格位置
                            {

                                IsLockPaint = true;

                                Font oldFont = this.SelectionFont;

                                SelectionStart = GetFirstCharIndexOfCurrentLine();
                                SelectionFont = new Font(oldFont, FontStyle.Bold);

                                SelectedText = sLast._TryStrAndOne() + " ";
                                SelectionFont = new Font(oldFont, FontStyle.Regular);
                                e.Handled = true;
                                IsLockPaint = false;

                            }
                            else   //----------------------------------------------附近没有序号标记,什么与不做
                            {

                            }
                        }
                    }   
                }
                else if (e.KeyCode == Keys.OemPeriod) //任何国家/地区键盘上的 OEM 句点键(Windows 2000 或更高版本)。
                {
                     
                    /*
                    //截取当行前面的所有空格和数字,包括 '.' , 遇到任何其它字符停止。

                    int nLinePos = m_rtbEx._GetCurrentCursorCoordinate().First;


                    StringList_ ls = new StringList_();

                    for(int i = nLinePos - 1; i > nLinePos - 50 && i >= 0; --i) //取50行前面的字符
                    {
                        string sTemp =  m_rtbEx.Lines[i]._Intercept_Head_number_RadixPoint_Space();

                        if(i == nLinePos - 1)  //当前行的文本行开头不是数字或者空格则退出
                        {
                            if (sTemp == "")
                                return;
                        } 
                        else
                        { 
                            if(sTemp.Length > 0)
                                ls.Add(sTemp);
                        }

                    }


                    if(ls.Count > 0)
                    {
                        string sLast = ls[0]._Try_NumberAddOne(1);
                        ls.InserFront(sLast);                    

                        m_HintForm.SetStringList(ls);
                        m_HintForm.ShownNearInTextCursor(m_rtbEx);     
                    }

                    */
                    
                }
                else if(e.KeyCode == Keys.ProcessKey)   //中文句号 “。”
                {
                    
                }
                else if(e.KeyCode  == Keys.F)
                {
                    if(e.Control)
                    {
                        ShowFindReplaceForm(false);
                        //System.Media.SystemSounds.Beep.Play();
                        //System.Media.SystemSounds.Asterisk.Play();
                        //System.Media.SystemSounds.Exclamation.Play();
                        //System.Media.SystemSounds.Hand.Play();
                        //System.Media.SystemSounds.Question.Play();

                        e.Handled |= true;
                    }
                }
                else if(e.KeyCode == Keys.R)
                {
                    if (e.Control)
                    {
                        ShowFindReplaceForm(true);
                        //System.Media.SystemSounds.Beep.Play();
                        //System.Media.SystemSounds.Asterisk.Play();
                        //System.Media.SystemSounds.Exclamation.Play();
                        //System.Media.SystemSounds.Hand.Play();
                        //System.Media.SystemSounds.Question.Play();
                        e.Handled |= true;
                    }
                }
                else
                {
                    
                  
                }


            }
            else if (SyntaxAnalysisType == LSyntaxAnalysisType.saCSharp)
            {

            }

            m_KeyeventStack.Add(e); //保存这一次按键信息
           
        }

代码着色

/*****************************************************************************

创建时间       :2022年08月08日

文件名         :Syntax_.cs

功能           :语法分析
  
作者           :李锋

微信号         :lifengwx2005

Email          :ruizhilf@139.com
  
联系电话       :1382877886(移动),18924615309(电信)

----------------------最后一次修改时间:2022年08月08日
 
*******************************************************************************/


using DocumentFormat.OpenXml.Drawing;
using System;
using System.Drawing;

namespace lf
{
 

	public enum SyntaxLanguage_
    {
		/// <summary>
		/// 服务器端最好的编程语言
		/// </summary>
		Java,
		/// <summary>
		/// /最通用的编程语言,迄今为止,最值得信任的编程语言
		/// </summary>
		C,
		/// <summary>
		/// AI(人工智能)、机器学习方向最佳的编程语言
		/// </summary>
		Python,
		/// <summary>
		/// 客户端最常用的脚本语言
		/// </summary>
		JavaScript,
		/// <summary>
		/// 微软最强有力的面向对象编程语言
		/// </summary>
		CSharp,
		/// <summary>
		/// IOS 端最高效的编程语言
		/// </summary>
		Swift,
		/// <summary>
		/// Golang),可扩展的编程语言,谷歌出品
		/// </summary>
		GO,
		/// <summary>
		/// 世界上最好的编程语言,不,最好用的 Web 编程语言
		/// </summary>
		PHP,
		/// <summary>
		/// 数据科学方面最可靠的编程语言
		/// </summary>
		Ruby, 
	}

 
    /// <summary>
    /// 
    /// </summary>
    public enum SyntaxType_
    {
		文本,	 
		运算符号,
		关键字,
        变量,
		局部变量,
		全局变量,	
		函数,
        类成员函数,
        宏,
		静态成员函数,
		静态字段, 
		基础类,
		枚举,
		注释,
		括号,
		模板数据,
		字符串值,
		指针,
		未定义,
		不存在,
	}







    public struct TypeColor_
	{
		public SyntaxType_ Type;
		public Color ForeColor;

		public TypeColor_(SyntaxType_ st, Color cColor) 
        {
			Type = st;
			ForeColor = cColor;
		}
	}

	public struct KeywordColor_
	{
		public int Pos;	
		public int Length;
		public Color ForeColor;
		public Boolean IsBold;

		public KeywordColor_(int nPos, int nLength,Color cColor, Boolean bBold = false)
		{			 
			Pos = nPos;
			Length = nLength;
			ForeColor = cColor;
			IsBold = bBold;
		}
    }

    /// <summary>
    /// 
    /// </summary>
    /// 创建时间: 2022-09-02      最后一次修改时间:2022-09-02
    public struct SyntaxWord_
    {
		public int Pos;       //在文中的位置
		public string Text;    //词,可能是类,变量,自定义类型,涵数
	}


	public class Syntax_
	{
		/// <summary>
		/// Java关键字
		/// abstract 表明类或者成员方法具有抽象属性 
		/// assert 断言,用来进行程序调试
		/// boolean 基本数据类型之一,声明布尔类型的关键字 
		/// break 提前跳出一个块
		/// byte 基本数据类型之一,字节类型 
		/// case 用在switch语句之中,表示其中的一个分支 
		/// catch 用在异常处理中,用来捕捉异常
		/// char 基本数据类型之一,字符类型
		/// class 声明一个类
		/// const 保留关键字,没有具体含义 
		/// continue 回到一个块的开始处 
		/// default 默认,例如,用在switch语句中,表明一个默认的分支。Java8 中也作用于声明接口函数的默认实现 
		/// do 用在do-while循环结构中
		/// double 基本数据类型之一,双精度浮点数类型 
		/// else 用在条件语句中,表明当条件不成立时的分支
		/// enum 枚举
		/// extends 表明一个类型是另一个类型的子类型。对于类,可以是另一个类或者抽象类;对于接口,可以是另一个接口
		/// final 用来说明最终属性,表明一个类不能派生出子类,或者成员方法不能被覆盖,或者成员域的值不能被改变,用来定义常量 
		/// finally 用于处理异常情况,用来声明一个基本肯定会被执行到的语句块
		/// float 基本数据类型之一,单精度浮点数类型 
		/// for 一种循环结构的引导词 
		/// goto 保留关键字,没有具体含义 
		/// if 条件语句的引导词
		/// implements 表明一个类实现了给定的接口
		/// import 表明要访问指定的类或包
		/// instanceof 用来测试一个对象是否是指定类型的实例对象
		/// int 基本数据类型之一,整数类型
		/// interface 接口
		/// long 基本数据类型之一,长整数类型
		/// native 用来声明一个方法是由与计算机相关的语言(如C/C++/FORTRAN语言)实现的
		/// new 用来创建新实例对象
		/// package 包
		/// private 一种访问控制方式:私用模式
		/// protected 一种访问控制方式:保护模式
		/// public 一种访问控制方式:共用模式 
		/// return 从成员方法中返回数据
		/// short 基本数据类型之一, 短整数类型
		/// static 表明具有静态属性
		/// strictfp 用来声明FP_strict(单精度或双精度浮点数)表达式遵循IEEE 754算术规范
		/// super 表明当前对象的父类型的引用或者父类型的构造方法 
		/// switch 分支语句结构的引导词
		/// synchronized 表明一段代码需要同步执行
		/// this 指向当前实例对象的引用
		/// throw 抛出一个异常
		/// throws 声明在当前定义的成员方法中所有需要抛出的异常
		/// transient 声明不用序列化的成员域
		/// try 尝试一个可能抛出异常的程序块
		/// void 声明当前成员方法没有返回值
		/// volatile 表明两个或者多个变量必须同步地发生变化 
		/// while 用在循环结构中
		/// </summary>
		public static StringList_ Java_Keyword = new StringList_{"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", 
			"const","continue", "default", "do", "double", "else", "enum", "extends", "final", "finally",
			"float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface",
			"long", "native", "new", "package", "private", "protected", "public", "return", "strictfp",
			"short", "static", "super", "switch", "synchronized ", "this", "throw", "throws", "transient",
			"try", "void", "volatile", "while" ,"operator"};

        public static StringList_ Java_Basicclass = new StringList_ {"Integer", "Double", "Number", "MathCharacter", "BooleanString", "BufferString",
            "BuilderArrays", "Scanner", "Math","String","Arrays"};


		public static StringList_ C_Keyword = new StringList_ { "asm", "do", "if", "return", "typedef", "auto", "double", "inline", "short", "typeid", "bool",
			"dynamic", "cast", "int", "signed", "typename", "break", "else", "long", "sizeof", "union", "case", "enum",
			"mutable", "static", "unsigned", "catch", "explicit", "namespace", "static", "cast", "using", "char", "export",
			"new", "struct", "virtual", "class", "extern", "operator", "switch", "void", "const", "false", "private", "template", "volatile",
			"const", "cast", "float", "protected", "this", "wchar", "t", "continue", "for", "public", "throw", "while", "default", "friend",
			"register", "true", "delete", "goto", "reinterpret", "cast", "try" ,"#define","size_t"};



        public static StringList_ C_Basicclass = new StringList_ {"Math","String","istream", "cin" ,"cout", "ostream" };
		public static StringList_ C_Function = new StringList_ {"iscntrl","isalnum","isalpha","isascii","isblank","isdigit","isgraph","islower","sprint","ispunct",
			"isspace","isupper","isxdigit","toascii","tolower","toupper","printf","malloc","strlen","strcpy","strcmp"};

		//运算符
		//public static StringList_ C_OperationalCharacter = new StringList_ { "+", "-", "*", "/", "<<", ">>", "&", "|", "||", "&&","=",";","->",".","::"};


		//运算符与标点符号
        public const String C_OperationalCharacter =  "+-*/<>&|&;,.=!:";


        public static StringList_ C_TemplaeData;  //模板数据类型

		//自定义类
		public static StringList_ CustomClass;


		//括号  ()   <  >   []  { }
		public static StringList_ Brackets;






        private SyntaxLanguage_ m_SyntaxLanguage;
		private StringList_ m_FileNameList = new StringList_();
		private string m_Text;
		private DList_<TypeColor_> m_TypeList = new DList_<TypeColor_>();
		private Color m_BackColor;

		

		public Syntax_(string Text, SyntaxLanguage_ sl, Color backColor)
        {
            m_SyntaxLanguage = sl;
            m_FileNameList = new StringList_();
            m_Text = Text;
            m_BackColor = backColor;
 

			/*
			Color.FromArgb(255, 0, 0)   //红色
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 182, 193), "浅粉红"));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 192, 203), "粉红"));
            //dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 240, 245), "脸红的淡紫色"));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(0, 128, 0), "纯绿 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(0, 100, 0), "深绿色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(127, 255, 0), "查特酒绿"));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(124, 252, 0), "草坪绿 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(60, 179, 113), "春天的绿色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(46, 139, 87), "海洋绿 "));
            //dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 250, 240), "花的白色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 165, 0), "橙色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 140, 0), "深橙色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 69, 0), "橙红色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 218, 185), "桃色 "));        
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(0, 0, 255), "纯蓝 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(25, 25, 112), "午夜的蓝色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(0, 0, 139), "深蓝色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(0, 0, 128), "海军蓝 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(65, 105, 225), "皇军蓝 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(135, 206, 250), "淡蓝色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(135, 206, 235), "天蓝色 "));

            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(128, 0, 128), "紫色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(186, 85, 211), "适中的兰花紫 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(148, 0, 211), "深紫罗兰色 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(153, 50, 204), "深兰花紫 "));

            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 255, 0), "纯黄 "));
          
             
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 215, 0), "金 "));
            dReulst.Add(new Pair_<Color, string>(Color.FromArgb(255, 248, 220), "玉米色 "));
             */
			if(m_BackColor == Color.Black)  //黑色背景
            {
			 
			  
            }
			else
            {
				 

				m_TypeList.Add(new TypeColor_(SyntaxType_.基础类, Color.FromArgb(150, 69, 0))); //紫色
               

			 
			 
           

                m_TypeList.Add(new TypeColor_(SyntaxType_.关键字, Color.Blue));   //关键字  蓝芭

				m_TypeList.Add(new TypeColor_(SyntaxType_.注释, Color.FromArgb(0, 100, 0))); //注释  深绿色 

                m_TypeList.Add(new TypeColor_(SyntaxType_.函数, Color.FromArgb(150, 150, 0))); //函数 紫色
                m_TypeList.Add(new TypeColor_(SyntaxType_.运算符号, Color.FromArgb(255,0,0))); //运算符 红色


                m_TypeList.Add(new TypeColor_(SyntaxType_.模板数据, Color.FromArgb(60, 255, 113))); //运算符 嫩绿色

		 
                m_TypeList.Add(new TypeColor_(SyntaxType_.字符串值, Color.YellowGreen)); // 

			
            
            }
        }


        public Color  GetColor(SyntaxType_ st)
        {
			foreach(TypeColor_ sc in m_TypeList)
            {
				if (sc.Type == st)
					return sc.ForeColor;
            }

			return Color.Blue;
        }


		public static void refresh_Java_Basicclass()
        {
			Java_Basicclass = lg.GetJava_Basicclass();
			 
		}



		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// 创建时间: 2022-08-08      最后一次修改时间:2022-08-09
		public DList_<KeywordColor_> GetSyntaxColor()
        {
			DList_<KeywordColor_> kcList = new DList_<KeywordColor_>();
			int nPos = -1;

			
			if (m_SyntaxLanguage == SyntaxLanguage_.Java)//------------------------------------------------------------Java
			{
				
				//-----------------------------------------------------------------关键字
				foreach (string s in Java_Keyword)
                {				

					nPos = m_Text._IndexOfWord(s);
			 
					while(nPos != -1)
                    { 
						kcList.Add(new KeywordColor_(nPos,s.Length, GetColor(SyntaxType_.关键字)));

						nPos = m_Text._IndexOfWord(s,nPos + s.Length);
                    }              
                }

                //-----------------------------------------------------------------基础类

                foreach (string s in Java_Basicclass)
				{
					nPos = m_Text._IndexOfWord(s);

					while (nPos != -1)
					{
						kcList.Add(new KeywordColor_(nPos, s.Length, GetColor(SyntaxType_.基础类)));

						nPos = m_Text._IndexOfWord(s, nPos + s.Length);
					}
				}


                //------------------------------------------------------------------运算符

                foreach (char c in C_OperationalCharacter)
                {
                    nPos = m_Text.IndexOf(c);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, 1, GetColor(SyntaxType_.运算符号)));

                        nPos = m_Text.IndexOf(c, nPos + 1);
                    }
                }

                //-----------------------------------------------------------------注释 //

                DList_<Pair_<int, int>> dl = m_Text._Syntax_C_ExplanatoryNote_Pos();

                foreach (Pair_<int, int> p in dl)
                {
                    kcList.Add(new KeywordColor_(p.First, p.Second, GetColor(SyntaxType_.注释)));
                }


                //--------------------------------------------括号,方括号,上下标
                DList_<Pair_<int, int>> dBra = m_Text._Syntax_C_FindBrackets(dl);

                foreach (Pair_<int, int> p in dBra)
                {
                    Color c = lg.RandomColor();

                    kcList.Add(new KeywordColor_(p.First, 1, c));
                    kcList.Add(new KeywordColor_(p.Second, 1, c));
                }

                //-----------------------------------------------------------------字符串值 
                dl = m_Text._Syntax_C_StringValue_Pos();

                foreach (Pair_<int, int> p in dl)
                {
                    kcList.Add(new KeywordColor_(p.First, p.Second, GetColor(SyntaxType_.字符串值)));
                }


            }
            else if(m_SyntaxLanguage == SyntaxLanguage_.C)//------------------------------------------------------------C&C++ Begin
            {
				 
				
                //-----------------------------------------------------------------关键字
                foreach (string s in C_Keyword)
                {

                    nPos = m_Text._IndexOfWord(s);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, s.Length, GetColor(SyntaxType_.关键字)));

                        nPos = m_Text._IndexOfWord(s, nPos + s.Length);
                    }
                }




                //--------------------------------------------------------------------------------------------基础类

                foreach (string s in C_Basicclass)
                {
                    nPos = m_Text._IndexOfWord(s);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, s.Length, GetColor(SyntaxType_.基础类)));

                        nPos = m_Text._IndexOfWord(s, nPos + s.Length);
                    }
                }



				//--------------------------------------------------------------------------------------------自定义类

				CustomClass = m_Text._Syntax_C_FindCustomClass();

                foreach (string s in CustomClass)
                {
                    nPos = m_Text._IndexOfWord(s);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, s.Length, GetColor(SyntaxType_.基础类)));

                        nPos = m_Text._IndexOfWord(s, nPos + s.Length);
                    }
                }

                //-------------------------------------------------------------------------------------模板数据



                C_TemplaeData = m_Text._Syntax_TemplateData();

                foreach (string s in C_TemplaeData)
                {
                    nPos = m_Text._IndexOfWord(s);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, s.Length, GetColor(SyntaxType_.模板数据)));

                        nPos = m_Text._IndexOfWord(s, nPos + s.Length);
                    }
                }


                //-----------------------------------------------------------------函数

                foreach (string s in C_Function)
                {
                    nPos = m_Text._IndexOfWord(s);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, s.Length, GetColor(SyntaxType_.函数)));

                        nPos = m_Text._IndexOfWord(s, nPos + s.Length);
                    }
                }


                //------------------------------------------------------------------运算符

                foreach (char c in C_OperationalCharacter)
                {
                    nPos = m_Text.IndexOf(c);

                    while (nPos != -1)
                    {
                        kcList.Add(new KeywordColor_(nPos, 1, GetColor(SyntaxType_.运算符号)));

                        nPos = m_Text.IndexOf(c, nPos + 1);
                    }
                }



				//-----------------------------------------------------------------注释 //

				DList_<Pair_<int, int>> dl = m_Text._Syntax_C_ExplanatoryNote_Pos();

				foreach( Pair_<int,int> p in dl)
				{
                    kcList.Add(new KeywordColor_(p.First,p.Second, GetColor(SyntaxType_.注释)));
                }


                //--------------------------------------------括号,方括号,上下标
                DList_<Pair_<int, int>> dBra = m_Text._Syntax_C_FindBrackets(dl);

                foreach (Pair_<int, int> p in dBra)
                {
					Color c = lg.RandomColor();

                    kcList.Add(new KeywordColor_(p.First, 1, c));
                    kcList.Add(new KeywordColor_(p.Second, 1, c));
                }

                //-----------------------------------------------------------------字符串值 
                dl = m_Text._Syntax_C_StringValue_Pos();

                foreach (Pair_<int, int> p in dl)
                {
                    kcList.Add(new KeywordColor_(p.First, p.Second, GetColor(SyntaxType_.字符串值)));
                }

            }//-----------------------------------------------------------------------------------------------C&C++ End
            else if (m_SyntaxLanguage == SyntaxLanguage_.CSharp)//------------------------------------------------------------CSharp Begin
            {
				string s = "/**//*a*//*b*/";


				lg.ShowInfo(s._Intercept_list("/*", "*/",0, true).Count.ToString());

			}
            else
			{
				lg.ShowInfo("还未完成!");
			}



		 			
			return kcList;
        }

	}



}

自定义文件格式 

数据库:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值