wyd1520 寫的ASP高亮類

2021-03-31 08:56:58 字數 3500 閱讀 9080

[原創]我寫的asp高亮類 此類高亮根據editplus高亮來做的

class wyd_aspcodehighlight

private regex

public keyword,object***mand,strings,vbcode

public keywordcolor,object***mandcolor,stringscolor,***ment,codecolor

private sub class_initialize()

set regex = new regexp

regex.ignorecase = true   ' 設定是否區分字母的大小寫 true 不區分。

regex.global = true   ' 設定全程性質。

keywordcolor="#0000ff"

object***mandcolor="#ff0000"

stringscolor="#ff00ff"

***ment="#008000"

codecolor="#993300"

keyword="set|private|if|then|sub|end|function|for|next|do|while|wend|true|false|nothing|class" '關建字 請自己新增

object***mand="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,"$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  ' 設定模式。

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  ' 設定是否區分字母的大小寫。

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("&object***mand&")/b",object***mandcolor)

temp=string_replace(temp,"""(.*?)""","""(.*)(<.+?>)("&keyword&object***mand&")+(<.+?>)(.*)""",stringscolor,1)' 字串

temp=string_replace(temp,"(('|rem).*)","'(.*)(<.+?>)("&keyword&object***mand&")+(<.+?>)(.*)",***ment,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

例子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

%>

<%

end if

%>

當年偶寫的asp程

當年偶用vbscript寫的asp程式,好不容易從電腦上翻了出來,在ado.net大行其道的今天,偶確要研究一下先進的ado技術,真有點時空錯亂的感覺 dim conn dim connstr set conn server.createobject adodb.connection if err ...

asp寫的日誌處理方法

一 實現方法 乙個書寫日誌的函式,提供幾個引數,使用者程式呼叫這個函式就可以實現日誌的記錄。日誌記錄到xml檔案中,日誌檔案按日期生成,每天新建立乙個日誌檔案,檔名為 yyyy mm dd.xml,分別用了年月日。而檢視日誌也日常簡單,使用者想看哪天的日誌,只要直接呼叫該xml檔案即可。因為xml檔...

asp寫的日誌處理方法 XML

一 實現方法 乙個書寫日誌的函式,提供幾個引數,使用者程式呼叫這個函式就可以實現日誌的記錄。日誌記錄到xml檔案中,日誌檔案按日期生成,每天新建立乙個日誌檔案,檔名為 yyyy mm dd.xml,分別用了年月日。而檢視日誌也日常簡單,使用者想看哪天的日誌,只要直接呼叫該xml檔案即可。因為xml檔...