#include "stdafx.h" #include "syntax.h" CString g_strInString; //定义一个字符串值除了包含字符数字、下划线_外,还包含什么字符常量, C++还会包含#, 如#include TCHAR *g_BeginCommentExStr[2];//当前语言的多行注释规则:引起多行注释的字符串 TCHAR *g_EndCommentExStr[2]; //当前语言的多行注释规则:结束多行注释的字符串 TCHAR *g_LineCommentStr[2]; //当前语言的单行注释规则, 以行末为中止 TCHAR *g_BeginStringStr[1]; //当前语言的字符规则, 引起字符串变量的字符串 TCHAR *g_EndStringStr[1]; //当前语言的字符规则, 结束字符串变量的字符串 TCHAR *g_BeginCharStr[1]; //当前语言的字符规则, 结束字符型常量的字符串 TCHAR *g_EndCharStr[1]; //当前语言的字符规则, 结束字符型常量的字符串 BOOL g_bControl; //控制字符,如C++中的\",因为控制字符\的存在其表示的是一个引号 BOOL g_bCase; //在进行关键字比较时是否区分大小写 int g_nstrInStringCount; int g_nBeginCommentExStrCount; int g_nEndCommentExStrCount; int g_nLineCommentStrCount; int g_nBeginStringStrCount; int g_nEndStringStrCount; int g_nBeginCharStrCount; int g_nEndCharStrCount; int g_nCurLanguage; void SetCurLanguage(int nLanguage) { g_nCurLanguage = nLanguage; } BOOL IsSynWord(CStringArray &m_strArrayKeyWords, CString &strReadyToTest) { int val; int low=0,hig=m_strArrayKeyWords.GetSize()-1; int mid=(low+hig)/2; while(low<=hig) { CString str = m_strArrayKeyWords[mid]; if(g_bCase) val=strReadyToTest.Compare(m_strArrayKeyWords[mid]); else val=strReadyToTest.CompareNoCase(m_strArrayKeyWords[mid]); if(val>0) low=mid+1; else if(val<0) hig=mid-1; else return TRUE; mid=(low+hig)/2; } return FALSE; } BOOL IsNumber(CString &strReadyToTest) { int nLength = strReadyToTest.GetLength(); //* switch (g_nCurLanguage) { case _BASIC: { if (nLength > 2 && strReadyToTest[0] == _T('&') && (strReadyToTest[1] == _T('O') || strReadyToTest[1] == _T('H'))) { for (int I = 2; I < nLength; I++) { if (_istdigit(strReadyToTest[I]) ||(strReadyToTest[I] >= _T('A') && strReadyToTest[I] <= _T('F')) ||(strReadyToTest[I] >= _T('a') && strReadyToTest[I] <= _T('f'))) continue; return FALSE; } return TRUE; } } break; default: break; } // switch if (!_istdigit(strReadyToTest[0])) return FALSE; for (int I = 1; I < nLength; I++) { if (!_istdigit(strReadyToTest[I]) && strReadyToTest[I] != _T('+') && strReadyToTest[I] != _T('-') && strReadyToTest[I] != _T('.') && strReadyToTest[I] != _T('e') && strReadyToTest[I] != _T('E')) return FALSE; } //*/ return TRUE; } //装入关键字列表及语法解析规则 void LoadSynWord(CStringArray &m_strArrayKeyWords, int nLanguage) { LoadParseRule(nLanguage); CString strAllSynWord; m_strArrayKeyWords.RemoveAll(); CWinApp *app = AfxGetApp(); switch ( nLanguage ) { case _BASIC: strAllSynWord = _T(" Alias,And,Any,As,Base,Boolean,Byref,Byte,Byval,Call,Case,Close,Compare,Const,Currency,Data,Date,Declare,Defbool,Defbyte,Defcur,Defdate,Defdbl,Defdec,Defint,Deflng,Defobj,Defsng,Defstr,Defvar,Dim,Do,Double,Each,Else,Elseif,End,Enum,Eqv,Erase,Error,Event,Exit,Explicit,False,For,Function,Get,Global,Gosub,Goto,If,IIf,Imp,Implements,In,Integer,Is,Let,Lib,Line,Lock,Long,Loop,Lset,New,Next,Not,Object,On,Open,Option,Optional,Or,Preserve,Print,Private,Property,Public,Put,Raiseevent,Redim,Resume,Return,Rset,Select,Set,Single,Static,Stop,String,Sub,Then,To,True,Type,Ubound,Unload,Unlock,Var,Variant,Wend,While,With,Write,Xor,#if,#End,#else,Abs,Array,Asc,Atn,CBool,CByte,CCur,CDate,CDbl,Chr,CInt,CLng,Cos,CreateObject,CSng,CStr,Date,DateAdd,DateDiff,DatePart,DateSerial,DateValue,Day,Exp,Filter,Fix,FormatCurrency,FormatDateTime,FormatNumber,FormatPercent,GetObject,Hex,Hour,InputBox,InStr,InStrRev,Int,IsArray,IsDate,IsEmpty,IsNull,IsNumeric,IsObject,Join,LBound,LCase,Left,Len,LoadPicture,Log,LTrim,Mid,Minute,Month,MonthName,MsgBox,Now,Oct,Replace,RGB,Right,Rnd,Round,RTrim,ScriptEngine,ScriptEngineBuildVersion,ScriptEngineMajorVersion,ScriptEngineMinorVersion,Second,Sgn,Sin,Space,Split,Sqr,StrComp,StrReverse,String,Tan,Time,TimeSerial,TimeValue,Trim,TypeName,UBound,UCase,VarType,Weekday,WeekdayName,Year,SelectYK,ExecuteYK,MannulSetYX,MannulSetYC,IsMainServer,SelectYT,ExecuteYT,CancelMansetYX,CancelMansetYC,Sleeps,"); strAllSynWord = app->GetProfileString(_T("Keywords"), _T("_BASIC"), strAllSynWord); break; default: //is NONE return; } if(!g_bCase) { strAllSynWord.MakeLower(); } CString strTemp; int nPosPrior = 0; int nPos; nPos = strAllSynWord.Find(_T(","), nPosPrior); while(nPos!=-1) { strTemp = strAllSynWord.Mid(nPosPrior+1 , nPos - nPosPrior - 1); m_strArrayKeyWords.Add(strTemp); nPosPrior = nPos; nPos = strAllSynWord.Find(_T(","), nPosPrior + 1); } SortSynWordArray(m_strArrayKeyWords); } void SortSynWordArray(CStringArray &m_strArrayKeyWords) { int i,j,x, count = m_strArrayKeyWords.GetSize(); CString strtmp; for(i=1;ix;j--) m_strArrayKeyWords.SetAt(j, m_strArrayKeyWords.GetAt(j-1)); m_strArrayKeyWords.SetAt(x, strtmp); } } /*/////////////////////////////////////////////////////////////////////////////////////////////// ParseLine(m_strArrayKeyWords, dwCookie, strLine, ColorInfo, nActualItems) ); 功能:根据所给定的语言解析一行字符串,返回用颜色指示的字符串块,以及解析后的当前行的解析结果, 指示解析后当前行处于什么状态,是处于字符串中、注释中、多行注释中还是正常状态。 入口参数: m_strArrayKeyWords: 关键字列表 dwCookie: 传入前一行的解析结果,如果前一行是多行注释的开始或者前一行是一软回车时有用 strLine: 被解析的一行字符串 ColorInfo: 解析后的颜色值,指定是关键字、字符串、注释还是正常的字符颜色 nActualItems strLine被解析后的块数 /////////////////////////////////////////////////////////////////////////////////////////////////*/ DWORD ParseLine(CStringArray &m_strArrayKeyWords, DWORD dwCookie, CString &strLine, COLORINFO *ColorInfo, int &nActualItems) { //* if(g_nCurLanguage ==_HTML || g_nCurLanguage ==_XML) { int dwCookieTmp = ParseLineForHtml(m_strArrayKeyWords, dwCookie, strLine, ColorInfo, nActualItems); return dwCookieTmp; } //*/ int nLength = strLine.GetLength(); int nIdentBegin = -1; int i; BOOL bMatch; BOOL bInString; //定义一个字符串的界限 BOOL bRedefineBlock = TRUE; BOOL bDecIndex = FALSE; BOOL bIsInTheControlChar = FALSE; //指示是否在\的控制中, strControl为空时无效, 初始化时必须为FALSE, 原因见结束定义字符串的处理代码 if(nLength == 0) return dwCookie; int I = 0; for ( I = 0; ; I++) { if (bRedefineBlock) //如果开始定义颜色块向下做 { int nPos = I; if (bDecIndex) nPos--; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK(nPos, COLORINDEX_COMMENT); } else { if (dwCookie & COOKIE_STRING) { DEFINE_BLOCK(nPos, COLORINDEX_STRING); } else { DEFINE_BLOCK(nPos, COLORINDEX_NORMAL); } } bRedefineBlock = FALSE; bDecIndex = FALSE; } if (I >= nLength) goto Out; //遇到双字节字体如中文直接跳过 if(IsDBCSLeadByte(strLine[I])) //检查是不是中文字符 { I += 2; if (I >= nLength) goto Out; else goto cmpnextchar; //继续处理strLine的下一个字符 } ////////////////////////////// if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK(I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; goto Out; } //如果当前正处于字符串变量中,则应检查是否有结束字符串变量的字符串 if (dwCookie & COOKIE_STRING) { if(g_bControl) { //处理控制字符,至少C++会用到(例\"表示引号而不是两个字符) if(I > 0) { if(strLine[I-1] != '\\') { if(strLine[I] != '\\') bIsInTheControlChar = FALSE; else bIsInTheControlChar = TRUE; } else { if(strLine[I] == '\\') { if(!bIsInTheControlChar) bIsInTheControlChar = TRUE; else bIsInTheControlChar = FALSE; } } } } int nlen; for (int i = 0; i < g_nEndStringStrCount; i++ ) { if(g_EndStringStr[i]==NULL) continue; nlen = strlen(g_EndStringStr[i]); bMatch = TRUE; //如果strLine的当前字符串值与结束定义字符规则中的一项相同则中止定义字符串 if (I >= nlen - 1) { for(int k=0; k 0) { if(strLine[I-1] != '\\') { if(strLine[I] != '\\') bIsInTheControlChar = FALSE; else bIsInTheControlChar = TRUE; } else { if(strLine[I] == '\\') { if(!bIsInTheControlChar) bIsInTheControlChar = TRUE; else bIsInTheControlChar = FALSE; } } } } int nlen; for (int i = 0; i < g_nEndCharStrCount; i++ ) { if(g_EndCharStr[i]==NULL) continue; nlen = strlen(g_EndCharStr[i]); bMatch = TRUE; //如果strLine的当前字符值与结束定义字符规则中的一项相同则中止定义字符串 if (I >= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k1) { if ( ++I>= nLength) // 考虑"/*/"的情况 goto Out; } goto cmpnextchar; } } } bInString = FALSE; for ( i = 0; i < g_nstrInStringCount; i++ ) { BOOL b = ( strLine[I] == g_strInString.GetAt(i) ) ; bInString |= b; if(bInString) break; } if (isalnum(strLine[I]) || strLine[I] == '_' || bInString) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { CString strtmp= strLine.Mid(nIdentBegin, I - nIdentBegin); if (IsSynWord(m_strArrayKeyWords, strtmp)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX); } else if (IsNumber(strtmp)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER); } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } } cmpnextchar: i=0; //没有意义,为编译通过而准备 } Out: //当遇到单行注释时会直接跳到这儿 if (nIdentBegin >= 0) { CString strtmp = strLine.Mid(nIdentBegin, I - nIdentBegin); if (IsSynWord(m_strArrayKeyWords, strtmp)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX); } else if (IsNumber(strtmp)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER); } } return dwCookie; } DWORD ParseLineForHtml(CStringArray &m_strArrayKeyWords, DWORD dwCookie, CString &strLine, COLORINFO *ColorInfo, int &nActualItems) { //对于无多行注释的语法在只取当前行的解析结果时可直接返回 if(g_nBeginCommentExStrCount==0 && ColorInfo==NULL) return dwCookie; int nLength = strLine.GetLength(); int nIdentBegin = -1; int i; BOOL bMatch; BOOL bInString; //定义一个字符串的界限 BOOL bRedefineBlock = TRUE; BOOL bDecIndex = FALSE; if(nLength == 0) return dwCookie; int I = 0; for ( I = 0; ; I++) { if (bRedefineBlock) //如果开始定义颜色块向下做 { int nPos = I; if (bDecIndex) nPos--; if (dwCookie & COOKIE_EXT_COMMENT) { DEFINE_BLOCK(nPos, COLORINDEX_COMMENT); } else if (dwCookie & COOKIE_STRING) { DEFINE_BLOCK(nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_SCRIPT) { DEFINE_BLOCK(nPos, COLORINDEX_STRING); } else { DEFINE_BLOCK(nPos, COLORINDEX_NORMAL); } bRedefineBlock = FALSE; bDecIndex = FALSE; } if (I >= nLength) goto Out; //遇到双字节字体如中文直接跳过 if(IsDBCSLeadByte(strLine[I])) //检查是不是中文字符 { I += 2; if (I >= nLength) goto Out; else goto cmpnextchar; //继续处理strLine的下一个字符 } ////////////////////////////// if ( !(dwCookie & COOKIE_TAG) ) { if (dwCookie & COOKIE_SCRIPT) { if ( I + 7 < nLength) {// the string "= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= nlen - 1) { for(int k=0; k= 0) { CString strtmp= strLine.Mid(nIdentBegin, I - nIdentBegin); if (IsNumber(strtmp)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER); }//* else { if(strtmp.CompareNoCase(_T("script"))==0) { if( nIdentBegin > 0 && strLine[nIdentBegin-1] == '<') { dwCookie |= COOKIE_SCRIPT; } else if( nIdentBegin > 1 && strLine[nIdentBegin-1] == '/' && strLine[nIdentBegin-2] == '<') { dwCookie &= ~COOKIE_SCRIPT; DEFINE_BLOCK(nIdentBegin-2, COLORINDEX_SYNTAX); } } if( (nIdentBegin > 0) && (strLine[nIdentBegin-1] == '=') ) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NORMAL); } else { DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX); } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } } } if (strLine[I] == '>') { bRedefineBlock = FALSE; dwCookie &= ~COOKIE_TAG; DEFINE_BLOCK(I, COLORINDEX_SYNTAX); if(dwCookie & COOKIE_SCRIPT) { DEFINE_BLOCK(I+1, COLORINDEX_STRING); } else if( (I > 1) && (strLine[I-1]=='-') && (strLine[I-2]=='-') ) { DEFINE_BLOCK(I, COLORINDEX_COMMENT); } else { DEFINE_BLOCK(I+1, COLORINDEX_NORMAL); } } cmpnextchar: i = 0; } Out: //当遇到单行注释时会直接跳到这儿 if (dwCookie & COOKIE_TAG) { if (nIdentBegin >= 0) { CString strtmp = strLine.Mid(nIdentBegin, I - nIdentBegin); if (IsSynWord(m_strArrayKeyWords, strtmp)) { if( (nIdentBegin > 0) && (strLine[nIdentBegin-1]=='/') ) { DEFINE_BLOCK(nIdentBegin-1, COLORINDEX_SYNTAX); } else { DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX); } if(strtmp.CompareNoCase(_T("script"))==0) { if( nIdentBegin > 0 && strLine[nIdentBegin-1] == '<') { dwCookie |= COOKIE_SCRIPT; } else if( nIdentBegin > 1 && strLine[nIdentBegin-1] == '/' && strLine[nIdentBegin-12] == '<') { dwCookie &= ~COOKIE_SCRIPT; DEFINE_BLOCK(nIdentBegin-2, COLORINDEX_NORMAL); } } } else if (IsNumber(strtmp)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER); } } } return dwCookie; } void LoadParseRule(int nlanguage) { g_strInString = _T(""); g_nstrInStringCount = 0; g_nBeginCommentExStrCount = 0; g_nEndCommentExStrCount = 0; g_nLineCommentStrCount = 0; g_nBeginStringStrCount = 0; g_nEndStringStrCount = 0; g_nBeginCharStrCount = 0; g_nEndCharStrCount = 0; g_bControl = FALSE; g_bCase = FALSE; ///////////////////////////////////////////////////////////////////////////// if(g_BeginCommentExStr[0]!= NULL) {delete g_BeginCommentExStr[0]; g_BeginCommentExStr[0] = NULL;} if(g_BeginCommentExStr[1]!= NULL) {delete g_BeginCommentExStr[1]; g_BeginCommentExStr[1] = NULL;} ///////////////////////////////////////////////////////////////////////////// if(g_EndCommentExStr[0]!= NULL) {delete g_EndCommentExStr[0]; g_EndCommentExStr[0] = NULL;} if(g_EndCommentExStr[1]!= NULL) {delete g_EndCommentExStr[1]; g_EndCommentExStr[1] = NULL;} ///////////////////////////////////////////////////////////////////////////// if(g_LineCommentStr[0]!= NULL) {delete g_LineCommentStr[0]; g_LineCommentStr[0] = NULL;} if(g_LineCommentStr[1]!= NULL) {delete g_LineCommentStr[1]; g_LineCommentStr[1] = NULL;} ///////////////////////////////////////////////////////////////////////////// if(g_BeginStringStr[0]!= NULL) {delete g_BeginStringStr[0]; g_BeginStringStr[0] = NULL;} ///////////////////////////////////////////////////////////////////////////// if(g_EndStringStr[0]!= NULL) {delete g_EndStringStr[0]; g_EndStringStr[0] = NULL;} ///////////////////////////////////////////////////////////////////////////// if(g_BeginCharStr[0]!= NULL) {delete g_BeginCharStr[0]; g_BeginCharStr[0] = NULL;} ///////////////////////////////////////////////////////////////////////////// if(g_EndCharStr[0]!= NULL) {delete g_EndCharStr[0]; g_EndCharStr[0] = NULL;} CString strInString = _T(""); CString BeginCommentExStr0 = _T(""); CString EndCommentExStr0 = _T(""); CString BeginCommentExStr1 = _T(""); CString EndCommentExStr1 = _T(""); CString LineCommentStr0 = _T(""); CString LineCommentStr1 = _T(""); CString BeginStringStr0 = _T(""); CString EndStringStr0 = _T(""); CString BeginCharStr0 = _T(""); CString EndCharStr0 = _T(""); switch ( nlanguage ) { case _BASIC: strInString = _T("&#"); LineCommentStr0=_T("\'"); LineCommentStr1=_T("rem"); BeginStringStr0=_T("\""); EndStringStr0=_T("\""); break; default: //is NONE return; } CString strLanguagePos = _T("icrEdit__ParseRule"); strLanguagePos += GetLanguageString(nlanguage); CString strtmp; CWinApp *app = AfxGetApp(); g_bCase = app->GetProfileInt( strLanguagePos, _T("g_bCase"), g_bCase); //一个单词包含的字符常量 strtmp = app->GetProfileString( strLanguagePos, _T("strInString"), strInString); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_strInString = strtmp; g_nstrInStringCount = g_strInString.GetLength(); } //一个单词包含的字符常量 //开始多行注释的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("BeginCommentExStr0"), BeginCommentExStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_BeginCommentExStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_BeginCommentExStr[0], strtmp); g_nBeginCommentExStrCount = 1; } strtmp = app->GetProfileString( strLanguagePos, _T("BeginCommentExStr1"), BeginCommentExStr1); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_BeginCommentExStr[1] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_BeginCommentExStr[1], strtmp); g_nBeginCommentExStrCount = 2; } //开始多行注释的字符串 //结束多行注释的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("EndCommentExStr0"), EndCommentExStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_EndCommentExStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_EndCommentExStr[0], strtmp); g_nEndCommentExStrCount = 1; } strtmp = app->GetProfileString( strLanguagePos, _T("EndCommentExStr1"), EndCommentExStr1); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_EndCommentExStr[1] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_EndCommentExStr[1], strtmp); g_nEndCommentExStrCount = 2; } //结束多行注释的字符串 //开始单行注释的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("LineCommentStr0"), LineCommentStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_LineCommentStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_LineCommentStr[0], strtmp); g_nLineCommentStrCount = 1; } strtmp = app->GetProfileString( strLanguagePos, _T("LineCommentStr1"), LineCommentStr1); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_LineCommentStr[1] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_LineCommentStr[1], strtmp); g_nLineCommentStrCount = 2; } //开始单行注释的字符串 //开始字符串变量的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("BeginStringStr0"), BeginStringStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_BeginStringStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_BeginStringStr[0], strtmp); g_nBeginStringStrCount = 1; } //开始字符串变量的字符串 //结束字符串变量的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("EndStringStr0"), EndStringStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_EndStringStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_EndStringStr[0], strtmp); g_nEndStringStrCount = 1; } //结束字符串变量的字符串 //开始字符型常量的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("BeginCharStr0"), BeginCharStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_BeginCharStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_BeginCharStr[0], strtmp); g_nBeginCharStrCount = 1; } //开始字符型常量的字符串 //结束字符型常量的字符串 strtmp = app->GetProfileString( strLanguagePos, _T("EndCharStr0"), EndCharStr0); strtmp.TrimLeft();strtmp.TrimRight();strtmp.TrimLeft(0x9);strtmp.TrimRight(0x9); if(!strtmp.IsEmpty()) { g_EndCharStr[0] = new TCHAR[strtmp.GetLength()+1]; strcpy(g_EndCharStr[0], strtmp); g_nEndCharStrCount = 1; } //结束字符型常量的字符串 } CString GetLanguageString(int nlanguage) { switch ( nlanguage ) { case _BASIC: return _T("_BASIC"); default: //is NONE return _T("Plain text"); } } void DeleteAllocString() { //删除分配的语法解析规则字符串指针以防止内存泄漏 if(g_BeginCommentExStr[0]!= NULL) {delete g_BeginCommentExStr[0]; g_BeginCommentExStr[0] = NULL;} if(g_BeginCommentExStr[1]!= NULL) {delete g_BeginCommentExStr[1]; g_BeginCommentExStr[1] = NULL;} if(g_EndCommentExStr[0]!= NULL) {delete g_EndCommentExStr[0]; g_EndCommentExStr[0] = NULL;} if(g_EndCommentExStr[1]!= NULL) {delete g_EndCommentExStr[1]; g_EndCommentExStr[1] = NULL;} if(g_LineCommentStr[0]!= NULL) {delete g_LineCommentStr[0]; g_LineCommentStr[0] = NULL;} if(g_LineCommentStr[1]!= NULL) {delete g_LineCommentStr[1]; g_LineCommentStr[1] = NULL;} if(g_BeginStringStr[0]!= NULL) {delete g_BeginStringStr[0]; g_BeginStringStr[0] = NULL;} if(g_EndStringStr[0]!= NULL) {delete g_EndStringStr[0]; g_EndStringStr[0] = NULL;} if(g_BeginCharStr[0]!= NULL) {delete g_BeginCharStr[0]; g_BeginCharStr[0] = NULL;} if(g_EndCharStr[0]!= NULL) {delete g_EndCharStr[0]; g_EndCharStr[0] = NULL;} } CString GetLineCommentString(int nlanguage) { CString LineCommentStr0 = _T(""); switch ( nlanguage ) { case _BASIC: LineCommentStr0=_T("\'"); break; default: //is NONE return LineCommentStr0; } CString strLanguagePos = _T("icrEdit__ParseRule"); strLanguagePos += GetLanguageString(nlanguage); CWinApp *app = AfxGetApp(); LineCommentStr0 = app->GetProfileString( strLanguagePos, _T("LineCommentStr0"), LineCommentStr0); LineCommentStr0.TrimLeft(); LineCommentStr0.TrimRight(); LineCommentStr0.TrimLeft(0x9); LineCommentStr0.TrimRight(0x9); if(!LineCommentStr0.IsEmpty()) return LineCommentStr0; LineCommentStr0 = app->GetProfileString( strLanguagePos, _T("LineCommentStr1"), LineCommentStr0); LineCommentStr0.TrimLeft(); LineCommentStr0.TrimRight(); LineCommentStr0.TrimLeft(0x9); LineCommentStr0.TrimRight(0x9); return LineCommentStr0; } //根据显示给用户看的字符串取出语言 int GetLanguageByStringShow(CString strlanguage) { if(strlanguage==_T("Basic")) return _BASIC; return 0; } //根据语言返回给用户看的字符串 CString GetStringShowByLanguage(int nlanguage) { switch(nlanguage) { case _BASIC: return _T("Basic"); default: return _T("Plain text"); } }