<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[TNF : Tatter Network Foundation forum - UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
	<link rel="self" href="http://forum.tattersite.com/ko/extern.php?action=feed&amp;tid=7924&amp;type=atom"/>
	<updated>2010-01-21T06:37:30Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.tattersite.com/ko/viewtopic.php?id=7924</id>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=37744#p37744"/>
			<content type="html"><![CDATA[<p>이거 모 프로젝트 코드에 반영했구요, 이제 1.8에도 옮겨서 적용하도록 하겠습니다^^<br />(PHP 함수로 가능한 부분은 그냥 그거 쓰도록 짰습니다~)</p>]]></content>
			<author>
				<name><![CDATA[inureyes]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=2</uri>
			</author>
			<updated>2010-01-21T06:37:30Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=37744#p37744</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=37577#p37577"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>inureyes 작성:</cite><blockquote><p>PHP 내부 명령을 쓰도록 분기를 해 볼까 생각중입니다. 한 번 만들어보고 퍼포먼스를 재어 보아야겠네요^^</p></blockquote></div><p>아니, 그런 경우에는 당연히 PHP built-in function을 사용하셔야죠. C와 PHP의 속도 차이란.......</p>]]></content>
			<author>
				<name><![CDATA[Cyrus Hackford]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=3468</uri>
			</author>
			<updated>2010-01-10T02:49:56Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=37577#p37577</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=37561#p37561"/>
			<content type="html"><![CDATA[<p>옙 1.8.2에 반영해 보도록 하겠습니다.</p><p>덧) 사실 1.8부터는 PHP 5 이상의 조건이 명시되어 있기 때문에, 유니코드를 제대로 지원하는 서버에서는 여부를 판단하여 PHP 내부 명령을 쓰도록 분기를 해 볼까 생각중입니다. 한 번 만들어보고 퍼포먼스를 재어 보아야겠네요^^</p>]]></content>
			<author>
				<name><![CDATA[inureyes]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=2</uri>
			</author>
			<updated>2010-01-08T02:28:04Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=37561#p37561</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=37518#p37518"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>inureyes 작성:</cite><blockquote><p>코드를 보고 있습니다. 질문이 하나 있습니다. 이 방식으로 하면 한글/영문이 섞여 있을때 문제가 되지 않나요?</p></blockquote></div><p>구시대의 유물인 이 스레드를 다시 발굴해서 죄송합니다.</p><p>UTF-8의 장점은 바이트 구별이 확실해서 섞이지 않는다는 것이죠.<br />255번째 바이트가 헤더 바이트인지 바디 바이트인지 구분해서 자릅니다. 255번째가 헤더 바이트라면 바로 앞에서 자르면 될 것이고, 바디 바이트라면 해당 바디 바이트가 문자의 끝인지 아닌지를 판단하여 다시금 그에 걸맞는 행동을 취합니다.</p><p>결과적으로, 맨 처음부터 문자 수를 세 가며 자르는 것 보다 더 빠르지요.</p>]]></content>
			<author>
				<name><![CDATA[Cyrus Hackford]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=3468</uri>
			</author>
			<updated>2010-01-05T13:33:44Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=37518#p37518</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=34659#p34659"/>
			<content type="html"><![CDATA[<p>코드를 보고 있습니다. 질문이 하나 있습니다. 이 방식으로 하면 한글/영문이 섞여 있을때 문제가 되지 않나요?</p>]]></content>
			<author>
				<name><![CDATA[inureyes]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=2</uri>
			</author>
			<updated>2009-04-17T05:27:40Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=34659#p34659</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=34073#p34073"/>
			<content type="html"><![CDATA[<div class="codebox"><pre><code>$siclLengthInt-$siclLoopInt</code></pre></div><p>이 부분 말씀이신가요? 그럼 for에서 조건을 true 대신 $siclLengthInt&gt;=$siclLoopInt로 수정해야겠군요.</p><div class="codebox"><pre><code>// FROM
for($siclLoopInt=2;true;$siclLoopInt++) { // Seeking for head byte.
    if((ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;6)!==2)
        break;
}

// TO
for($siclLoopInt=2;$siclLengthInt&gt;=$siclLoopInt;$siclLoopInt++) { // Seeking for head byte.
    if((ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;6)!==2)
        break;
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Cyrus Hackford]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=3468</uri>
			</author>
			<updated>2009-03-06T15:07:10Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=34073#p34073</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=34063#p34063"/>
			<content type="html"><![CDATA[<p>forloop의 언더플로우 문제 빼고는 문제빼고는 괜찮아 보이는군요.</p>]]></content>
			<author>
				<name><![CDATA[gendoh]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=17</uri>
			</author>
			<updated>2009-03-06T07:39:48Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=34063#p34063</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=34047#p34047"/>
			<content type="html"><![CDATA[<p>잠깐만요!</p><p>여기 새 코드가 있습니다!</p><p>if가 몇 개 줄어서 더 간단한 버전입니다. 굳이 if를 더 달 필요가 없더군요.</p><div class="codebox"><pre><code>public static function Slice($siclTextStr,$siclLengthInt=255) {
    if(strlen($siclTextStr)&lt;=$siclLengthInt)
        return $siclTextStr;
    
    $siclVerifyInt=ord($siclTextStr[$siclLengthInt-1])&gt;&gt;6;
    if(($siclVerifyInt&gt;&gt;1)===0) // 1byte
        $siclLocationSubtInt=0;
    elseif($siclVerifyInt===3) // Head byte of multi-bytes characters.
        $siclLocationSubtInt=1;
    elseif($siclVerifyInt===2) { // Middle of multi-bytes character.
        for($siclLoopInt=2;true;$siclLoopInt++) { // Seeking for head byte.
            if((ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;6)!==2)
                break;
        }
        switch(ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;4) { // Identify the length of current character.
            case 12:
            case 13:
                $siclVerifiedLengthInt=2;
                break;
            case 14:
                $siclVerifiedLengthInt=3;
                break;
            case 15:
                $siclVerifiedLengthInt=4;
                break;
        }
        if($siclLoopInt===$siclVerifiedLengthInt) // The byte we&#039;re verifying is the last byte of the character.
            $siclLocationSubtInt=0;
        else
            $siclLocationSubtInt=$siclLoopInt;
        unset($siclLoopInt,$siclVerifiedLengthInt);
    }
    $siclSlicedStr=substr($siclTextStr,0,$siclLengthInt-$siclLocationSubtInt);
    unset($siclTextStr,$siclLengthInt,$siclLocationSubtInt);
    
    return $siclSlicedStr;
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Cyrus Hackford]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=3468</uri>
			</author>
			<updated>2009-03-05T14:41:04Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=34047#p34047</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RSS 답글: UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=34035#p34035"/>
			<content type="html"><![CDATA[<p>오오 감사합니다^^ 코드 리뷰후 적용하도록 하겠습니다!</p>]]></content>
			<author>
				<name><![CDATA[inureyes]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=2</uri>
			</author>
			<updated>2009-03-05T02:27:44Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=34035#p34035</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[UTF8::lessenAsByte 메소드의 더 빠른 버전을 소개합니다.]]></title>
			<link rel="alternate" href="http://forum.tattersite.com/ko/viewtopic.php?pid=34020#p34020"/>
			<content type="html"><![CDATA[<p>반갑습니다, Cyrus입니다(구 Ikaris C. Faust).</p><p>현재 Textcube에서 사용하는 UTF8 클래스의 lessenAsByte의 더 빠른 버전을 소개합니다.<br />개인적으로 쓰려고 만든 것이지만, 그냥 이곳에 한 번 던져 봅니다.</p><p>이 메소드와 lessenAsByte 메소드의 속도 비교는 <a href="http://cyrush.com/4db/library/test.php">http://cyrush.com/4db/library/test.php</a> 에서 보실 수 있습니다.</p><div class="codebox"><pre><code>public static function Slice($siclTextStr,$siclLengthInt=255) {
    if(strlen($siclTextStr)&lt;=$siclLengthInt)
        return $siclTextStr;
    
    $siclVerifyInt=ord($siclTextStr[$siclLengthInt-1])&gt;&gt;6;
    if(($siclVerifyInt&gt;&gt;1)===0) // 1byte
        $siclLocationSubtInt=0;
    elseif($siclVerifyInt===3) // Head byte of multi-bytes characters.
        $siclLocationSubtInt=1;
    elseif($siclVerifyInt===2) { // Middle of multi-bytes character.
        if(isset($siclTextStr[$siclLengthInt])===false) { // End of the string
            for($siclLoopInt=2;true;$siclLoopInt++) { // Seeking for head byte.
                if((ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;6)===2)
                    continue;
                else
                    break;
            }
            $siclVerifyLengthInt=ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;4;
            if($siclVerifyLengthInt&gt;=0 &amp;&amp; $siclVerifyLengthInt&lt;=7) // Broken byte.
                $siclLocationSubtInt=$siclLoopInt-1;
            else {
                switch($siclVerifyLengthInt) { // Identify the length of current character.
                    case 12:
                    case 13:
                        $siclVerifiedLengthInt=2;
                        break;
                    case 14:
                        $siclVerifiedLengthInt=3;
                        break;
                    case 15:
                        $siclVerifiedLengthInt=4;
                        break;
                }
                if($siclLoopInt!==$siclVerifiedLengthInt) // We&#039;re in the middle of the character.
                    $siclLocationSubtInt=$siclLoopInt;
                else // The byte we&#039;re verifying is the last byte of the character.
                    $siclLocationSubtInt=0;
            }
            unset($siclLoopInt,$siclVerifiedLengthInt);
        } elseif((ord($siclTextStr[$siclLengthInt])&gt;&gt;6)!==2) // Last byte of the character.
            $siclLocationSubtInt=0;
        else {
            for($siclLoopInt=2;true;$siclLoopInt++) { // Seeking for head byte.
                if((ord($siclTextStr[$siclLengthInt-$siclLoopInt])&gt;&gt;6)===2)
                    continue;
                else
                    break;
            }
            $siclLocationSubtInt=$siclLoopInt;
            unset($siclLoopInt);
        }
    }
    $siclSlicedStr=substr($siclTextStr,0,$siclLengthInt-$siclLocationSubtInt);
    unset($siclTextStr,$siclLengthInt,$siclLocationSubtInt);
    
    return $siclSlicedStr;
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Cyrus Hackford]]></name>
				<uri>http://forum.tattersite.com/ko/profile.php?id=3468</uri>
			</author>
			<updated>2009-03-03T16:07:39Z</updated>
			<id>http://forum.tattersite.com/ko/viewtopic.php?pid=34020#p34020</id>
		</entry>
</feed>
