Javascript N层对称标记算法的实现 By shawl.qiu
说明:
本算法是鄙人在弄一个叫 Styler 的类时弄的, 不过后来发现, 可以使用在许多地方...
主要就是以特定规律标记各层的成对出现.
比如 {{}}
可以标记为 brace1begin brace2begin brace2end brace1end
现在主要是使用在鄙人的 Styler(v.1.3尚未发布) 类 和 Highlights类(尚未发布)
shawl.qiu
2007-08-22
http://blog.csdn.net/btbtd
内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
<style type="text/css">
/* <![CDATA[ */
/* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if ( navigator. appName == "Microsoft Internet Explorer" )
{
//最大化窗口
self. moveTo ( - 5, - 5 )
self. resizeTo ( screen. availWidth + 8, screen. availHeight + 8 )
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Nodes =
[
, "SQSTRUCTURE0/n"
, "<html>/n"
, "SQCONTENT0/n"
, "<head><div><div><div></div></div></div>/n"
, "SQCONTENT1/n"
, "<title>/n"
, "SQCONTENT2/n"
, "<//title><a><a></a></a>/n"
, "SQCONTENT3/n"
, "<//head>/n"
, "SQCONTENT4/n"
, "<body>/n"
, "SQCONTENT5/n"
, "<table>/n"
, "SQCONTENT6/n"
, "<tr>/n"
, "SQCONTENT7/n"
, "<td>/n"
, "SQCONTENT8/n"
, "<a>/n"
, "SQCONTENT9/n"
, "<//a>/n"
, "SQCONTENT10/n"
, "<a>/n"
, "SQCONTENT11/n"
, "<//a>/n"
, "SQCONTENT12/n"
, "<a>/n"
, "SQCONTENT13/n"
, "<//a>/n"
, "SQCONTENT14/n"
, "<a>/n"
, "SQCONTENT15/n"
, "<//a>/n"
, "SQCONTENT16/n"
, "<//td>/n"
, "SQCONTENT17/n"
, "<td>/n"
, "SQCONTENT18/n"
, "<a>/n"
, "SQCONTENT19/n"
, "<//a>/n"
, "SQCONTENT20/n"
, "<//td>/n"
, "SQCONTENT21/n"
, "<//tr>/n"
, "SQCONTENT22/n"
, "<tr>/n"
, "SQCONTENT23/n"
, "<td>/n"
, "SQCONTENT24/n"
, "<div>/n"
, "SQCONTENT25/n"
, "<A>/n"
, "SQCONTENT26/n"
, "<//A>/n"
, "SQCONTENT27/n"
, "<//div>/n"
, "SQCONTENT28/n"
, "<//td>/n"
, "SQCONTENT29/n"
, "<//tr>/n"
, "SQCONTENT30/n"
, "<tr>/n"
, "SQCONTENT31/n"
, "<td>/n"
, "SQCONTENT32/n"
, "<div>/n"
, "SQCONTENT33/n"
, "<form>/n"
, "SQCONTENT34/n"
, "<//form>/n"
, "SQCONTENT35/n"
, "<form>/n"
, "SQCONTENT36/n"
, "<//form>/n"
, "SQCONTENT37/n"
, "<//div>/n"
, "SQCONTENT38/n"
, "<//td>/n"
, "SQCONTENT39/n"
, "<//tr>/n"
, "SQCONTENT40/n"
, "<tr>/n"
, "SQCONTENT41/n"
, "<td>/n"
, "SQCONTENT42/n"
, "<div>/n"
, "SQCONTENT43/n"
, "<//div>/n"
, "SQCONTENT44/n"
, "<//td>/n"
, "SQCONTENT45/n"
, "<//tr>/n"
, "SQCONTENT46/n"
, "<//table>/n"
, "SQCONTENT47/n"
, "<table>/n"
, "SQCONTENT48/n"
, "<tr>/n"
, "SQCONTENT49/n"
, "<td>/n"
, "SQCONTENT50/n"
, "<div>/n"
, "SQCONTENT51/n"
, "<div>/n"
, "SQCONTENT52/n"
, "<label>/n"
, "SQCONTENT53/n"
, "<//label>/n"
, "SQCONTENT54/n"
, "<ul>/n"
, "SQCONTENT55/n"
, "<li>/n"
, "SQCONTENT56/n"
, "<//li>/n"
, "SQCONTENT57/n"
, "<li>/n"
, "SQCONTENT58/n"
, "<//li>/n"
, "SQCONTENT59/n"
, "<li>/n"
, "SQCONTENT60/n"
, "<//li>/n"
, "SQCONTENT61/n"
, "<li>/n"
, "SQCONTENT62/n"
, "<//li>/n"
, "SQCONTENT63/n"
, "<li>/n"
, "SQCONTENT64/n"
, "<//li>/n"
, "SQCONTENT65/n"
, "<li>/n"
, "SQCONTENT66/n"
, "<//li>/n"
, "SQCONTENT67/n"
, "<li>/n"
, "SQCONTENT68/n"
, "<//li>/n"
, "SQCONTENT69/n"
, "<li>/n"
, "SQCONTENT70/n"
, "<//li>/n"
, "SQCONTENT71/n"
, "<li>/n"
, "SQCONTENT72/n"
, "<//li>/n"
, "SQCONTENT73/n"
, "<//ul>/n"
, "SQCONTENT74/n"
, "<//div>/n"
, "SQCONTENT75/n"
, "<div>/n"
, "SQCONTENT76/n"
, "<a>/n"
, "SQCONTENT77/n"
, "<//a>/n"
, "SQCONTENT78/n"
, "<//div>/n"
, "SQCONTENT79/n"
, "<//div>/n"
, "SQCONTENT80/n"
, "<//td>/n"
, "SQCONTENT81/n"
, "<td>/n"
, "SQCONTENT82/n"
, "<form>/n"
, "SQCONTENT83/n"
, "<//form>/n"
, "SQCONTENT84/n"
, "<//td>/n"
, "SQCONTENT85/n"
, "<//tr>/n"
, "SQCONTENT86/n"
, "<tr>/n"
, "SQCONTENT87/n"
, "<td>/n"
, "SQCONTENT88/n"
, "<div>/n"
, "SQCONTENT89/n"
, "<div>/n"
, "SQCONTENT90/n"
, "<div>/n"
, "SQCONTENT91/n"
, "<span>/n"
, "SQCONTENT92/n"
, "<//span>/n"
, "SQCONTENT93/n"
, "<span>/n"
, "SQCONTENT94/n"
, "<//span>/n"
, "SQCONTENT95/n"
, "<span>/n"
, "SQCONTENT96/n"
, "<//span>/n"
, "SQCONTENT97/n"
, "<span>/n"
, "SQCONTENT98/n"
, "<//span>/n"
, "SQCONTENT99/n"
, "<a>/n"
, "SQCONTENT100/n"
, "<//a>/n"
, "SQCONTENT101/n"
, "<a>/n"
, "SQCONTENT102/n"
, "<//a>/n"
, "SQCONTENT103/n"
, "<a>/n"
, "SQCONTENT104/n"
, "<//a>/n"
, "SQCONTENT105/n"
, "<a>/n"
, "SQCONTENT106/n"
, "<//a>/n"
, "SQCONTENT107/n"
, "<a>/n"
, "SQCONTENT108/n"
, "<//a>/n"
, "SQCONTENT109/n"
, "<a>/n"
, "SQCONTENT110/n"
, "<//a>/n"
, "SQCONTENT111/n"
, "<a>/n"
, "SQCONTENT112/n"
, "<//a>/n"
, "SQCONTENT113/n"
, "<a>/n"
, "SQCONTENT114/n"
, "<//a>/n"
, "SQCONTENT115/n"
, "<a>/n"
, "SQCONTENT116/n"
, "<//a>/n"
, "SQCONTENT117/n"
, "<a>/n"
, "SQCONTENT118/n"
, "<//a>/n"
, "SQCONTENT119/n"
, "<a>/n"
, "SQCONTENT120/n"
, "<//a>/n"
, "SQCONTENT121/n"
, "<a>/n"
, "SQCONTENT122/n"
, "<//a>/n"
, "SQCONTENT123/n"
, "<//div>/n"
, "SQCONTENT124/n"
, "<div>/n"
, "SQCONTENT125/n"
, "<//div>/n"
, "SQCONTENT126/n"
, "<//div>/n"
, "SQCONTENT127/n"
, "<//div>/n"
, "SQCONTENT128/n"
, "<//td>/n"
, "SQCONTENT129/n"
, "<//tr>/n"
, "SQCONTENT130/n"
, "<tr>/n"
, "SQCONTENT131/n"
, "<td>/n"
, "SQCONTENT132/n"
, "<table>/n"
, "SQCONTENT133/n"
, "<tr>/n"
, "SQCONTENT134/n"
, "<td>/n"
, "SQCONTENT135/n"
, "<a>/n"
, "SQCONTENT136/n"
, "<//a>/n"
, "SQCONTENT137/n"
, "<//td>/n"
, "SQCONTENT138/n"
, "<td>/n"
, "SQCONTENT139/n"
, "<a>/n"
, "SQCONTENT140/n"
, "<//a>/n"
, "SQCONTENT141/n"
, "<//td>/n"
, "SQCONTENT142/n"
, "<td>/n"
, "SQCONTENT143/n"
, "<a>/n"
, "SQCONTENT144/n"
, "<//a>/n"
, "SQCONTENT145/n"
, "<//td>/n"
, "SQCONTENT146/n"
, "<td>/n"
, "SQCONTENT147/n"
, "<a>/n"
, "SQCONTENT148/n"
, "<//a>/n"
, "SQCONTENT149/n"
, "<//td>/n"
, "SQCONTENT150/n"
, "<//tr>/n"
, "SQCONTENT151/n"
, "<tr>/n"
, "SQCONTENT152/n"
, "<td>/n"
, "SQCONTENT153/n"
, "<a>/n"
, "SQCONTENT154/n"
, "<//a>/n"
, "SQCONTENT155/n"
, "<//td>/n"
, "SQCONTENT156/n"
, "<td>/n"
, "SQCONTENT157/n"
, "<a>/n"
, "SQCONTENT158/n"
, "<//a>/n"
, "SQCONTENT159/n"
, "<//td>/n"
, "SQCONTENT160/n"
, "<td>/n"
, "SQCONTENT161/n"
, "<a>/n"
, "SQCONTENT162/n"
, "<//a>/n"
, "SQCONTENT163/n"
, "<//td>/n"
, "SQCONTENT164/n"
, "<td>/n"
, "SQCONTENT165/n"
, "<a>/n"
, "SQCONTENT166/n"
, "<//a>/n"
, "SQCONTENT167/n"
, "<//td>/n"
, "SQCONTENT168/n"
, "<//tr>/n"
, "SQCONTENT169/n"
, "<tr>/n"
, "SQCONTENT170/n"
, "<td>/n"
, "SQCONTENT171/n"
, "<a>/n"
, "SQCONTENT172/n"
, "<//a>/n"
, "SQCONTENT173/n"
, "<//td>/n"
, "SQCONTENT174/n"
, "<td>/n"
, "SQCONTENT175/n"
, "<a>/n"
, "SQCONTENT176/n"
, "<//a>/n"
, "SQCONTENT177/n"
, "<//td>/n"
, "SQCONTENT178/n"
, "<td>/n"
, "SQCONTENT179/n"
, "<a>/n"
, "SQCONTENT180/n"
, "<//a>/n"
, "SQCONTENT181/n"
, "<//td>/n"
, "SQCONTENT182/n"
, "<td>/n"
, "SQCONTENT183/n"
, "<a>/n"
, "SQCONTENT184/n"
, "<//a>/n"
, "SQCONTENT185/n"
, "<//td>/n"
, "SQCONTENT186/n"
, "<//tr>/n"
, "SQCONTENT187/n"
, "<tr>/n"
, "SQCONTENT188/n"
, "<td>/n"
, "SQCONTENT189/n"
, "<a>/n"
, "SQCONTENT190/n"
, "<//a>/n"
, "SQCONTENT191/n"
, "<//td>/n"
, "SQCONTENT192/n"
, "<td>/n"
, "SQCONTENT193/n"
, "<a>/n"
, "SQCONTENT194/n"
, "<//a>/n"
, "SQCONTENT195/n"
, "<//td>/n"
, "SQCONTENT196/n"
, "<td>/n"
, "SQCONTENT197/n"
, "<a>/n"
, "SQCONTENT198/n"
, "<//a>/n"
, "SQCONTENT199/n"
, "<//td>/n"
, "SQCONTENT200/n"
, "<td>/n"
, "SQCONTENT201/n"
, "<a>/n"
, "SQCONTENT202/n"
, "<//a>/n"
, "SQCONTENT203/n"
, "<//td>/n"
, "SQCONTENT204/n"
, "<//tr>/n"
, "SQCONTENT205/n"
, "<tr>/n"
, "SQCONTENT206/n"
, "<td>/n"
, "SQCONTENT207/n"
, "<a>/n"
, "SQCONTENT208/n"
, "<//a>/n"
, "SQCONTENT209/n"
, "<//td>/n"
, "SQCONTENT210/n"
, "<td>/n"
, "SQCONTENT211/n"
, "<a>/n"
, "SQCONTENT212/n"
, "<//a>/n"
, "SQCONTENT213/n"
, "<//td>/n"
, "SQCONTENT214/n"
, "<td>/n"
, "SQCONTENT215/n"
, "<a>/n"
, "SQCONTENT216/n"
, "<//a>/n"
, "SQCONTENT217/n"
, "<//td>/n"
, "SQCONTENT218/n"
, "<td>/n"
, "SQCONTENT219/n"
, "<a>/n"
, "SQCONTENT220/n"
, "<//a>/n"
, "SQCONTENT221/n"
, "<//td>/n"
, "SQCONTENT222/n"
, "<//tr>/n"
, "SQCONTENT223/n"
, "<//table>/n"
, "SQCONTENT224/n"
, "<//td>/n"
, "SQCONTENT225/n"
, "<//tr>/n"
, "SQCONTENT226/n"
, "<//table>/n"
, "SQCONTENT227/n"
, "<div>/n"
, "SQCONTENT228/n"
, "<a>/n"
, "SQCONTENT229/n"
, "<//a>/n"
, "SQCONTENT230/n"
, "<a>/n"
, "SQCONTENT231/n"
, "<//a>/n"
, "SQCONTENT232/n"
, "<div>/n"
, "SQCONTENT233/n"
, "<//div>/n"
, "SQCONTENT234/n"
, "<//div>/n"
, "SQCONTENT235/n"
, "<//body>/n"
, "SQCONTENT236/n"
, "<//html>/n"
]. join ( "" )
;
Nodes = [Nodes ];
document. write ( "<xmp>Nodes: /n", Nodes, "</xmp><hr/>" );
var Re = new RegExp ( "(<([a-zA-Z][^<>]*?)>[//s//S]*?</2>)" );
var TagAr = [ ];
while ( Re. test ( Nodes [ 0 ] ) )
{
Nodes [ 0 ]. replace
(
Re,
function ( $0, $1, $2 )
{
var LevelAr = [0 ];
var sBegin = ["SQTAG", $2, "BEGIN" ]. join ( "" );
var sEnd = ["SQTAG", $2, "END" ]. join ( "" );
var sOpenTag = ["<", $2, ">" ]. join ( "" );
var sCloseTag = ["</", $2, ">" ]. join ( "" );
fMakeMarker
(
Nodes
, sBegin
, sEnd
, LevelAr
, "x"
, sOpenTag
, sCloseTag
, false
, false
);
TagAr. push ( [$2, LevelAr [ 0 ], sBegin, sEnd, sOpenTag, sCloseTag ] );
}
);
} // end while
// alert(TagAr.join("/n"));
document. write ( "<xmp>Final Nodes: /n", Nodes, "</xmp><hr/>" );
function fMakeMarker
(
Nodes
, PATTERNBEGIN
, PATTERNEND
, LevelAr
, sIdPostfix
, sLeft
, sRight
, bDebug
, bNoRecursive
)
{ // shawl.qiu code : return string
if ( Nodes [ 0 ]. indexOf ( sLeft ) < 0 || Nodes [ 0 ]. indexOf ( sRight ) < 0 ) return Nodes [ 0 ];
var Debug = bDebug;
var Pos = [ ];
var iStart = 0;
var iOver = Nodes [ 0 ]. length;
var TempPostfix = LevelAr [ 0 ] + sIdPostfix;
var TEMPPATTERNBEGIN = PATTERNBEGIN + TempPostfix;
var TEMPPATTERNEND = PATTERNEND + TempPostfix;
if ( Debug )
{
document. write ( "<xmp>" );
document. write ( "Nodes: ", Nodes, "/n/n" );
document. write
(
"Nodes[0].indexOf(sLeft, iStart): "
, Nodes [ 0 ]. indexOf ( sLeft, iStart )
, "/n"
);
document. write ( "</xmp>" );
document. write ( "<hr/>" );
}
while ( iStart < iOver )
{
var LeftPos = Nodes [ 0 ]. indexOf ( sLeft, iStart );
if ( LeftPos < 0 ) break;
var RightPos = Nodes [ 0 ]. indexOf ( sRight, LeftPos );
if ( RightPos < 0 ) break;
var TempStr = Nodes [ 0 ]. substring ( LeftPos, RightPos + sRight. length );
var iLeftOccur = fStringGetTimes ( TempStr, sLeft, true );
var iRightOccur = fStringGetTimes ( TempStr, sRight, true );
//alert(RightPos)
if ( iLeftOccur - iRightOccur !== 0 )
{
var Times = iLeftOccur - iRightOccur;
RightPos = fGetNextPos ( Nodes, Times, LeftPos, RightPos, sLeft, sRight );
}
// alert(RightPos)
//document.write("<xmp>", TempStr, "</xmp>");
// return;
if ( RightPos < 0 ) break;
var TempNodes = [ ];
TempNodes. push ( Nodes [ 0 ]. substring ( 0, LeftPos ) );
TempNodes. push ( TEMPPATTERNBEGIN );
TempNodes. push ( Nodes [ 0 ]. substring ( LeftPos + sLeft. length, RightPos ) );
TempNodes. push ( TEMPPATTERNEND );
TempNodes. push ( Nodes [ 0 ]. slice ( RightPos + sRight. length ) );
//alert(TempNodes)
Nodes [ 0 ] = TempNodes. join ( "" );
var Span = TEMPPATTERNEND. length + TEMPPATTERNBEGIN. length - sLeft. length;
iOver += Span;
RightPos += Span;
TempStr = Nodes [ 0 ]. slice
(
LeftPos
, RightPos
);
iLeftOccur = fStringGetTimes ( TempStr, sLeft, true );
iRightOccur = fStringGetTimes ( TempStr, sRight, true );
if ( Debug )
{
document. write ( "<xmp>" );
document. write ( "TempNodes: ", TempNodes, "/n" );
document. write ( "LeftPos: ", LeftPos, "/n" );
document. write ( "RightPos: ", RightPos, "/n" );
document. write ( "TempStr: ", TempStr, "/n" );
document. write ( "iLeftOccur: ", iLeftOccur, "/n" );
document. write ( "iRightOccur: ", iRightOccur, "/n" );
document. write ( "LevelAr: ", LevelAr, "/n" );
document. write ( "</xmp>" );
}
iStart = RightPos + 1;
}
if ( Debug )
document. write ( "<hr/>" );
if ( bNoRecursive ) return;
LevelAr [ 0 ] = LevelAr [ 0 ] + 1;
if ( Nodes [ 0 ]. indexOf ( sLeft ) > - 1&& Nodes [ 0 ]. indexOf ( sRight ) > - 1 )
{
arguments. callee
(
Nodes
, PATTERNBEGIN
, PATTERNEND
, LevelAr
, sIdPostfix
, sLeft
, sRight
, bDebug
);
}
} // end function fMakeMarker
function fGetNextPos ( Nodes, Times, LeftPos, RightPos, sLeft, sRight )
{
if ( Times < 1 ) return RightPos;
for ( var i =0; i <Times; i ++ )
{
RightPos = Nodes [ 0 ]. indexOf ( sRight, RightPos );
}
var TempStr = Nodes [ 0 ]. substring ( LeftPos, RightPos + sRight. length );
var iLeftOccur = fStringGetTimes ( TempStr, sLeft, true );
var iRightOccur = fStringGetTimes ( TempStr, sRight, true );
Times = iLeftOccur - iRightOccur;
if ( Times > 0 )
{
RightPos = arguments. callee ( Nodes, Times, LeftPos, RightPos + sRight. length, sLeft, sRight );
}
return RightPos;
}
function fStringGetTimes ( Source, sMatch, bCharacter, sFlag )
{ // shawl.qiu code : return integer
var iTime = 0;
var Re = null;
if (! sFlag ) sFlag = "gi";
if ( Source. constructor == String )
{
Source = [Source ];
}
if (! bCharacter )
{
Re = new RegExp ( '//b(' + sMatch + ')//b', sFlag );
}
else
{
sMatch = "//" + sMatch;
Re = new RegExp ( '(' + sMatch + ')', sFlag );
}
Source [ 0 ]. replace
(
Re
, function ( $0, $1 )
{
if ( $1 != '' ) iTime += 1;
}
);
return iTime;
} // end function fStringGetTimes
/*]]*/
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
<style type="text/css">
/* <![CDATA[ */
/* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if ( navigator. appName == "Microsoft Internet Explorer" )
{
//最大化窗口
self. moveTo ( - 5, - 5 )
self. resizeTo ( screen. availWidth + 8, screen. availHeight + 8 )
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Nodes =
[
, "SQSTRUCTURE0/n"
, "<html>/n"
, "SQCONTENT0/n"
, "<head><div><div><div></div></div></div>/n"
, "SQCONTENT1/n"
, "<title>/n"
, "SQCONTENT2/n"
, "<//title><a><a></a></a>/n"
, "SQCONTENT3/n"
, "<//head>/n"
, "SQCONTENT4/n"
, "<body>/n"
, "SQCONTENT5/n"
, "<table>/n"
, "SQCONTENT6/n"
, "<tr>/n"
, "SQCONTENT7/n"
, "<td>/n"
, "SQCONTENT8/n"
, "<a>/n"
, "SQCONTENT9/n"
, "<//a>/n"
, "SQCONTENT10/n"
, "<a>/n"
, "SQCONTENT11/n"
, "<//a>/n"
, "SQCONTENT12/n"
, "<a>/n"
, "SQCONTENT13/n"
, "<//a>/n"
, "SQCONTENT14/n"
, "<a>/n"
, "SQCONTENT15/n"
, "<//a>/n"
, "SQCONTENT16/n"
, "<//td>/n"
, "SQCONTENT17/n"
, "<td>/n"
, "SQCONTENT18/n"
, "<a>/n"
, "SQCONTENT19/n"
, "<//a>/n"
, "SQCONTENT20/n"
, "<//td>/n"
, "SQCONTENT21/n"
, "<//tr>/n"
, "SQCONTENT22/n"
, "<tr>/n"
, "SQCONTENT23/n"
, "<td>/n"
, "SQCONTENT24/n"
, "<div>/n"
, "SQCONTENT25/n"
, "<A>/n"
, "SQCONTENT26/n"
, "<//A>/n"
, "SQCONTENT27/n"
, "<//div>/n"
, "SQCONTENT28/n"
, "<//td>/n"
, "SQCONTENT29/n"
, "<//tr>/n"
, "SQCONTENT30/n"
, "<tr>/n"
, "SQCONTENT31/n"
, "<td>/n"
, "SQCONTENT32/n"
, "<div>/n"
, "SQCONTENT33/n"
, "<form>/n"
, "SQCONTENT34/n"
, "<//form>/n"
, "SQCONTENT35/n"
, "<form>/n"
, "SQCONTENT36/n"
, "<//form>/n"
, "SQCONTENT37/n"
, "<//div>/n"
, "SQCONTENT38/n"
, "<//td>/n"
, "SQCONTENT39/n"
, "<//tr>/n"
, "SQCONTENT40/n"
, "<tr>/n"
, "SQCONTENT41/n"
, "<td>/n"
, "SQCONTENT42/n"
, "<div>/n"
, "SQCONTENT43/n"
, "<//div>/n"
, "SQCONTENT44/n"
, "<//td>/n"
, "SQCONTENT45/n"
, "<//tr>/n"
, "SQCONTENT46/n"
, "<//table>/n"
, "SQCONTENT47/n"
, "<table>/n"
, "SQCONTENT48/n"
, "<tr>/n"
, "SQCONTENT49/n"
, "<td>/n"
, "SQCONTENT50/n"
, "<div>/n"
, "SQCONTENT51/n"
, "<div>/n"
, "SQCONTENT52/n"
, "<label>/n"
, "SQCONTENT53/n"
, "<//label>/n"
, "SQCONTENT54/n"
, "<ul>/n"
, "SQCONTENT55/n"
, "<li>/n"
, "SQCONTENT56/n"
, "<//li>/n"
, "SQCONTENT57/n"
, "<li>/n"
, "SQCONTENT58/n"
, "<//li>/n"
, "SQCONTENT59/n"
, "<li>/n"
, "SQCONTENT60/n"
, "<//li>/n"
, "SQCONTENT61/n"
, "<li>/n"
, "SQCONTENT62/n"
, "<//li>/n"
, "SQCONTENT63/n"
, "<li>/n"
, "SQCONTENT64/n"
, "<//li>/n"
, "SQCONTENT65/n"
, "<li>/n"
, "SQCONTENT66/n"
, "<//li>/n"
, "SQCONTENT67/n"
, "<li>/n"
, "SQCONTENT68/n"
, "<//li>/n"
, "SQCONTENT69/n"
, "<li>/n"
, "SQCONTENT70/n"
, "<//li>/n"
, "SQCONTENT71/n"
, "<li>/n"
, "SQCONTENT72/n"
, "<//li>/n"
, "SQCONTENT73/n"
, "<//ul>/n"
, "SQCONTENT74/n"
, "<//div>/n"
, "SQCONTENT75/n"
, "<div>/n"
, "SQCONTENT76/n"
, "<a>/n"
, "SQCONTENT77/n"
, "<//a>/n"
, "SQCONTENT78/n"
, "<//div>/n"
, "SQCONTENT79/n"
, "<//div>/n"
, "SQCONTENT80/n"
, "<//td>/n"
, "SQCONTENT81/n"
, "<td>/n"
, "SQCONTENT82/n"
, "<form>/n"
, "SQCONTENT83/n"
, "<//form>/n"
, "SQCONTENT84/n"
, "<//td>/n"
, "SQCONTENT85/n"
, "<//tr>/n"
, "SQCONTENT86/n"
, "<tr>/n"
, "SQCONTENT87/n"
, "<td>/n"
, "SQCONTENT88/n"
, "<div>/n"
, "SQCONTENT89/n"
, "<div>/n"
, "SQCONTENT90/n"
, "<div>/n"
, "SQCONTENT91/n"
, "<span>/n"
, "SQCONTENT92/n"
, "<//span>/n"
, "SQCONTENT93/n"
, "<span>/n"
, "SQCONTENT94/n"
, "<//span>/n"
, "SQCONTENT95/n"
, "<span>/n"
, "SQCONTENT96/n"
, "<//span>/n"
, "SQCONTENT97/n"
, "<span>/n"
, "SQCONTENT98/n"
, "<//span>/n"
, "SQCONTENT99/n"
, "<a>/n"
, "SQCONTENT100/n"
, "<//a>/n"
, "SQCONTENT101/n"
, "<a>/n"
, "SQCONTENT102/n"
, "<//a>/n"
, "SQCONTENT103/n"
, "<a>/n"
, "SQCONTENT104/n"
, "<//a>/n"
, "SQCONTENT105/n"
, "<a>/n"
, "SQCONTENT106/n"
, "<//a>/n"
, "SQCONTENT107/n"
, "<a>/n"
, "SQCONTENT108/n"
, "<//a>/n"
, "SQCONTENT109/n"
, "<a>/n"
, "SQCONTENT110/n"
, "<//a>/n"
, "SQCONTENT111/n"
, "<a>/n"
, "SQCONTENT112/n"
, "<//a>/n"
, "SQCONTENT113/n"
, "<a>/n"
, "SQCONTENT114/n"
, "<//a>/n"
, "SQCONTENT115/n"
, "<a>/n"
, "SQCONTENT116/n"
, "<//a>/n"
, "SQCONTENT117/n"
, "<a>/n"
, "SQCONTENT118/n"
, "<//a>/n"
, "SQCONTENT119/n"
, "<a>/n"
, "SQCONTENT120/n"
, "<//a>/n"
, "SQCONTENT121/n"
, "<a>/n"
, "SQCONTENT122/n"
, "<//a>/n"
, "SQCONTENT123/n"
, "<//div>/n"
, "SQCONTENT124/n"
, "<div>/n"
, "SQCONTENT125/n"
, "<//div>/n"
, "SQCONTENT126/n"
, "<//div>/n"
, "SQCONTENT127/n"
, "<//div>/n"
, "SQCONTENT128/n"
, "<//td>/n"
, "SQCONTENT129/n"
, "<//tr>/n"
, "SQCONTENT130/n"
, "<tr>/n"
, "SQCONTENT131/n"
, "<td>/n"
, "SQCONTENT132/n"
, "<table>/n"
, "SQCONTENT133/n"
, "<tr>/n"
, "SQCONTENT134/n"
, "<td>/n"
, "SQCONTENT135/n"
, "<a>/n"
, "SQCONTENT136/n"
, "<//a>/n"
, "SQCONTENT137/n"
, "<//td>/n"
, "SQCONTENT138/n"
, "<td>/n"
, "SQCONTENT139/n"
, "<a>/n"
, "SQCONTENT140/n"
, "<//a>/n"
, "SQCONTENT141/n"
, "<//td>/n"
, "SQCONTENT142/n"
, "<td>/n"
, "SQCONTENT143/n"
, "<a>/n"
, "SQCONTENT144/n"
, "<//a>/n"
, "SQCONTENT145/n"
, "<//td>/n"
, "SQCONTENT146/n"
, "<td>/n"
, "SQCONTENT147/n"
, "<a>/n"
, "SQCONTENT148/n"
, "<//a>/n"
, "SQCONTENT149/n"
, "<//td>/n"
, "SQCONTENT150/n"
, "<//tr>/n"
, "SQCONTENT151/n"
, "<tr>/n"
, "SQCONTENT152/n"
, "<td>/n"
, "SQCONTENT153/n"
, "<a>/n"
, "SQCONTENT154/n"
, "<//a>/n"
, "SQCONTENT155/n"
, "<//td>/n"
, "SQCONTENT156/n"
, "<td>/n"
, "SQCONTENT157/n"
, "<a>/n"
, "SQCONTENT158/n"
, "<//a>/n"
, "SQCONTENT159/n"
, "<//td>/n"
, "SQCONTENT160/n"
, "<td>/n"
, "SQCONTENT161/n"
, "<a>/n"
, "SQCONTENT162/n"
, "<//a>/n"
, "SQCONTENT163/n"
, "<//td>/n"
, "SQCONTENT164/n"
, "<td>/n"
, "SQCONTENT165/n"
, "<a>/n"
, "SQCONTENT166/n"
, "<//a>/n"
, "SQCONTENT167/n"
, "<//td>/n"
, "SQCONTENT168/n"
, "<//tr>/n"
, "SQCONTENT169/n"
, "<tr>/n"
, "SQCONTENT170/n"
, "<td>/n"
, "SQCONTENT171/n"
, "<a>/n"
, "SQCONTENT172/n"
, "<//a>/n"
, "SQCONTENT173/n"
, "<//td>/n"
, "SQCONTENT174/n"
, "<td>/n"
, "SQCONTENT175/n"
, "<a>/n"
, "SQCONTENT176/n"
, "<//a>/n"
, "SQCONTENT177/n"
, "<//td>/n"
, "SQCONTENT178/n"
, "<td>/n"
, "SQCONTENT179/n"
, "<a>/n"
, "SQCONTENT180/n"
, "<//a>/n"
, "SQCONTENT181/n"
, "<//td>/n"
, "SQCONTENT182/n"
, "<td>/n"
, "SQCONTENT183/n"
, "<a>/n"
, "SQCONTENT184/n"
, "<//a>/n"
, "SQCONTENT185/n"
, "<//td>/n"
, "SQCONTENT186/n"
, "<//tr>/n"
, "SQCONTENT187/n"
, "<tr>/n"
, "SQCONTENT188/n"
, "<td>/n"
, "SQCONTENT189/n"
, "<a>/n"
, "SQCONTENT190/n"
, "<//a>/n"
, "SQCONTENT191/n"
, "<//td>/n"
, "SQCONTENT192/n"
, "<td>/n"
, "SQCONTENT193/n"
, "<a>/n"
, "SQCONTENT194/n"
, "<//a>/n"
, "SQCONTENT195/n"
, "<//td>/n"
, "SQCONTENT196/n"
, "<td>/n"
, "SQCONTENT197/n"
, "<a>/n"
, "SQCONTENT198/n"
, "<//a>/n"
, "SQCONTENT199/n"
, "<//td>/n"
, "SQCONTENT200/n"
, "<td>/n"
, "SQCONTENT201/n"
, "<a>/n"
, "SQCONTENT202/n"
, "<//a>/n"
, "SQCONTENT203/n"
, "<//td>/n"
, "SQCONTENT204/n"
, "<//tr>/n"
, "SQCONTENT205/n"
, "<tr>/n"
, "SQCONTENT206/n"
, "<td>/n"
, "SQCONTENT207/n"
, "<a>/n"
, "SQCONTENT208/n"
, "<//a>/n"
, "SQCONTENT209/n"
, "<//td>/n"
, "SQCONTENT210/n"
, "<td>/n"
, "SQCONTENT211/n"
, "<a>/n"
, "SQCONTENT212/n"
, "<//a>/n"
, "SQCONTENT213/n"
, "<//td>/n"
, "SQCONTENT214/n"
, "<td>/n"
, "SQCONTENT215/n"
, "<a>/n"
, "SQCONTENT216/n"
, "<//a>/n"
, "SQCONTENT217/n"
, "<//td>/n"
, "SQCONTENT218/n"
, "<td>/n"
, "SQCONTENT219/n"
, "<a>/n"
, "SQCONTENT220/n"
, "<//a>/n"
, "SQCONTENT221/n"
, "<//td>/n"
, "SQCONTENT222/n"
, "<//tr>/n"
, "SQCONTENT223/n"
, "<//table>/n"
, "SQCONTENT224/n"
, "<//td>/n"
, "SQCONTENT225/n"
, "<//tr>/n"
, "SQCONTENT226/n"
, "<//table>/n"
, "SQCONTENT227/n"
, "<div>/n"
, "SQCONTENT228/n"
, "<a>/n"
, "SQCONTENT229/n"
, "<//a>/n"
, "SQCONTENT230/n"
, "<a>/n"
, "SQCONTENT231/n"
, "<//a>/n"
, "SQCONTENT232/n"
, "<div>/n"
, "SQCONTENT233/n"
, "<//div>/n"
, "SQCONTENT234/n"
, "<//div>/n"
, "SQCONTENT235/n"
, "<//body>/n"
, "SQCONTENT236/n"
, "<//html>/n"
]. join ( "" )
;
Nodes = [Nodes ];
document. write ( "<xmp>Nodes: /n", Nodes, "</xmp><hr/>" );
var Re = new RegExp ( "(<([a-zA-Z][^<>]*?)>[//s//S]*?</2>)" );
var TagAr = [ ];
while ( Re. test ( Nodes [ 0 ] ) )
{
Nodes [ 0 ]. replace
(
Re,
function ( $0, $1, $2 )
{
var LevelAr = [0 ];
var sBegin = ["SQTAG", $2, "BEGIN" ]. join ( "" );
var sEnd = ["SQTAG", $2, "END" ]. join ( "" );
var sOpenTag = ["<", $2, ">" ]. join ( "" );
var sCloseTag = ["</", $2, ">" ]. join ( "" );
fMakeMarker
(
Nodes
, sBegin
, sEnd
, LevelAr
, "x"
, sOpenTag
, sCloseTag
, false
, false
);
TagAr. push ( [$2, LevelAr [ 0 ], sBegin, sEnd, sOpenTag, sCloseTag ] );
}
);
} // end while
// alert(TagAr.join("/n"));
document. write ( "<xmp>Final Nodes: /n", Nodes, "</xmp><hr/>" );
function fMakeMarker
(
Nodes
, PATTERNBEGIN
, PATTERNEND
, LevelAr
, sIdPostfix
, sLeft
, sRight
, bDebug
, bNoRecursive
)
{ // shawl.qiu code : return string
if ( Nodes [ 0 ]. indexOf ( sLeft ) < 0 || Nodes [ 0 ]. indexOf ( sRight ) < 0 ) return Nodes [ 0 ];
var Debug = bDebug;
var Pos = [ ];
var iStart = 0;
var iOver = Nodes [ 0 ]. length;
var TempPostfix = LevelAr [ 0 ] + sIdPostfix;
var TEMPPATTERNBEGIN = PATTERNBEGIN + TempPostfix;
var TEMPPATTERNEND = PATTERNEND + TempPostfix;
if ( Debug )
{
document. write ( "<xmp>" );
document. write ( "Nodes: ", Nodes, "/n/n" );
document. write
(
"Nodes[0].indexOf(sLeft, iStart): "
, Nodes [ 0 ]. indexOf ( sLeft, iStart )
, "/n"
);
document. write ( "</xmp>" );
document. write ( "<hr/>" );
}
while ( iStart < iOver )
{
var LeftPos = Nodes [ 0 ]. indexOf ( sLeft, iStart );
if ( LeftPos < 0 ) break;
var RightPos = Nodes [ 0 ]. indexOf ( sRight, LeftPos );
if ( RightPos < 0 ) break;
var TempStr = Nodes [ 0 ]. substring ( LeftPos, RightPos + sRight. length );
var iLeftOccur = fStringGetTimes ( TempStr, sLeft, true );
var iRightOccur = fStringGetTimes ( TempStr, sRight, true );
//alert(RightPos)
if ( iLeftOccur - iRightOccur !== 0 )
{
var Times = iLeftOccur - iRightOccur;
RightPos = fGetNextPos ( Nodes, Times, LeftPos, RightPos, sLeft, sRight );
}
// alert(RightPos)
//document.write("<xmp>", TempStr, "</xmp>");
// return;
if ( RightPos < 0 ) break;
var TempNodes = [ ];
TempNodes. push ( Nodes [ 0 ]. substring ( 0, LeftPos ) );
TempNodes. push ( TEMPPATTERNBEGIN );
TempNodes. push ( Nodes [ 0 ]. substring ( LeftPos + sLeft. length, RightPos ) );
TempNodes. push ( TEMPPATTERNEND );
TempNodes. push ( Nodes [ 0 ]. slice ( RightPos + sRight. length ) );
//alert(TempNodes)
Nodes [ 0 ] = TempNodes. join ( "" );
var Span = TEMPPATTERNEND. length + TEMPPATTERNBEGIN. length - sLeft. length;
iOver += Span;
RightPos += Span;
TempStr = Nodes [ 0 ]. slice
(
LeftPos
, RightPos
);
iLeftOccur = fStringGetTimes ( TempStr, sLeft, true );
iRightOccur = fStringGetTimes ( TempStr, sRight, true );
if ( Debug )
{
document. write ( "<xmp>" );
document. write ( "TempNodes: ", TempNodes, "/n" );
document. write ( "LeftPos: ", LeftPos, "/n" );
document. write ( "RightPos: ", RightPos, "/n" );
document. write ( "TempStr: ", TempStr, "/n" );
document. write ( "iLeftOccur: ", iLeftOccur, "/n" );
document. write ( "iRightOccur: ", iRightOccur, "/n" );
document. write ( "LevelAr: ", LevelAr, "/n" );
document. write ( "</xmp>" );
}
iStart = RightPos + 1;
}
if ( Debug )
document. write ( "<hr/>" );
if ( bNoRecursive ) return;
LevelAr [ 0 ] = LevelAr [ 0 ] + 1;
if ( Nodes [ 0 ]. indexOf ( sLeft ) > - 1&& Nodes [ 0 ]. indexOf ( sRight ) > - 1 )
{
arguments. callee
(
Nodes
, PATTERNBEGIN
, PATTERNEND
, LevelAr
, sIdPostfix
, sLeft
, sRight
, bDebug
);
}
} // end function fMakeMarker
function fGetNextPos ( Nodes, Times, LeftPos, RightPos, sLeft, sRight )
{
if ( Times < 1 ) return RightPos;
for ( var i =0; i <Times; i ++ )
{
RightPos = Nodes [ 0 ]. indexOf ( sRight, RightPos );
}
var TempStr = Nodes [ 0 ]. substring ( LeftPos, RightPos + sRight. length );
var iLeftOccur = fStringGetTimes ( TempStr, sLeft, true );
var iRightOccur = fStringGetTimes ( TempStr, sRight, true );
Times = iLeftOccur - iRightOccur;
if ( Times > 0 )
{
RightPos = arguments. callee ( Nodes, Times, LeftPos, RightPos + sRight. length, sLeft, sRight );
}
return RightPos;
}
function fStringGetTimes ( Source, sMatch, bCharacter, sFlag )
{ // shawl.qiu code : return integer
var iTime = 0;
var Re = null;
if (! sFlag ) sFlag = "gi";
if ( Source. constructor == String )
{
Source = [Source ];
}
if (! bCharacter )
{
Re = new RegExp ( '//b(' + sMatch + ')//b', sFlag );
}
else
{
sMatch = "//" + sMatch;
Re = new RegExp ( '(' + sMatch + ')', sFlag );
}
Source [ 0 ]. replace
(
Re
, function ( $0, $1 )
{
if ( $1 != '' ) iTime += 1;
}
);
return iTime;
} // end function fStringGetTimes
/*]]*/
</script>
</body>
</html>