欧文のまわりにスペースを入れる君

by clockmaker
文中の英単語と日本語の間にスペースを入れるツール。

英単語の混じった文章を読みやすくします。
♥3 | Line 76 | Modified 2010-11-18 18:23:00 | MIT License
play

ActionScript3 source code

/**
 * Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5nFH
 */

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark">
    <!-- =====================================================
         文中の英単語と日本語の間にスペースを入れるツール。
         英単語の混じった文章を読みやすくします。
         ===================================================== -->
    <fx:Script>
        <![CDATA[
            import mx.controls.*;

            private function doArrange():void
            {
                var str:String = orijinal.text;
                var out:String = "";
                var prev:Boolean = false;
                var prevIgnore:Boolean = false;

                for (var i:int = 0; i < str.length; i++)
                {
                    var index:int = str.charCodeAt(i);
                    //trace(index, str.charAt(i))

                    var isEnglishWord:Boolean = (index >= 14 && index <= 177)
                        || index == 174 //「®」
                        || index == 8482 //「™」
                        ; // 14「」〜177「±」

                    var ignore:Boolean = i <= 0
                        || index == 13 //「\n」
                        || index == 10 //「\r」
                        || index == 32 //「\n」
                        || index == 12289 //「、」
                        || index == 12290 //「。」
                        || index == 12300 //「
                        || index == 12301 // 」
                        || index == 12288 // 「 」    
                        ;

                    if (isEnglishWord != prev && !ignore && !prevIgnore)
                        out += " ";

                    out += str.charAt(i);

                    prev = isEnglishWord;
                    prevIgnore = ignore;
                }

                output.text = out;
            }

            private function copy():void
            {
                System.setClipboard(output.text);
                Alert.show("Copied Output Script")
            }
        ]]>
    </fx:Script>

    <s:Panel title="文中の英単語と日本語の間にスペースを入れるツール"
             width="100%"
             height="100%">
        <s:layout>
            <s:VerticalLayout horizontalAlign="center"
                              paddingBottom="10"
                              paddingLeft="10"
                              paddingRight="10"
                              paddingTop="10"
                              gap="10"/>
        </s:layout>
        <s:TextArea id="orijinal"
                    width="100%"
                    height="100%"
                    focusIn="orijinal.selectAll()"
                    fontFamily="Courier New"
                    text="Webアプリケーション開発のためのFlash Professional CS5&#xd;&#xd;インテリジェントなActionScript®コーディングツールを備え、他のAdobeツールとの強力な連携が可能な統合開発環境により、クロスプラットフォームのWebアプリケーションやコンテンツを効率的に開発できます。"/>
        <s:Button click="doArrange()"
                  label="Start"/>
        <s:TextArea id="output"
                    width="100%"
                    height="100%"
                    focusIn="output.selectAll()"
                    fontFamily="Courier New"/>
        <s:Button click="copy()"
                  label="Copy Clipboard"/>
    </s:Panel>
</s:Application>

Forked