ASP高亮類
代碼如下:
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 '' 設(shè)置是否區(qū)分字母的大小寫 true 不區(qū)分。
regex.global = true '' 設(shè)置全程性質(zhì)。
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" ''關(guān)建字 請自己添加
objectcommand="left|mid|right|int|cint|clng|string|join|array" ''函數(shù) 請自己添加
vbcode=""
end sub
private sub class_terminate()
set regex = nothing
end sub
private function m_replace(str,pattern,color)
regex.pattern = pattern '' 設(shè)置模式。
m_replace=regex.replace(str,"$1")
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 '' 設(shè)置模式。
if isstring=1 then
string_replace=regex.replace(str,""$1"")
else
string_replace=regex.replace(str,"$1")
end if
end function
private function re(str)
dim tregex,temp
set tregex = new regexp
tregex.ignorecase = true '' 設(shè)置是否區(qū)分字母的大小寫。
tregex.global = true '' 設(shè)置全程性質(zhì)。
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=""&repvbcrlf(temp)&""
end function
public function repvbcrlf(fstring)
repvbcrlf = replace(fstring, chr(10), "
")
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), "")
''fstring = replace(fstring, chr(10), "
")
htmlencode = fstring
end function
end class
例子
<br /> </input type="submit" value="fff" />
star=timer()
set tt = new wyd_aspcodehighlight
if request("xx")<>"" then
tt.vbcode=request("xx")
response.write tt.makeli()
response.write "
"&formatnumber(timer()-star,2)*1000
else
%>
class lih <br /> private regex <br /> public keyword,objectcommand,strings,vbcode <br /> public keywordcolor,objectcommandcolor,stringscolor,comment <br /> private sub class_initialize() <br /> set regex = new regexp <br /> keywordcolor="#0000ff" <br /> objectcommandcolor="#ff0000" <br /> stringscolor="#ff00ff" <br /> comment="#008000" <br /> keyword="if|end|for|next|function|then|do|while|wend|class" <br /> vbcode="" <br /> end sub <br /> private sub class_terminate() <br /> set regex = nothing <br /> end sub <br /> private function m_replace(str,pattern,color) <br /> regex.ignorecase = false '' 設(shè)置是否區(qū)分字母的大小寫。 <br /> regex.global = true '' 設(shè)置全程性質(zhì)。 <br /> regex.pattern = pattern '' 設(shè)置模式。 <br /> <input type="submit" value="fff" /> <br /> <br /> <% <br /> end if <br /> %>
相關(guān)文章
- 檢測函數(shù) asp class
- 遭遇ASP類的事件設(shè)計
- ASP高亮類
- Object對象的一些的隱藏函數(shù)介紹
- 淺談ASP中的類
- 在VBScript中使用類
- ASP 類專題
- 代碼與頁面的分離
- ASP代碼的對象化
- 一個asp快速字符串連接類
- 一個簡單的asp數(shù)據(jù)庫操作類
- ASP類編寫詳細(xì)說明
- 實現(xiàn)支持邏輯搜索/單詞搜索/詞組搜索+支持OR/AND關(guān)鍵字的VBS CLASS!
- ASP類Class入門 推薦
- 創(chuàng)建一個ASP通用分頁類
- 如何編寫一個ASP類
- 一個ACCESS數(shù)據(jù)庫訪問的類第1/3頁
- 分頁類,異常類
- ASP 類 Class入門