ASP高亮類

來源:互聯網
上載者:User

Class Wyd_AspCodeHighLight
Private RegEx
Public Keyword,ObjectCommand,Strings,VBCode
Public KeyWordColor,ObjectCommandColor,StringsColor,Comment,CodeColor
 Private Sub Class_Initialize()
   Set RegEx = New RegExp
RegEx.IgnoreCase = True   '' 設定是否區分字母的大小寫 True 不區分。
   RegEx.Global = True   '' 設定全程性質。
   KeyWordColor="#0000FF"
   ObjectCommandColor="#FF0000"
   StringsColor="#FF00FF"
Comment="#008000"
CodeColor="#993300"
Keyword="Set|Private|If|Then|Sub|End|Function|For|Next|Do|While|Wend|True|False|Nothing|Class" ''關建字 請自己添加
ObjectCommand="Left|Mid|Right|Int|Cint|Clng|String|Join|Array" ''函數 請自己添加
VBCode=""
 End Sub
 Private Sub Class_Terminate()
   Set RegEx = Nothing
 End Sub
 Private Function M_Replace(Str,Pattern,Color)
   RegEx.Pattern = Pattern  '' 設定模式。
   M_Replace=RegEx.Replace(Str,"<font color="&Color&">$1</font>")
 End Function

 Private Function String_Replace(Str,Pattern,Pattern1,Color,IsString)
 Dim Temp,RetStr
RegEx.Pattern =Pattern1
   Set Matches = RegEx.Execute(Str)
   For Each Match In Matches   '' 遍曆 Matches 集合
      Temp=Re(Match.value)
      Str = Replace(Str,Match.value,Temp)
   Next
RegEx.Pattern = Pattern  '' 設定模式。
If IsString=1 Then
      String_Replace=RegEx.Replace(Str,"<font color="&Color&">"$1"</font>")
Else
   String_Replace=RegEx.Replace(Str,"<font color="&Color&">$1</font>")
End If
 End Function

 Private Function Re(Str)
  Dim TRegEx,Temp
  Set TRegEx = New RegExp
  TRegEx.IgnoreCase = True  '' 設定是否區分字母的大小寫。
  TRegEx.Global = True   '' 設定全程性質。
  TRegEx.Pattern="<.*?>"
  Temp=TRegEx.Replace(Str,"")
  Temp=Replace(Temp,"<","")
  Temp=Replace(Temp,">","")
  Re=Temp
  Set TRegEx=Nothing
 End Function

 Public Function MakeLi()
   Dim Temp
If VBCode="" Then
   MakeLi=""
   Exit Function
End If
   VBCode=HTMLEncode(VBCode)
   Temp=M_Replace(VBCode,"\b("&Keyword&")\b",KeyWordColor)
   Temp=M_Replace(Temp,"\b("&ObjEctCommand&")\b",ObjectCommandColor)
   Temp=String_Replace(Temp,"""(.*?)""","""(.*)(<.+?>)("&KeyWord&ObjectCommand&")+(<.+?>)(.*)""",StringsColor,1)'' 字串
   Temp=String_Replace(Temp,"((''|rem).*)","''(.*)(<.+?>)("&KeyWord&ObjectCommand&")+(<.+?>)(.*)",Comment,0) ''注釋
   MakeLi="<FONT  COLOR="&CodeColor&">"&RepVbCrlf(Temp)&"</FONT>"
 End Function
 Public Function RepVbCrlf(fString)
    RepVbCrlf = Replace(fString, CHR(10), "<BR> ")
 End Function
 Public Function HTMLEncode(fString)
    If IsNull(fString) Or fString="" Then
    HTMLEncode=""
 Exit Function
    End If
    fString = replace(fString, ">", ">")
    fString = replace(fString, "<", "<")
    ''fString = Replace(fString, CHR(32), " ")
    ''fString = Replace(fString, CHR(9), " ")
    ''fString = Replace(fString, CHR(34), """)
    ''fString = Replace(fString, CHR(39), "''")
    ''fString = Replace(fString, CHR(13), "")
    ''fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
    ''fString = Replace(fString, CHR(10), "<BR> ")
    HTMLEncode = fString
  End Function
End Class

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.