<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>不敢流泪 &#187; Web</title>
	<atom:link href="http://www.boluor.com/tag/web/feed" rel="self" type="application/rss+xml" />
	<link>http://www.boluor.com</link>
	<description></description>
	<lastBuildDate>Fri, 07 Oct 2011 07:28:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>批量修改文章中的标签</title>
		<link>http://www.boluor.com/update-tags-of-posts-in-batch.html</link>
		<comments>http://www.boluor.com/update-tags-of-posts-in-batch.html#comments</comments>
		<pubDate>Sat, 22 Aug 2009 20:19:56 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=299</guid>
		<description><![CDATA[<p>　　实在受不了syntax highlighter的速度，所以暂时去找了个wp-syntax高亮插件来代替。问题来了，我之前使用时标签都是类似：［c］［/c］，［php］［/php］的，当时偷懒不想写完整的标签。但是wp-syntax只支持类似&#60;pre lang=”language” line=”1&#8243;&#62;&#60;/pre&#62;之类的标签。只好想法去修改了，但是手工修改的工作量太大，于是继续想懒办法。<br />
　　解决的方法肯定是正则表达式了。所以用php写了个，数据库就按照wp的结构来。下面是代码：<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&#60;?php</span>
	<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#34;localhost&#038;qu</span></pre></div></div><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>　　实在受不了syntax highlighter的速度，所以暂时去找了个wp-syntax高亮插件来代替。问题来了，我之前使用时标签都是类似：［c］［/c］，［php］［/php］的，当时偷懒不想写完整的标签。但是wp-syntax只支持类似&lt;pre lang=”language” line=”1&#8243;&gt;&lt;/pre&gt;之类的标签。只好想法去修改了，但是手工修改的工作量太大，于是继续想懒办法。<br />
　　解决的方法肯定是正则表达式了。所以用php写了个，数据库就按照wp的结构来。下面是代码：<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span> <span style="color: #339933;">,</span>  <span style="color: #0000ff;">&quot;mysqlname&quot;</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;passwd&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't connect to server&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//这句很关键，如果不设定，读取的全部是乱码，update后数据库中保存的也就成乱码了。</span>
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'UTF8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//修改所有文章.</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select ID ,post_content from wp_posts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span>MYSQL_ASSOC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$rst</span> <span style="color: #339933;">=</span> rp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;post_content&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ID&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sqlupdate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update wp_posts set post_content = '<span style="color: #006699; font-weight: bold;">$rst</span>' where ID = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlupdate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #666666; font-style: italic;">//sleep(10);这句话如果有的话，执行时间过长。超过了30s的最大执行时间。没找到怎么取消这个时间限制。</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ok&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面是只修改其中一篇文章时的代码.</span>
<span style="color: #666666; font-style: italic;">/*
	$result = mysql_query(&quot;select ID,post_content from wp_posts where ID=197&quot;);
	$row = mysql_fetch_row($result);
	$id = $row[0];	//ID
	$rst = rp($row[1]);//post_content
	$sqlupdate = &quot;update wp_posts set post_content = '$rst' where ID = $id&quot;;
	mysql_query($sqlupdate);
&nbsp;
	echo &quot;ok&quot;; 
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> rp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">&quot;/\[c\](.*?)\[\/c\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[cpp\](.*?)\[\/cpp\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[php\](.*?)\[\/php\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[css\](.*?)\[\/css\]/is&quot;</span><span style="color: #339933;">,</span>  
        <span style="color: #0000ff;">&quot;/\[html\](.*?)\[\/html\]/is&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$replace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>c<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>cpp<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>php<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>css<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>html<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span>  <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span><span style="color: #000088;">$replace</span><span style="color: #339933;">,</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>　　你看到的我现在的文章，就是用这个方法修改的。不过，遇到点小问题，有几篇竟然没有转换过去，而当我用修改单篇文章的方式修改时又可以，难道是因为我执行时间太短，还是mysql请求太频繁？<br />
　　早上4点20了，要睡了额。</p>
<p>　　<strong>随笔</strong>：很喜欢<a href="http://mindhacks.cn/">刘未鹏大师</a>的一幅画。<br />
<div id="attachment_300" class="wp-caption alignnone" style="width: 310px"><a href="http://www.boluor.com/wp-content/uploads/2009/08/paradoxoflearning-thumb.jpg"><img src="http://www.boluor.com/wp-content/uploads/2009/08/paradoxoflearning-thumb-300x182.jpg" alt="寻找什么和找到了什么" title="paradoxoflearning-thumb" width="300" height="182" class="size-medium wp-image-300" /></a><p class="wp-caption-text">寻找什么和找到了什么</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/update-tags-of-posts-in-batch.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>wordpress纠结笔记之评论表情</title>
		<link>http://www.boluor.com/note-about-wordpress-comment-smiles.html</link>
		<comments>http://www.boluor.com/note-about-wordpress-comment-smiles.html#comments</comments>
		<pubDate>Tue, 18 Aug 2009 09:17:30 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=278</guid>
		<description><![CDATA[<p>　　之前在life-studio的BLOG上看到一篇文章介绍<a href="http://wange.im/expression-without-plugins-in-wordpress.html">WordPress 非插件调用表情符</a>.按照其中的提示修改后，发现我还是用不了表情符号。而且很奇怪的是，他的代码中只有如何将显示的表情符号转换为相应的文字符号，没有代码处理将文字符号转换为图片。后来问了才知道，原来wordpress又有默认的处理，将一堆的表情符号转换为相应的图片，不用我们另写代码处理。</p>
<p>　　继续测试，发现显示出来还是文字符号。郁闷，决定自己写代码实现。</p>
<p>　　学了几天正则表达式后，我决定在评论提交到服务器后将这些文字符号替换成相应的图片标签。wordpress的评论提交到了根目录下的wp-comments-post.php中，&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>　　之前在life-studio的BLOG上看到一篇文章介绍<a href="http://wange.im/expression-without-plugins-in-wordpress.html">WordPress 非插件调用表情符</a>.按照其中的提示修改后，发现我还是用不了表情符号。而且很奇怪的是，他的代码中只有如何将显示的表情符号转换为相应的文字符号，没有代码处理将文字符号转换为图片。后来问了才知道，原来wordpress又有默认的处理，将一堆的表情符号转换为相应的图片，不用我们另写代码处理。</p>
<p>　　继续测试，发现显示出来还是文字符号。郁闷，决定自己写代码实现。</p>
<p>　　学了几天正则表达式后，我决定在评论提交到服务器后将这些文字符号替换成相应的图片标签。wordpress的评论提交到了根目录下的wp-comments-post.php中，所以在这里面改。找到</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000088;">$comment_content</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这行代码，在其下面添加几行：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000088;">$baseurl</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'siteurl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/:(.+):/U&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$replacement</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$baseurl</span>/wp-contents/images/smilies/icon_<span style="color: #000099; font-weight: bold;">\$</span>{1}.gif<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\$</span>{1}<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$comment_content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$replacement</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$comment_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>　　这样处理的话，用life-studio提供的方法，需要修改下他提供的那个文件。smiley.php。（需要下载的看文章末尾的附件）。就是将其中一些wp可以识别的略写的符号都变成了全称，比如:?:换成了:question:。<br />
<span id="more-278"></span><br />
　　继续测试，我只写了几个表情符号的标签，发现可以显示表情图片了。后来，Sandy发现如果评论中有中文就不能显示了，表情符号直接被过滤掉了。life-studio提醒说，可能是wp-comments-post.php不是utf-8格式的，于是再次将其保存为utf-8。这次我写的评论中有中文字符也没问题了。但是Sandy说他发还是没效果。</p>
<p>　　纠结。。。</p>
<p>　　Sandy说貌似只有你有特权吧，其他人都不能使用表情符号。我就去查，果真如此，wordpress又默认将一些标签给屏蔽了，除管理员以外都不能使用。于是，跑到wp-includes/kses.php中，找到$allowedtags，添加img标签：(a标签默认是允许的)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'img'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'src'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'alt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span>	<span style="color: #666666; font-style: italic;">//如果需要更多的属性，在这里添加就可以.</span></pre></td></tr></table></div>

<p>　　也就是说，wordpress是可以定制哪些标签被允许使用的。不过wordpress偷偷作的事情好多好多阿，让我忙乎了差不多一天。</p>
<p><strong>后记：</strong><br />
　　终于搞定了，很无聊，于是随手点击了一个链接进去，突然发现。。。在wordpress设置选项－>撰写栏下面，有个格式化选项，第一个选项就是：转换如 <img src='http://www.boluor.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  和 <img src='http://www.boluor.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' />  的文字表情符号为图像，我没有打勾。。。囧阿。之前以为是一些插件的原因，还一个个的停掉测试了。</p>
<p>　　这一番纠结，虽然学了些东西。不过，我更应该考虑的是Sandy的建议了，wordpress其实并不适合我，它不能让我学到一个博客的底层，太复杂太庞大，我学到的不过是wp的结构和一大堆它提供的函数库罢了，而对于我学html,php,mysql等等，并没有大的提升。其实一个小博客，一个不完善，不牛X的博客才更适合我用。</p>
<p><em>下载附件看这里：</em><br />
<a href='http://www.boluor.com/wp-content/uploads/2009/08/smiley.php.zip'>smiley.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/note-about-wordpress-comment-smiles.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>[临时]测试codeHilight</title>
		<link>http://www.boluor.com/temptesting-codehilight.html</link>
		<comments>http://www.boluor.com/temptesting-codehilight.html#comments</comments>
		<pubDate>Wed, 05 Aug 2009 17:11:29 +0000</pubDate>
		<dc:creator>Sandy</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=231</guid>
		<description><![CDATA[测试codeHilighter啦～]]></description>
			<content:encoded><![CDATA[<p><b>测试代码喽：</b><br />
<br/>codeHilighter by sandy_zc_1 。<br/>应boluor要求拿来替换掉该死的奇慢无比臃肿不堪的syntaxhighlighter。<br/><br />
<script language="javascript" src="http://www.boluor.com/wp-content/plugins/codeh1/codeh.js" type="text/javascript"></script><br />
<script language="javascript" src="http://www.boluor.com/wp-content/plugins/codeh1/chcommon.js" type="text/javascript"></script></p>
<link rel="stylesheet" href="http://www.boluor.com/wp-content/plugins/syntaxhighlighter-plus/syntaxhighlighter/styles/shCore.css" type="text/css" media="screen" />
<p><b>JS代码：</b></p>
<div id="cdh_js1" class="dCodeH1">
function Space(n)<br/>{<br/>&nbsp;&nbsp;&nbsp; if(n&gt;3)<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var str1=Space3(Math.floor(n/2));<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str1+=str1;<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(n%2!=0){ return str1+&quot; &quot;;}<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else { return str1;}<br/>&nbsp;&nbsp;&nbsp; }else if(n==3)<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot; &nbsp; &quot;;<br/>&nbsp;&nbsp;&nbsp; }else if(n==2)<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot; &nbsp;&quot;;<br/>&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp;&nbsp; return &quot; &quot;;<br/>}
</div>
<p><script language="javascript" >CodeHilight(document.getElementById("cdh_js1"),"JS");</script><br />
<span id="more-231"></span><br />
<b>C++代码：</b></p>
<div id="cdh_cpp1" class="dCodeH1">
// Vector implementation (out of line) -*- C++ -*-<br/><br/>// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.<br/>//<br/>// This file is part of the GNU ISO C++ Library. &nbsp;This library is free<br/>// software; you can redistribute it and/or modify it under the<br/>// terms of the GNU General Public License as published by the<br/>// Free Software Foundation; either version 2, or (at your option)<br/>// any later version.<br/><br/>// This library is distributed in the hope that it will be useful,<br/>// but WITHOUT ANY WARRANTY; without even the implied warranty of<br/>// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. &nbsp;See the<br/>// GNU General Public License for more details.<br/><br/>// You should have received a copy of the GNU General Public License along<br/>// with this library; see the file COPYING. &nbsp;If not, write to the Free<br/>// Software Foundation, 59 Temple Place &#8211; Suite 330, Boston, MA 02111-1307,<br/>// USA.<br/><br/>// As a special exception, you may use this file as part of a free software<br/>// library without restriction. &nbsp;Specifically, if other files instantiate<br/>// templates or use macros or inline functions from this file, or you compile<br/>// this file and link it with other files to produce an executable, this<br/>// file does not by itself cause the resulting executable to be covered by<br/>// the GNU General Public License. &nbsp;This exception does not however<br/>// invalidate any other reasons why the executable file might be covered by<br/>// the GNU General Public License.<br/><br/>/*<br/>&nbsp;*<br/>&nbsp;* Copyright (c) 1994<br/>&nbsp;* Hewlett-Packard Company<br/>&nbsp;*<br/>&nbsp;* Permission to use, copy, modify, distribute and sell this software<br/>&nbsp;* and its documentation for any purpose is hereby granted without fee,<br/>&nbsp;* provided that the above copyright notice appear in all copies and<br/>&nbsp;* that both that copyright notice and this permission notice appear<br/>&nbsp;* in supporting documentation. &nbsp;Hewlett-Packard Company makes no<br/>&nbsp;* representations about the suitability of this software for any<br/>&nbsp;* purpose. &nbsp;It is provided &quot;as is&quot; without express or implied warranty.<br/>&nbsp;*<br/>&nbsp;*<br/>&nbsp;* Copyright (c) 1996<br/>&nbsp;* Silicon Graphics Computer Systems, Inc.<br/>&nbsp;*<br/>&nbsp;* Permission to use, copy, modify, distribute and sell this software<br/>&nbsp;* and its documentation for any purpose is hereby granted without fee,<br/>&nbsp;* provided that the above copyright notice appear in all copies and<br/>&nbsp;* that both that copyright notice and this permission notice appear<br/>&nbsp;* in supporting documentation. &nbsp;Silicon Graphics makes no<br/>&nbsp;* representations about the suitability of this &nbsp;software for any<br/>&nbsp;* purpose. &nbsp;It is provided &quot;as is&quot; without express or implied warranty.<br/>&nbsp;*/<br/><br/>/** @file vector.tcc<br/>&nbsp;* &nbsp;This is an internal header file, included by other library headers.<br/>&nbsp;* &nbsp;You should not attempt to use it directly.<br/>&nbsp;*/<br/><br/>#ifndef _VECTOR_TCC<br/>#define _VECTOR_TCC 1<br/><br/>namespace _GLIBCXX_STD<br/>{<br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;reserve(size_type __n)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__n &gt; this-&gt;max_size())<br/>&nbsp;&nbsp;&nbsp; __throw_length_error(__N(&quot;vector::reserve&quot;));<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (this-&gt;capacity() &lt; __n)<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp; const size_type __old_size = size();<br/>&nbsp;&nbsp;&nbsp; &nbsp; pointer __tmp = _M_allocate_and_copy(__n,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; std::_Destroy(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; _M_deallocate(this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp;&nbsp; &nbsp; this-&gt;_M_impl._M_start = __tmp;<br/>&nbsp;&nbsp;&nbsp; &nbsp; this-&gt;_M_impl._M_finish = __tmp + __old_size;<br/>&nbsp;&nbsp;&nbsp; &nbsp; this-&gt;_M_impl._M_end_of_storage = this-&gt;_M_impl._M_start + __n;<br/>&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;typename vector&lt;_Tp,_Alloc&gt;::iterator<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;insert(iterator __position, const value_type&amp; __x)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;size_type __n = __position &#8211; begin();<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (this-&gt;_M_impl._M_finish != this-&gt;_M_impl._M_end_of_storage &amp;&amp; __position == end())<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::_Construct(this-&gt;_M_impl._M_finish, __x);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;++this-&gt;_M_impl._M_finish;<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_M_insert_aux(__position, __x);<br/>&nbsp;&nbsp; &nbsp; &nbsp;return begin() + __n;<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;typename vector&lt;_Tp,_Alloc&gt;::iterator<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;erase(iterator __position)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__position + 1 != end())<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::copy(__position + 1, end(), __position);<br/>&nbsp;&nbsp; &nbsp; &nbsp;&#8211;this-&gt;_M_impl._M_finish;<br/>&nbsp;&nbsp; &nbsp; &nbsp;std::_Destroy(this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp;return __position;<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;typename vector&lt;_Tp,_Alloc&gt;::iterator<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;erase(iterator __first, iterator __last)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;iterator __i(copy(__last, end(), __first));<br/>&nbsp;&nbsp; &nbsp; &nbsp;std::_Destroy(__i, end());<br/>&nbsp;&nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish = this-&gt;_M_impl._M_finish &#8211; (__last &#8211; __first);<br/>&nbsp;&nbsp; &nbsp; &nbsp;return __first;<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;&amp;<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;operator=(const vector&lt;_Tp,_Alloc&gt;&amp; __x)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (&amp;__x != this)<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const size_type __xlen = __x.size();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (__xlen &gt; capacity())<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), __x.end());<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_M_deallocate(this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_start = __tmp;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_end_of_storage = this-&gt;_M_impl._M_start + __xlen;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else if (size() &gt;= __xlen)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iterator __i(copy(__x.begin(), __x.end(), begin()));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(__i, end());<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::copy(__x.begin(), __x.begin() + size(), this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_copy(__x.begin() + size(), __x.end(), this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish = this-&gt;_M_impl._M_start + __xlen;<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;return *this;<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_fill_assign(size_t __n, const value_type&amp; __val)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__n &gt; capacity())<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;vector __tmp(__n, __val, get_allocator());<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;__tmp.swap(*this);<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;else if (__n &gt; size())<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::fill(begin(), end(), __val);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish<br/>&nbsp;&nbsp;&nbsp; &nbsp; = std::uninitialized_fill_n(this-&gt;_M_impl._M_finish, __n &#8211; size(), __val);<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;erase(fill_n(begin(), __n, __val), end());<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt; template&lt;typename _InputIterator&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_assign_aux(_InputIterator __first, _InputIterator __last, input_iterator_tag)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;iterator __cur(begin());<br/>&nbsp;&nbsp; &nbsp; &nbsp;for ( ; __first != __last &amp;&amp; __cur != end(); ++__cur, ++__first)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;*__cur = *__first;<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__first == __last)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;erase(__cur, end());<br/>&nbsp;&nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;insert(end(), __first, __last);<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt; template&lt;typename _ForwardIterator&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;forward_iterator_tag)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;size_type __len = std::distance(__first, __last);<br/><br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__len &gt; capacity())<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;pointer __tmp(_M_allocate_and_copy(__len, __first, __last));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_M_deallocate(this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_start = __tmp;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_end_of_storage = this-&gt;_M_impl._M_finish = this-&gt;_M_impl._M_start + __len;<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;else if (size() &gt;= __len)<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;iterator __new_finish(copy(__first, __last, this-&gt;_M_impl._M_start));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(__new_finish, end());<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish = __new_finish.base();<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_ForwardIterator __mid = __first;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::advance(__mid, size());<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::copy(__first, __mid, this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish = std::uninitialized_copy(__mid, __last, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_insert_aux(iterator __position, const _Tp&amp; __x)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (this-&gt;_M_impl._M_finish != this-&gt;_M_impl._M_end_of_storage)<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::_Construct(this-&gt;_M_impl._M_finish, *(this-&gt;_M_impl._M_finish &#8211; 1));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;++this-&gt;_M_impl._M_finish;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_Tp __x_copy = __x;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::copy_backward(__position,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;iterator(this-&gt;_M_impl._M_finish-2),<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;iterator(this-&gt;_M_impl._M_finish-1));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;*__position = __x_copy;<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const size_type __old_size = size();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const size_type __len = __old_size != 0 ? 2 * __old_size : 1;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;iterator __new_start(this-&gt;_M_allocate(__len));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;iterator __new_finish(__new_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;try<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_finish = std::uninitialized_copy(iterator(this-&gt;_M_impl._M_start),<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;__position,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;__new_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::_Construct(__new_finish.base(), __x);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;++__new_finish;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_finish = std::uninitialized_copy(__position,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;iterator(this-&gt;_M_impl._M_finish),<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;__new_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;catch(&#8230;)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(__new_start,__new_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_M_deallocate(__new_start.base(),__len);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__throw_exception_again;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(begin(), end());<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_M_deallocate(this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_start = __new_start.base();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish = __new_finish.base();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_end_of_storage = __new_start.base() + __len;<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_fill_insert(iterator __position, size_type __n, const value_type&amp; __x)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__n != 0)<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (size_type(this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_finish) &gt;= __n)<br/>&nbsp;&nbsp;&nbsp; &nbsp; {<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value_type __x_copy = __x;<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;const size_type __elems_after = end() &#8211; __position;<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;iterator __old_finish(this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;if (__elems_after &gt; __n)<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_copy(this-&gt;_M_impl._M_finish &#8211; __n,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish += __n;<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::copy_backward(__position, __old_finish &#8211; __n, __old_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::fill(__position, __position + __n, __x_copy);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_fill_n(this-&gt;_M_impl._M_finish,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;__n &#8211; __elems_after,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;__x_copy);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish += __n &#8211; __elems_after;<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_copy(__position, __old_finish, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish += __elems_after;<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::fill(__position, __old_finish, __x_copy);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp;&nbsp; &nbsp; }<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp;&nbsp; &nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; const size_type __old_size = size();<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; const size_type __len = __old_size + std::max(__old_size, __n);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; iterator __new_start(this-&gt;_M_allocate(__len));<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; iterator __new_finish(__new_start);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; try<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __new_finish = std::uninitialized_copy(begin(), __position,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_start);<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __new_finish = std::uninitialized_fill_n(__new_finish, __n, __x);<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __new_finish = std::uninitialized_copy(__position, end(),<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; catch(&#8230;)<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::_Destroy(__new_start,__new_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _M_deallocate(__new_start.base(),__len);<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __throw_exception_again;<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; std::_Destroy(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; _M_deallocate(this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_start = __new_start.base();<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_finish = __new_finish.base();<br/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_end_of_storage = __new_start.base() + __len;<br/>&nbsp;&nbsp;&nbsp; &nbsp; }<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt; template&lt;typename _InputIterator&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_range_insert(iterator __pos,<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_InputIterator __first, _InputIterator __last,<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;input_iterator_tag)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;for ( ; __first != __last; ++__first)<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;__pos = insert(__pos, *__first);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;++__pos;<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;template&lt;typename _Tp, typename _Alloc&gt; template&lt;typename _ForwardIterator&gt;<br/>&nbsp;&nbsp; &nbsp;void<br/>&nbsp;&nbsp; &nbsp;vector&lt;_Tp,_Alloc&gt;::<br/>&nbsp;&nbsp; &nbsp;_M_range_insert(iterator __position,_ForwardIterator __first,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; _ForwardIterator __last, forward_iterator_tag)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp;if (__first != __last)<br/>&nbsp;&nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;size_type __n = std::distance(__first, __last);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (size_type(this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_finish) &gt;= __n)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const size_type __elems_after = end() &#8211; __position;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iterator __old_finish(this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (__elems_after &gt; __n)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_copy(this-&gt;_M_impl._M_finish &#8211; __n,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_finish,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish += __n;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::copy_backward(__position, __old_finish &#8211; __n, __old_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::copy(__first, __last, __position);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ForwardIterator __mid = __first;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::advance(__mid, __elems_after);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_copy(__mid, __last, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish += __n &#8211; __elems_after;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::uninitialized_copy(__position, __old_finish, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish += __elems_after;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::copy(__first, __mid, __position);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const size_type __old_size = size();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const size_type __len = __old_size + std::max(__old_size, __n);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iterator __new_start(this-&gt;_M_allocate(__len));<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iterator __new_finish(__new_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_finish = std::uninitialized_copy(iterator(this-&gt;_M_impl._M_start),<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;__position, __new_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_finish = std::uninitialized_copy(__first, __last,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;__new_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__new_finish = std::uninitialized_copy(__position,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;iterator(this-&gt;_M_impl._M_finish),<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;__new_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch(&#8230;)<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(__new_start,__new_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_M_deallocate(__new_start.base(), __len);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__throw_exception_again;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::_Destroy(this-&gt;_M_impl._M_start, this-&gt;_M_impl._M_finish);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_M_deallocate(this-&gt;_M_impl._M_start,<br/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;_M_impl._M_end_of_storage &#8211; this-&gt;_M_impl._M_start);<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_start = __new_start.base();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_finish = __new_finish.base();<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this-&gt;_M_impl._M_end_of_storage = __new_start.base() + __len;<br/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp;}<br/>} // namespace std<br/><br/>#endif /* _VECTOR_TCC */<br/><br/>
</div>
<p><script language="javascript" >CodeHilight(document.getElementById("cdh_cpp1"),"CPP");</script><br />
<br/><br />
<br/></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:Courier new,verdana;"><span style="color: #993333;">int</span> a<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>↑该死的syntaxhighlighter，还得留个它的小尾巴（因为目前codehilight的css依附于它的css中。。）<br />
(boluor注：现在不需要了，我已经将syntaxhighlighter给禁掉了。在本篇文章中调用了css。)<br />
<br/><br />
<br/><br />
yeah，看来效果还不错。可惜因为还没做成插件，因此使用麻烦些，boluor先将就一下，之后可以将其做成wp插件。<br />
<br/><br />
ok，Sandy收工，boluor，该你上场了～～！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/temptesting-codehilight.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>textContent与innerText的不同</title>
		<link>http://www.boluor.com/differences-between-textcontent-and-einnertext.html</link>
		<comments>http://www.boluor.com/differences-between-textcontent-and-einnertext.html#comments</comments>
		<pubDate>Sat, 20 Jun 2009 16:20:04 +0000</pubDate>
		<dc:creator>Sandy</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=138</guid>
		<description><![CDATA[<p><strong>textContent与innerText的不同</strong></p>
<p><strong>by  Sandy_zc_1  :</strong>因为发现网络上很少有这方面的内容，因此就把自己私有blog上的这篇文章搬出来到Boluor的公开blog，方便其它人查阅。</p>
<p><strong>————————————————————————————————————————</strong></p>
<p>以下是正文<strong> </strong>↓↓↓<strong> </strong></p>
<p><strong>textContent与innerText的不同</strong></p>
<p>IE下有个innerText属性，FF下有个textContent属性。很多以前给IE写脚本的，在FF下找不到innerText属性，于是网上搜到的建议是用textContent来替代。反之给FF写脚本的也一样。</p>
<p>但是实际上，这里有个误解。网上很多文章说“F&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><strong>textContent与innerText的不同</strong></p>
<p><strong>by  Sandy_zc_1  :</strong>因为发现网络上很少有这方面的内容，因此就把自己私有blog上的这篇文章搬出来到Boluor的公开blog，方便其它人查阅。</p>
<p><strong>————————————————————————————————————————</strong></p>
<p>以下是正文<strong> </strong>↓↓↓<strong> </strong></p>
<p><strong>textContent与innerText的不同</strong></p>
<p>IE下有个innerText属性，FF下有个textContent属性。很多以前给IE写脚本的，在FF下找不到innerText属性，于是网上搜到的建议是用textContent来替代。反之给FF写脚本的也一样。</p>
<p>但是实际上，这里有个误解。网上很多文章说“FF下等效于innerText属性的属性是textContent”————但是事实上并非如此。innerText与textContent有几点很重要的不同，导致它们在一些情况下不能直接互换使用。</p>
<p>前些日子写了个代码高亮JS插件，在IE下工作完全正常，而在FF下就不对头。在IE下使用的是innerText属性，而在FF下使用的则是textContent属性。在进行字符串处理的时候二者的不同导致了完全不一样的结果。于是就专门写了点东西来测试二者的不同。</p>
<p>根据测试的结果表明：<br />
<strong>innerText：</strong>它的内容实际上就是你在浏览器看到的内容。它的值是经过浏览器解释过的结果：它将元素的innerHTML换码、解释，最终显示出来，然后去除各种格式信息留下的纯文本。它会把&lt;br/&gt;换成换行符，会将多个空格并成一个空格对待，而本来的换行符却并不会引起换行，IE会将其当作一个普通的单词边界（一般是空格）。再说的形象点，一个元素的innerText属性的值，和你将这个元素内容复制粘贴到记事本里的内容一致。<span id="more-138"></span></p>
<p><strong>textContent：</strong>它的内容则是innerHTML去除所有标签后的内容（我怀疑这个是从XMLDOM中照搬过来的属性，特性完全一致）。它会将innerHTML中的转义字符（&amp;lt;、&amp;nbsp;什么的）进行换码，但是不对任何html标签进行解释，而是直接剔除它们。它也不会对innerHTML中的文本按照HTML的方式进行格式转换，比如多个空格还会原原本本地保留，不会合并为一个空格，换行符仍然存在（相反&lt;br/&gt;却不会导致换行）。</p>
<p><span style="color: navy;">更加简练的总结：IE中的innerText是需要对innerHTML的值进行：<br />
1、HTML转义（等同于XML转义，对&amp;lt;、&amp;amp;等转义字符进行处理）；<br />
2、经过HTML解释和CSS样式解释；<br />
3、之后又剔除格式信息<br />
之后留下的纯文本。<br />
而FF中的textContent没有2、3步，在经过了HTML转义之后直接剔除所有html标签后得到的纯文本。</span></p>
<p>一个例子：</p>
<blockquote><p>&lt;div id=”T1&#8243;&gt;<br />
ABCD<br />
EFG   HIJ&lt;br/&gt;KLM &amp;nbsp;N<br />
OPQ&lt;div&gt;RS&lt;/div&gt;T<br />
T<br />
&lt;div&gt;</p></blockquote>
<p>这个id为T1的div，<br />
在<span style="color: blue;">IE中的innerText属性</span>的值为：</p>
<blockquote><p>ABCD EFG HIJ<br />
KLM  N OPQ<br />
RS<br />
T T</p></blockquote>
<p>而<span style="color: blue;">在FF中的textContent的属性</span>的值为：</p>
<blockquote>
<div><span style="color: teal;"><em>(这里有个换行)</em></span><br />
ABCD<br />
EFG   HIJKLM  N<br />
OPQRST<br />
T</div>
</blockquote>
<div>注意那个div中还嵌套了个div，而这个更能反映IE的innerText和FF的textContent各自的处理方式的不同：<br />
div是块（block）元素，默认会独占一行，因此，在IE中的innerText反映为上述div中的RS独占一行，而FF的textContent完全不理会HTML格式，因此其textContent中的RS是和其它字符连在一起的，不会独占一行。</p>
<p>.</p>
<p>如果想更进一步，看看这个有趣的结果：<br />
假如给里面那个div加一个style=”float:left;”，那么这个div就会由块元素变化为行元素，不再独占一行，因此IE的innerText属性中RS便不再独占一行，而与其它字符连在一起，而在FF中由于textContent不理会标签更不会理会CSS，因此它的textContent属性的值不会有任何变化。</p>
<p>.</p>
<p>这么看来，很多网上说的“让FF支持innerText属性”云云，其实都是多多少少有问题的。要实现IE的innerText，远没有想象中的那么简单，你若要使用JavaScript让FF拥有和innerText完全一样的效果，得自己把html标签属性全部parse一遍，解释它们，甚至还需要去解释css……<br />
（不过根据原理，貌似通过剪贴板的复制和取回操作可以在FF下模拟innerText效果（这个未测试），但是1有副作用，2FF下的剪贴板操作也很麻烦。）</p>
<p>不过还好，大多数时候我们并不需要那么精确，使用innerHTML做点简单的处理即可达到比较接近的效果了。</p></div>
<p><em>注：以上代码均在IE6和FF3下完成测试。</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/differences-between-textcontent-and-einnertext.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

