﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-Eckel's world</title><link>http://www.blogjava.net/eckelcn/</link><description>The program should be extensible and reusable.</description><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 06:01:40 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 06:01:40 GMT</pubDate><ttl>60</ttl><item><title>深入StringBuffer</title><link>http://www.blogjava.net/eckelcn/archive/2005/11/18/20467.html</link><dc:creator>eckelcn</dc:creator><author>eckelcn</author><pubDate>Fri, 18 Nov 2005 09:25:00 GMT</pubDate><guid>http://www.blogjava.net/eckelcn/archive/2005/11/18/20467.html</guid><wfw:comment>http://www.blogjava.net/eckelcn/comments/20467.html</wfw:comment><comments>http://www.blogjava.net/eckelcn/archive/2005/11/18/20467.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eckelcn/comments/commentRss/20467.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eckelcn/services/trackbacks/20467.html</trackback:ping><description><![CDATA[<DIV align=center><STRONG>深入StringBuffer</STRONG><BR><EM>作者:eckel_cn</EM></DIV>
<DIV>&nbsp;&nbsp;&nbsp; 最近,闲暇之余,重新整理自用的StringUtil类,在整理到repeat方法(重复字符串)时,发现其存在效率问题,便打算重新写一下,却发现了一系列以前没太注意的东西,觉得很有必要写下来.</DIV>
<DIV>原来这个repeat方法,很简单,主要代码大致如下:<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN><IMG id=Codehighlighter1_48_183_Open_Image onclick="this.style.display='none'; Codehighlighter1_48_183_Open_Text.style.display='none'; Codehighlighter1_48_183_Closed_Image.style.display='inline'; Codehighlighter1_48_183_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_48_183_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_183_Closed_Text.style.display='none'; Codehighlighter1_48_183_Open_Image.style.display='inline'; Codehighlighter1_48_183_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;repeat1(String&nbsp;str,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;n)&nbsp;</SPAN><SPAN id=Codehighlighter1_48_183_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_48_183_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>StringBuffer&nbsp;strBuf&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;StrBuffer(str.length()</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">n);<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_130_156_Open_Image onclick="this.style.display='none'; Codehighlighter1_130_156_Open_Text.style.display='none'; Codehighlighter1_130_156_Closed_Image.style.display='inline'; Codehighlighter1_130_156_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_130_156_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_130_156_Closed_Text.style.display='none'; Codehighlighter1_130_156_Open_Image.style.display='inline'; Codehighlighter1_130_156_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;n;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_130_156_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_130_156_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;strBuf.append(str);<BR></SPAN><SPAN style="COLOR: #008080">5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>retrn&nbsp;strBuf.toString();<BR></SPAN><SPAN style="COLOR: #008080">7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<DIV>&nbsp;&nbsp;&nbsp; 初一看,就能发现一点问题,当n很大,达到一定大小,就能使堆栈溢出.出现OutOfMemery错误.</DIV>
<DIV>那如何避免这个问题呢,我马上想到了,既然StringBuffer和String一样内部都是在操作char数组,<BR>那我就自己直接操作char数组,在最少的循环里面,填充char数组,代码如下:<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG id=Codehighlighter1_48_455_Open_Image onclick="this.style.display='none'; Codehighlighter1_48_455_Open_Text.style.display='none'; Codehighlighter1_48_455_Closed_Image.style.display='inline'; Codehighlighter1_48_455_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_48_455_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_455_Closed_Text.style.display='none'; Codehighlighter1_48_455_Open_Image.style.display='inline'; Codehighlighter1_48_455_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;repeat2(String&nbsp;str,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;n)&nbsp;</SPAN><SPAN id=Codehighlighter1_48_455_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_48_455_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;len&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;str.length();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;maxlen&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;len&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;n;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">[]&nbsp;chars&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">[len&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;n];<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;str.getChars(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,&nbsp;len,&nbsp;chars,&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;count&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;len;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;copyLen&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_296_395_Open_Image onclick="this.style.display='none'; Codehighlighter1_296_395_Open_Text.style.display='none'; Codehighlighter1_296_395_Closed_Image.style.display='inline'; Codehighlighter1_296_395_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_296_395_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_296_395_Closed_Text.style.display='none'; Codehighlighter1_296_395_Open_Image.style.display='inline'; Codehighlighter1_296_395_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">&nbsp;((copyLen&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;maxlen&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;count&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;count&nbsp;</SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000">&nbsp;count&nbsp;:&nbsp;maxlen&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;count)&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_296_395_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_296_395_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.arraycopy(chars,&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,&nbsp;chars,&nbsp;count,&nbsp;copyLen);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;copyLen;<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;outstr&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String(chars);<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;outstr;<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<DIV>&nbsp;&nbsp;&nbsp; 测试后,发现,循环控制在了最少,但是,性能却还不如repeat1,也许你会和我一样开始很惊讶,但看了<BR>StringBuffer的实现后,发现repeat2的实现中,将char数组,转换为String,是效率多么低的事情,这个过程需要在String内部重新创建一个char数组,然后把传进去的char数组,复制给它.而repeat1中为什么没有这个性能问题呢,其实这就是要归功于SUN在实现StringBuffer中的一个重要属性:shared,当你使用StringBuffer后,想得到String时,String会共享StringBuffer中的char数组,这样一来,性能非常高.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 共享会不会带来副作用呢,SUN的实现当然考虑到了,在改变StringBuffer时,如果这个StringBuffer<BR>有其他String共享它的char数组时,StringBuffer就把这个char数组让给String,自己重新复制一份使用.</DIV>
<DIV>既然问题发现了,我又换了种算法来实现,同样也是把循环控制在最少,同时解决转换带来的效率低下问题.<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG id=Codehighlighter1_48_1106_Open_Image onclick="this.style.display='none'; Codehighlighter1_48_1106_Open_Text.style.display='none'; Codehighlighter1_48_1106_Closed_Image.style.display='inline'; Codehighlighter1_48_1106_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_48_1106_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_1106_Closed_Text.style.display='none'; Codehighlighter1_48_1106_Open_Image.style.display='inline'; Codehighlighter1_48_1106_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;repeat3(String&nbsp;str,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;n)&nbsp;</SPAN><SPAN id=Codehighlighter1_48_1106_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_48_1106_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;if&nbsp;input&nbsp;string&nbsp;is&nbsp;null,return&nbsp;null.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #008000"><IMG id=Codehighlighter1_109_127_Open_Image onclick="this.style.display='none'; Codehighlighter1_109_127_Open_Text.style.display='none'; Codehighlighter1_109_127_Closed_Image.style.display='inline'; Codehighlighter1_109_127_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_109_127_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_109_127_Closed_Text.style.display='none'; Codehighlighter1_109_127_Open_Image.style.display='inline'; Codehighlighter1_109_127_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;str)&nbsp;</SPAN><SPAN id=Codehighlighter1_109_127_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_109_127_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;strlen&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;str.length();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;if&nbsp;repeat&nbsp;number&nbsp;is&nbsp;less&nbsp;than&nbsp;two&nbsp;or&nbsp;given&nbsp;string's&nbsp;length&nbsp;is&nbsp;zero,<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;then&nbsp;return&nbsp;the&nbsp;givien&nbsp;string.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #008000"><IMG id=Codehighlighter1_297_314_Open_Image onclick="this.style.display='none'; Codehighlighter1_297_314_Open_Text.style.display='none'; Codehighlighter1_297_314_Closed_Image.style.display='inline'; Codehighlighter1_297_314_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_297_314_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_297_314_Closed_Text.style.display='none'; Codehighlighter1_297_314_Open_Image.style.display='inline'; Codehighlighter1_297_314_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;n&nbsp;</SPAN><SPAN style="COLOR: #000000">||</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;strlen)&nbsp;</SPAN><SPAN id=Codehighlighter1_297_314_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_297_314_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;str;<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;assigns&nbsp;the&nbsp;enough&nbsp;size&nbsp;for&nbsp;the&nbsp;string&nbsp;buffer.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;StringBuffer&nbsp;strBuf&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;StringBuffer(strlen&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;n);<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;get&nbsp;odd&nbsp;length&nbsp;flag.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;oddLen&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;n&nbsp;</SPAN><SPAN style="COLOR: #000000">%</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;:&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;calculates&nbsp;the&nbsp;grow&nbsp;times.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;growTimes&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">)&nbsp;Math.floor(Math.log(n)&nbsp;</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">&nbsp;Math.log(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;adds&nbsp;one&nbsp;given&nbsp;string.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;strBuf.append(str);<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;grows&nbsp;until&nbsp;more&nbsp;than&nbsp;half&nbsp;of&nbsp;the&nbsp;repeat&nbsp;count.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #008000"><IMG id=Codehighlighter1_732_837_Open_Image onclick="this.style.display='none'; Codehighlighter1_732_837_Open_Text.style.display='none'; Codehighlighter1_732_837_Closed_Image.style.display='inline'; Codehighlighter1_732_837_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_732_837_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_732_837_Closed_Text.style.display='none'; Codehighlighter1_732_837_Open_Image.style.display='inline'; Codehighlighter1_732_837_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;growTimes;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_732_837_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_732_837_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;strBuf.append(strBuf);<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_820_834_Open_Image onclick="this.style.display='none'; Codehighlighter1_820_834_Open_Text.style.display='none'; Codehighlighter1_820_834_Closed_Image.style.display='inline'; Codehighlighter1_820_834_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_820_834_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_820_834_Closed_Text.style.display='none'; Codehighlighter1_820_834_Open_Image.style.display='inline'; Codehighlighter1_820_834_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(Math.pow(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;n&nbsp;</SPAN><SPAN style="COLOR: #000000">&amp;&amp;</SPAN><SPAN style="COLOR: #000000">&nbsp;Math.pow(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,&nbsp;i)&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;=</SPAN><SPAN style="COLOR: #000000">&nbsp;n)&nbsp;</SPAN><SPAN id=Codehighlighter1_820_834_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_820_834_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">break</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;reset&nbsp;the&nbsp;string&nbsp;buffer's&nbsp;length&nbsp;to&nbsp;half&nbsp;of&nbsp;the&nbsp;repeat&nbsp;count.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;strBuf.setLength(strlen&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;Math.round(n&nbsp;</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;grows&nbsp;to&nbsp;the&nbsp;repeat&nbsp;count.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;strBuf.append(strBuf);<BR></SPAN><SPAN style="COLOR: #008080">31</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_1020_1045_Open_Image onclick="this.style.display='none'; Codehighlighter1_1020_1045_Open_Text.style.display='none'; Codehighlighter1_1020_1045_Closed_Image.style.display='inline'; Codehighlighter1_1020_1045_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1020_1045_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1020_1045_Closed_Text.style.display='none'; Codehighlighter1_1020_1045_Open_Image.style.display='inline'; Codehighlighter1_1020_1045_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(oddLen)&nbsp;</SPAN><SPAN id=Codehighlighter1_1020_1045_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1020_1045_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">32</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;strBuf.append(str);<BR></SPAN><SPAN style="COLOR: #008080">33</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">34</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;String&nbsp;returnStr&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String(strBuf);<BR></SPAN><SPAN style="COLOR: #008080">35</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;returnStr;<BR></SPAN><SPAN style="COLOR: #008080">36</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">37</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp; 算法实现,再次测试,测试发现,在规模不是特别大的情况下,repeat3的效率要明显优于前两个,但在规模大的情况下,会变的差不多,怎么会这样的呢,再次进行深入调查,结果发现是SUN的System.arrayCopy这个方法有性能问题,特别是当要复制的长度特别大的情况下,性能下降的比较快,再换个IBM的JDK实现,又发现,IBM的这个方法的实现要比SUN有改进.</DIV>
<DIV>&nbsp;&nbsp;&nbsp; 真是一次比较有意思的深入StringBuffer,在实际运用中repeat3完全可以代替上面两种方法.</DIV><img src ="http://www.blogjava.net/eckelcn/aggbug/20467.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eckelcn/" target="_blank">eckelcn</a> 2005-11-18 17:25 <a href="http://www.blogjava.net/eckelcn/archive/2005/11/18/20467.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对javascript特殊字符的处理</title><link>http://www.blogjava.net/eckelcn/archive/2005/11/18/20466.html</link><dc:creator>eckelcn</dc:creator><author>eckelcn</author><pubDate>Fri, 18 Nov 2005 09:25:00 GMT</pubDate><guid>http://www.blogjava.net/eckelcn/archive/2005/11/18/20466.html</guid><wfw:comment>http://www.blogjava.net/eckelcn/comments/20466.html</wfw:comment><comments>http://www.blogjava.net/eckelcn/archive/2005/11/18/20466.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/eckelcn/comments/commentRss/20466.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eckelcn/services/trackbacks/20466.html</trackback:ping><description><![CDATA[<DIV align=center><STRONG>对javascript特殊字符的处理</STRONG></DIV>
<DIV align=center>作者:eckel_cn</DIV>
<DIV>&nbsp;</DIV>
<DIV>javascript和JAVA一样,一些特殊字符需要转义</DIV>
<DIV>&nbsp;</DIV>
<DIV>特别是在一些JSP网页的开发中,好多程序员经常会忘掉这点,</DIV>
<DIV>例:</DIV>
<DIV>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;List&nbsp;textList&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;(List)request.getAttribute(</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">textList</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">);&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">2</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">3</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;!--</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">4</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">var</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;txtList&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">new</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;Array();<BR></SPAN><SPAN style="COLOR: #008080">5</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">for</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;(&nbsp;</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">int</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">0</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;textList.size()&nbsp;;&nbsp;i</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">++</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">)&nbsp;{&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">6</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">txtList[</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">i</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">]&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%=textList.get(i)%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">;<BR></SPAN><SPAN style="COLOR: #008080">7</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">8</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">--&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">9</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV>这段JS就存在问题,未对特殊符号进行处理.有特殊符号的情况下有可能报JSERROR</DIV>
<DIV>&nbsp;</DIV>
<DIV>JAVASCRIPT中需要转义的有:</DIV>
<DIV>&nbsp;</DIV>
<DIV>
<TABLE cellSpacing=0 rules=all border=1>
<TBODY>
<TR vAlign=top>
<TH width="35%"><FONT face=Arial size=1>转义序列</FONT></TH>
<TH width="65%"><FONT face=Arial size=1>字符</FONT></TH></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\b</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>退格</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\f</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>走纸换页</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\n</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>换行</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\r</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>回车</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\t</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>横向跳格 (Ctrl-I)</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\'</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>单引号</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\"</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>双引号</FONT></TD></TR>
<TR vAlign=top>
<TD width="35%"><FONT face=Arial size=1>\\</FONT></TD>
<TD width="65%"><FONT face=Arial size=1>反斜杠</FONT></TD></TR></TBODY></TABLE><BR>此外,对/符号我觉得也有必要进行处理,因为象 --&gt;&lt;/script&gt; 这样的字符串也会使SCRIPT出错.</DIV>
<DIV>&nbsp;</DIV>
<DIV>下面提供一个比较实用java的方法,做这个特殊符号的处理:</DIV>
<DIV>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG id=Codehighlighter1_29_936_Open_Image onclick="this.style.display='none'; Codehighlighter1_29_936_Open_Text.style.display='none'; Codehighlighter1_29_936_Closed_Image.style.display='inline'; Codehighlighter1_29_936_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_29_936_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_29_936_Closed_Text.style.display='none'; Codehighlighter1_29_936_Open_Image.style.display='inline'; Codehighlighter1_29_936_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;JavaScriptUtils&nbsp;</SPAN><SPAN id=Codehighlighter1_29_936_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_29_936_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_84_903_Open_Image onclick="this.style.display='none'; Codehighlighter1_84_903_Open_Text.style.display='none'; Codehighlighter1_84_903_Closed_Image.style.display='inline'; Codehighlighter1_84_903_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_84_903_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_84_903_Closed_Text.style.display='none'; Codehighlighter1_84_903_Open_Image.style.display='inline'; Codehighlighter1_84_903_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;javaScriptEscape(String&nbsp;input)&nbsp;</SPAN><SPAN id=Codehighlighter1_84_903_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_84_903_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_107_128_Open_Image onclick="this.style.display='none'; Codehighlighter1_107_128_Open_Text.style.display='none'; Codehighlighter1_107_128_Closed_Image.style.display='inline'; Codehighlighter1_107_128_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_107_128_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_107_128_Closed_Text.style.display='none'; Codehighlighter1_107_128_Open_Image.style.display='inline'; Codehighlighter1_107_128_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(input&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_107_128_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_107_128_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;input;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;StringBuffer&nbsp;filtered&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;StringBuffer(input.length());<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">&nbsp;prevChar&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\u0000</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">&nbsp;c;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_272_413_Open_Image onclick="this.style.display='none'; Codehighlighter1_272_413_Open_Text.style.display='none'; Codehighlighter1_272_413_Closed_Image.style.display='inline'; Codehighlighter1_272_413_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_272_413_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_272_413_Closed_Text.style.display='none'; Codehighlighter1_272_413_Open_Image.style.display='inline'; Codehighlighter1_272_413_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;input.length();&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_272_413_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_272_413_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;c&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;input.charAt(i);<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_315_352_Open_Image onclick="this.style.display='none'; Codehighlighter1_315_352_Open_Text.style.display='none'; Codehighlighter1_315_352_Closed_Image.style.display='inline'; Codehighlighter1_315_352_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_315_352_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_315_352_Closed_Text.style.display='none'; Codehighlighter1_315_352_Open_Image.style.display='inline'; Codehighlighter1_315_352_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_315_352_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_315_352_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\\</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">);</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\</SPAN><SPAN style="COLOR: #000000">''</SPAN><SPAN style="COLOR: #000000">)&nbsp;{</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_440_478_Open_Image onclick="this.style.display='none'; Codehighlighter1_440_478_Open_Text.style.display='none'; Codehighlighter1_440_478_Closed_Image.style.display='inline'; Codehighlighter1_440_478_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_440_478_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_440_478_Closed_Text.style.display='none'; Codehighlighter1_440_478_Open_Image.style.display='inline'; Codehighlighter1_440_478_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\\</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_440_478_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_440_478_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_504_539_Open_Image onclick="this.style.display='none'; Codehighlighter1_504_539_Open_Text.style.display='none'; Codehighlighter1_504_539_Closed_Image.style.display='inline'; Codehighlighter1_504_539_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_504_539_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_504_539_Closed_Text.style.display='none'; Codehighlighter1_504_539_Open_Image.style.display='inline'; Codehighlighter1_504_539_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\t</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_504_539_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_504_539_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\t</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_565_636_Open_Image onclick="this.style.display='none'; Codehighlighter1_565_636_Open_Text.style.display='none'; Codehighlighter1_565_636_Closed_Image.style.display='inline'; Codehighlighter1_565_636_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_565_636_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_565_636_Closed_Text.style.display='none'; Codehighlighter1_565_636_Open_Image.style.display='inline'; Codehighlighter1_565_636_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\n</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_565_636_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_565_636_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_594_631_Open_Image onclick="this.style.display='none'; Codehighlighter1_594_631_Open_Text.style.display='none'; Codehighlighter1_594_631_Closed_Image.style.display='inline'; Codehighlighter1_594_631_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_594_631_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_594_631_Closed_Text.style.display='none'; Codehighlighter1_594_631_Open_Image.style.display='inline'; Codehighlighter1_594_631_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(prevChar&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\r</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_594_631_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_594_631_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_662_697_Open_Image onclick="this.style.display='none'; Codehighlighter1_662_697_Open_Text.style.display='none'; Codehighlighter1_662_697_Closed_Image.style.display='inline'; Codehighlighter1_662_697_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_662_697_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_662_697_Closed_Text.style.display='none'; Codehighlighter1_662_697_Open_Image.style.display='inline'; Codehighlighter1_662_697_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\r</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_662_697_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_662_697_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_720_766_Open_Image onclick="this.style.display='none'; Codehighlighter1_720_766_Open_Text.style.display='none'; Codehighlighter1_720_766_Closed_Image.style.display='inline'; Codehighlighter1_720_766_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_720_766_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_720_766_Closed_Text.style.display='none'; Codehighlighter1_720_766_Open_Image.style.display='inline'; Codehighlighter1_720_766_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\f</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_720_766_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_720_766_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">31</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\f</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">32</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_787_843_Open_Image onclick="this.style.display='none'; Codehighlighter1_787_843_Open_Text.style.display='none'; Codehighlighter1_787_843_Closed_Image.style.display='inline'; Codehighlighter1_787_843_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_787_843_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_787_843_Closed_Text.style.display='none'; Codehighlighter1_787_843_Open_Image.style.display='inline'; Codehighlighter1_787_843_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(c&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_787_843_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_787_843_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">33</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">34</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">35</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_853_882_Open_Image onclick="this.style.display='none'; Codehighlighter1_853_882_Open_Text.style.display='none'; Codehighlighter1_853_882_Closed_Image.style.display='inline'; Codehighlighter1_853_882_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_853_882_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_853_882_Closed_Text.style.display='none'; Codehighlighter1_853_882_Open_Image.style.display='inline'; Codehighlighter1_853_882_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_853_882_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_853_882_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">36</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;filtered.append(c);<BR></SPAN><SPAN style="COLOR: #008080">37</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">38</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;prevChar&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;c;<BR></SPAN><SPAN style="COLOR: #008080">39</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">40</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;filtered.toString();<BR></SPAN><SPAN style="COLOR: #008080">41</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">42</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}<BR></SPAN><SPAN style="COLOR: #008080">43</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR><BR>上面的例子应改为:</DIV>
<DIV>
<DIV>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;List&nbsp;textList&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;(List)request.getAttribute(</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">textList</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">);&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">2</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">3</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;!--</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">4</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">var</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;txtList&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">new</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;Array();<BR></SPAN><SPAN style="COLOR: #008080">5</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">for</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;(&nbsp;</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">int</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">0</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;textList.size()&nbsp;;&nbsp;i</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">++</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">)&nbsp;{&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">6</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">txtList[</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">i</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">]&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%=JavaScriptUtils.javaScriptEscape(textList.get(i))%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">;<BR></SPAN><SPAN style="COLOR: #008080">7</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">%&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">8</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">--&gt;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR></SPAN><SPAN style="COLOR: #008080">9</SPAN>&nbsp;<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV></DIV><img src ="http://www.blogjava.net/eckelcn/aggbug/20466.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eckelcn/" target="_blank">eckelcn</a> 2005-11-18 17:25 <a href="http://www.blogjava.net/eckelcn/archive/2005/11/18/20466.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正确使用window.open返回对象的opener</title><link>http://www.blogjava.net/eckelcn/archive/2005/11/18/20465.html</link><dc:creator>eckelcn</dc:creator><author>eckelcn</author><pubDate>Fri, 18 Nov 2005 09:23:00 GMT</pubDate><guid>http://www.blogjava.net/eckelcn/archive/2005/11/18/20465.html</guid><wfw:comment>http://www.blogjava.net/eckelcn/comments/20465.html</wfw:comment><comments>http://www.blogjava.net/eckelcn/archive/2005/11/18/20465.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eckelcn/comments/commentRss/20465.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eckelcn/services/trackbacks/20465.html</trackback:ping><description><![CDATA[<DIV align=left>众所周知JavaScript中: </DIV>
<DIV>var win = window.open(url,windowName,...); 的使用,</DIV>
<DIV>而win.opener则是指向父窗口的引用</DIV>
<DIV>&nbsp;</DIV>
<DIV>然而,有种情况却比较特别,</DIV>
<DIV>&nbsp;</DIV>
<DIV>假如有两个窗口window1和window2</DIV>
<DIV>按下列步骤执行:</DIV>
<DIV>var win = window.open(url,windowName,...);&nbsp; (window1)</DIV>
<DIV>&nbsp;</DIV>
<DIV>var win = window.open(url,windowName,...);&nbsp; (window2)</DIV>
<DIV>其中先后这两次打开的子窗口的windowName一样</DIV>
<DIV>&nbsp;</DIV>
<DIV>此时你会发现在window2中的win.opener却不是指向window2的,却是指向window1.</DIV>
<DIV>如果你想在子窗口关闭父窗口的话,就不正确了,因此可以修改上面的执行方法为:</DIV>
<DIV>
<DIV>var win = window.open(url,windowName,...);&nbsp; (window1)</DIV>
<DIV>win.opener = window;</DIV>
<DIV>&nbsp;</DIV>
<DIV>var win = window.open(url,windowName,...);&nbsp; (window2)</DIV>
<DIV>win.opener = window;</DIV>
<DIV>&nbsp;</DIV>
<DIV>只有这样修改才OK</DIV>
<DIV>&nbsp;</DIV></DIV>
<DIV>&nbsp;</DIV><img src ="http://www.blogjava.net/eckelcn/aggbug/20465.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eckelcn/" target="_blank">eckelcn</a> 2005-11-18 17:23 <a href="http://www.blogjava.net/eckelcn/archive/2005/11/18/20465.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>