<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[TNF : Tatter Network Foundation forum - replaceAll 버그(무한루프)]]></title>
		<link>http://forum.tattersite.com/ko/viewtopic.php?id=181</link>
		<description><![CDATA[replaceAll 버그(무한루프) 의 최근 RSS 글들.]]></description>
		<lastBuildDate>Mon, 24 Apr 2006 16:29:03 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=988#p988</link>
			<description><![CDATA[<div class="quotebox"><cite>crizin 작성:</cite><blockquote><div class="codebox"><pre><code>var source = &quot;a1\r\na2\r\na3\r\n&quot;;
alert(source.replace(new RegExp(&quot;^a&quot;, &quot;gm&quot;), &quot;_&quot;));</code></pre></div><p>이런 경우라면 m을 써주는 쪽이 의도에 가깝게 매치가 되는 것 같아요..</p><p>&#039;원본 문자열이 멀티라인이다&#039; 라고 선언해준다는 것 같습니다</p><p>음.. 근데 replaceAll 함수의 경우에는 굳이 없어도 상관 없겠군요;; (일단 넣어놓고 곰곰히 생각을..)</p></blockquote></div><p>아.. ^, $같은 경우는 생각도 못했었네요.;;</p>]]></description>
			<author><![CDATA[null@example.com (Peris)]]></author>
			<pubDate>Mon, 24 Apr 2006 16:29:03 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=988#p988</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=987#p987</link>
			<description><![CDATA[<div class="quotebox"><cite>Peris 작성:</cite><blockquote><p>근데 몰라서 질문드리는 겁니다만;<br />m옵션이 구체적으로 하는 일이 뭔가요?<br />저같은 경우 g옵션만으로도 언제나 원하는 결과를 얻어서 m은 사용을 안하거든요.;;</p></blockquote></div><div class="codebox"><pre><code>var source = &quot;a1\r\na2\r\na3\r\n&quot;;
alert(source.replace(new RegExp(&quot;^a&quot;, &quot;gm&quot;), &quot;_&quot;));</code></pre></div><p>이런 경우라면 m을 써주는 쪽이 의도에 가깝게 매치가 되는 것 같아요..</p><p>&#039;원본 문자열이 멀티라인이다&#039; 라고 선언해준다는 것 같습니다</p><p>음.. 근데 replaceAll 함수의 경우에는 굳이 없어도 상관 없겠군요;; (일단 넣어놓고 곰곰히 생각을..)</p>]]></description>
			<author><![CDATA[null@example.com (crizin)]]></author>
			<pubDate>Mon, 24 Apr 2006 15:51:37 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=987#p987</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=986#p986</link>
			<description><![CDATA[<div class="quotebox"><cite>crizin 작성:</cite><blockquote><p>그렇게 하면 간단하군요! <img src="http://forum.tattersite.com/ko/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>그리고 두번째 정규식에서 case insensitive 옵션은 빼고 multi line 옵션을 넣어서</p><div class="codebox"><pre><code>if(!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(source, target) {
        source = source.replace(new RegExp(&quot;(\\W)&quot;, &quot;g&quot;), &quot;\\$1&quot;);
        return this.replace(new RegExp(source, &quot;gm&quot;), target);
    }
}</code></pre></div><p>최종적으로 이렇게 했으면 합니다</p><p>코멘트 주세요~</p></blockquote></div><p>네. 그렇게 하는게 맞을거 같네요. <img src="http://forum.tattersite.com/ko/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>근데 몰라서 질문드리는 겁니다만;<br />m옵션이 구체적으로 하는 일이 뭔가요?<br />저같은 경우 g옵션만으로도 언제나 원하는 결과를 얻어서 m은 사용을 안하거든요.;;</p>]]></description>
			<author><![CDATA[null@example.com (Peris)]]></author>
			<pubDate>Mon, 24 Apr 2006 13:54:41 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=986#p986</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=985#p985</link>
			<description><![CDATA[<div class="quotebox"><cite>crizin 작성:</cite><blockquote><p>그렇게 하면 간단하군요! <img src="http://forum.tattersite.com/ko/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>그리고 두번째 정규식에서 case insensitive 옵션은 빼고 multi line 옵션을 넣어서</p><div class="codebox"><pre><code>if(!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(source, target) {
        source = source.replace(new RegExp(&quot;(\\W)&quot;, &quot;g&quot;), &quot;\\$1&quot;);
        return this.replace(new RegExp(source, &quot;gm&quot;), target);
    }
}</code></pre></div><p>최종적으로 이렇게 했으면 합니다</p><p>코멘트 주세요~</p></blockquote></div><p>쓸데없는 말입니다만....이러한 thread 를 가만히 보고 있으면 과연 집단의 지혜는 정말 대단하구나...라는 생각을 하게 됩니다. <img src="http://forum.tattersite.com/ko/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[null@example.com (chester)]]></author>
			<pubDate>Mon, 24 Apr 2006 13:51:33 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=985#p985</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=984#p984</link>
			<description><![CDATA[<p>그렇게 하면 간단하군요! <img src="http://forum.tattersite.com/ko/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>그리고 두번째 정규식에서 case insensitive 옵션은 빼고 multi line 옵션을 넣어서</p><div class="codebox"><pre><code>if(!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(source, target) {
        source = source.replace(new RegExp(&quot;(\\W)&quot;, &quot;g&quot;), &quot;\\$1&quot;);
        return this.replace(new RegExp(source, &quot;gm&quot;), target);
    }
}</code></pre></div><p>최종적으로 이렇게 했으면 합니다</p><p>코멘트 주세요~</p>]]></description>
			<author><![CDATA[null@example.com (crizin)]]></author>
			<pubDate>Mon, 24 Apr 2006 13:35:29 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=984#p984</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=974#p974</link>
			<description><![CDATA[<p>specialChars 를 등록하는 방법은 아래와 같이하시면 됩니다.</p><p>php의 경우 non-word 문자에 대해서 그 문자 자체를 사용하기 위해서 \를 붙여주는 것이 항상 안전하다고 매뉴얼에 적혀 있습니다. <img src="http://forum.tattersite.com/ko/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />(js에서도 통용되는 말인지는 잘 모르겠지만..;; )</p><div class="codebox"><pre><code>String.prototype.replaceAll = function(source, target) {
    source = source.replace(/(\W)/g, &quot;\\$1&quot;);
    return this.replace(new RegExp(source, &quot;gi&quot;), target);
}</code></pre></div><p>일단 이렇게 커밋해두겠습니다.</p>]]></description>
			<author><![CDATA[null@example.com (Peris)]]></author>
			<pubDate>Mon, 24 Apr 2006 10:06:17 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=974#p974</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=973#p973</link>
			<description><![CDATA[<div class="quotebox"><cite>gendoh 작성:</cite><blockquote><p>잠시 의문이.. JavaScript에서 Replace 함수를 찬찬히 생각해 보면 당연히 StartIndex를 받아야 할 것 같은데 왜 없을가요? --?<br />첫번째것만 처리해 줄꺼면 당연히 한방짜리나 시작위치 정해줄 수 있어야 하는거 아니겠음? (서울1945버젼)</p></blockquote></div><p>정규표현식에서 index를 받아서 처리하는게 더 이상할 거 같네요.;;</p>]]></description>
			<author><![CDATA[null@example.com (Peris)]]></author>
			<pubDate>Mon, 24 Apr 2006 09:59:57 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=973#p973</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=971#p971</link>
			<description><![CDATA[<p>음.. 제가 잘못 이해하고 있는건가요?</p><p>str=&quot;a|b&quot;;str=str.replaceAll(&quot;|&quot;, &quot;:&quot;);</p><p>이런 경우 str=str.replaceAll(&quot;\\|&quot;, &quot;:&quot;); 이라고 쓰겠죠.</p><br /><p>뭐 사실 저라면 replaceAll을 따로 만들지 않고 str=str.replace(/\|/gi, &quot;:&quot;); 이렇게 사용하고 말거 같네요.;;</p>]]></description>
			<author><![CDATA[null@example.com (Peris)]]></author>
			<pubDate>Mon, 24 Apr 2006 09:56:20 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=971#p971</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=957#p957</link>
			<description><![CDATA[<p>잠시 의문이.. JavaScript에서 Replace 함수를 찬찬히 생각해 보면 당연히 StartIndex를 받아야 할 것 같은데 왜 없을가요? --?<br />첫번째것만 처리해 줄꺼면 당연히 한방짜리나 시작위치 정해줄 수 있어야 하는거 아니겠음? (서울1945버젼)</p>]]></description>
			<author><![CDATA[null@example.com (gendoh)]]></author>
			<pubDate>Mon, 24 Apr 2006 06:51:02 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=957#p957</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=955#p955</link>
			<description><![CDATA[<p>여러 책이나 글 등에서 regular expression이 느리다고 되도록 쓰지 말라고 하나,<br />script language에서는 직접 manipulate하는 것보다 re가 더 빠릅니다.<br />re로 구현하는 것에 한 표!</p>]]></description>
			<author><![CDATA[null@example.com (PAPACHA)]]></author>
			<pubDate>Mon, 24 Apr 2006 06:45:06 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=955#p955</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=951#p951</link>
			<description><![CDATA[<div class="codebox"><pre><code>    if (source != target) {
        var startIndex = 0;
        var curIndex = 0;
        var sb = &quot;&quot;;
        while ((curIndex = buffer.indexOf(source, startIndex)) != -1) {
            sb += buffer.substr(startIndex, curIndex - startIndex);
            sb += target;
            startIndex = curIndex + source.length;
        }
        
        sb += buffer.substr(startIndex, buffer.length - startIndex);
        
        buffer = sb;
    }</code></pre></div><p>저의 첫 자바스크립트 코드입니다. -0- 적당히 고쳐서... 느리긴 하겠지만 그래도 심각하게는???</p>]]></description>
			<author><![CDATA[null@example.com (gendoh)]]></author>
			<pubDate>Mon, 24 Apr 2006 06:24:34 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=951#p951</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=944#p944</link>
			<description><![CDATA[<p>indexOf만 가지고 해결하는 방법은 잘 모르겠네요.. 무한루프는 막아질 수 있으나 &quot;a&amp;b&amp;c&quot;.replaceAll(&quot;&amp;&quot;, &quot;&amp;&quot;) 하면 a&amp;amp;b&amp;c 이렇게 바뀌지 않을까요?</p><p>아무튼 스트링 노가다를 통한 방법은 아래처럼 가능할 것 같습니다</p><div class="codebox"><pre><code>var StringBuffer = function()
{ this.buffer = new Array(); }

StringBuffer.prototype.append=function(str)
{ this.buffer[this.buffer.length] = str; }

StringBuffer.prototype.toString = function()
{ return this.buffer.join(&quot;&quot;); }

if(!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(source, target) {
        if(source.length == 0)
            return this;
        var sb = new StringBuffer();
        var clone = this;
        var position = clone.indexOf(source);
        while(position != -1) {
            sb.append(clone.substring(0, position));
            sb.append(target);
            clone = clone.substring(position + source.length, clone.length);
            position = clone.indexOf(source);
        }
        sb.append(clone);
        return sb.toString();
    }
}</code></pre></div><p>단점이라면 겁나게 느리다는 것;</p><p>Peris님 코드처럼 정규식을 이용할 경우에는 source 문자열에서 정규식 표현부분을 다 제거해줘야 합니다</p><div class="codebox"><pre><code>if(!String.prototype.replaceAllReg) {
    String.prototype.replaceAllReg = function(source, target) {
        var specialChars = &quot;(\\\\|\\||\\.|\\*|\\+|\\?|\\{|\\}|\\[|\\]|\\(|\\)|\\^|\\$)&quot;;
        source = source.replace(new RegExp(specialChars, &quot;g&quot;), &quot;\\$1&quot;);
        return this.replace(new RegExp(source, &quot;gm&quot;), target);
    }
}</code></pre></div><p>이렇게 하면 대략 50배정도 빠르긴 한데 모든 경우를 체크해서 specialChars를 꼼꼼히 만들어줘야 합니다. 안그러면 시한폭탄!</p><p>의견 주세요..;</p>]]></description>
			<author><![CDATA[null@example.com (crizin)]]></author>
			<pubDate>Mon, 24 Apr 2006 05:11:30 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=944#p944</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=938#p938</link>
			<description><![CDATA[<p>indexOf에 startIndex를 주면 될듯. 변경된 부분 다음을 index로 넘겨주는 로직이 추가되면 될듯 하군요.</p>]]></description>
			<author><![CDATA[null@example.com (gendoh)]]></author>
			<pubDate>Mon, 24 Apr 2006 03:54:59 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=938#p938</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=936#p936</link>
			<description><![CDATA[<p>근데 replaceAll 함수의 용도가 source 문자열에 정규식이 들어와도 영향받지 않고 말그대로 replaceAll 하는거라 수정하신 코드는 예외적인 경우가 발생할 수 있을 것 같습니다. (str=&quot;a|b&quot;;str=str.replaceAll(&quot;|&quot;, &quot;:&quot;); 같은 경우..)<br />으음.. 문자열 노가다를 최소화 하면서 replaceAll이 가능한 방법을 찾아봐야 될 것 같군요</p>]]></description>
			<author><![CDATA[null@example.com (crizin)]]></author>
			<pubDate>Mon, 24 Apr 2006 03:35:55 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=936#p936</guid>
		</item>
		<item>
			<title><![CDATA[replaceAll 버그(무한루프)]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=916#p916</link>
			<description><![CDATA[<p>1.0.4 이후 개발버전(원본, 실험본 둘 다)에서 script/common.js 파일 내에 추가된 replaceAll 함수 문제입니다.<br />기존의 방식은 replaceAll(&quot;&amp;&quot;, &quot;&amp;&quot;) 같은 경우 무한루프에 빠지게 됩니다.<br />(script/generaltag.js 파일 내에 존재함)</p><p>태그 내에 &quot;te&quot;를 입력하면 무한루프에 빠지길래 원인을 찾다가 발견하게 되었네요.<br />(Terms &amp; Vocabulary 라는 태그에서 무한 루프에 빠지는 듯..)</p><div class="codebox"><pre><code>if(!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(source, target) {
        var buffer = this;
        if(source != target)
            while(buffer.indexOf(source) != -1)
                buffer = buffer.replace(source, target);
        return buffer;
    }
}</code></pre></div><p>위를 아래와 같이 수정해서 실험본에 커밋하겠습니다.</p><div class="codebox"><pre><code>if(!String.prototype.replaceAll) {
    String.prototype.replaceAll = function(source, target) {
        return this.replace(new RegExp(source, &quot;gi&quot;), target);
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Peris)]]></author>
			<pubDate>Sun, 23 Apr 2006 10:28:17 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=916#p916</guid>
		</item>
	</channel>
</rss>
