「テキスト変換」の版間の差分

Ks (トーク | 投稿記録)
編集の要約なし
MSY-07 (トーク | 投稿記録)
<source>タグを<syntaxhighlight>タグに置き換える
22行目: 22行目:
# セパレータの挿入<br><code>f[f.length] = "--";</code><br>でセパレータを挿入できます(- の数は任意).
# セパレータの挿入<br><code>f[f.length] = "--";</code><br>でセパレータを挿入できます(- の数は任意).
# グルーピング<br>下のコードで,グルーピングができます.
# グルーピング<br>下のコードで,グルーピングができます.
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "グループ名", function(f){    // <= グルーピング開始
f[f.length] = [ "グループ名", function(f){    // <= グルーピング開始
   f[f.length] = {    // <= 以降はグルーピングされる機能を追加
   f[f.length] = {    // <= 以降はグルーピングされる機能を追加
33行目: 33行目:
   };
   };
]};  // <= グルーピングの終了
]};  // <= グルーピングの終了
</source>
</syntaxhighlight>


= コード =
= コード =
39行目: 39行目:


== 基本コード ==
== 基本コード ==
<source lang="javascript">
<syntaxhighlight lang="javascript">
#title = "テキスト変換"
#title = "テキスト変換"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
186行目: 186行目:
   }
   }
})();
})();
</source>
</syntaxhighlight>


== 拡張コード ==
== 拡張コード ==
194行目: 194行目:


=== 空白削除 ===
=== 空白削除 ===
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "空白削除", function(f){
f[f.length] = [ "空白削除", function(f){
   f[f.length] = [ "行頭の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+/mg,"")} ];
   f[f.length] = [ "行頭の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+/mg,"")} ];
202行目: 202行目:
   f[f.length] = [ "カンマ前後の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+|[ \t ]+$/mg,"").replace(/[ \t ]*,[ \t ]*/mg,",")} ];
   f[f.length] = [ "カンマ前後の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+|[ \t ]+$/mg,"").replace(/[ \t ]*,[ \t ]*/mg,",")} ];
}];
}];
</source>
</syntaxhighlight>
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"空白削除",
   title:"空白削除",
229行目: 229行目:
   }
   }
};
};
</source>
</syntaxhighlight>


=== 文字変換 ===
=== 文字変換 ===
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "文字変換", function(f){
f[f.length] = [ "文字変換", function(f){
   f[f.length] = [ "大文字に変換", "", function(a){return a.toUpperCase()} ];
   f[f.length] = [ "大文字に変換", "", function(a){return a.toUpperCase()} ];
248行目: 248行目:
   f[f.length] = [ "アラビア数字⇒漢数字", "", function(a){return a.replace(/[0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}).replace(/[0-9]/mg,function(s){return"〇一二三四五六七八九".substr(Number(s),1)})} ];
   f[f.length] = [ "アラビア数字⇒漢数字", "", function(a){return a.replace(/[0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}).replace(/[0-9]/mg,function(s){return"〇一二三四五六七八九".substr(Number(s),1)})} ];
}];
}];
</source>
</syntaxhighlight>
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"文字変換",
   title:"文字変換",
303行目: 303行目:
   }
   }
};
};
</source>
</syntaxhighlight>


=== ソート ===
=== ソート ===
「[[昇順で並び替え]]」「[[降順で並び替え]]」 の移植です.
「[[昇順で並び替え]]」「[[降順で並び替え]]」 の移植です.
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "ソート", function(f){
f[f.length] = [ "ソート", function(f){
   f[f.length] = [ "昇順ソート(文字列)", "S", function(a){return a.split("\n").sort().join("\n")} ];
   f[f.length] = [ "昇順ソート(文字列)", "S", function(a){return a.split("\n").sort().join("\n")} ];
   f[f.length] = [ "降順ソート(文字列)", "S", function(a){return a.split("\n").sort().reverse().join("\n")} ];
   f[f.length] = [ "降順ソート(文字列)", "S", function(a){return a.split("\n").sort().reverse().join("\n")} ];
}];
}];
</source>
</syntaxhighlight>
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"ソート",
   title:"ソート",
327行目: 327行目:
   }
   }
};
};
</source>
</syntaxhighlight>


=== 行操作 ===
=== 行操作 ===
「[[連続する重複行を削除]]」の移植を含みます.
「[[連続する重複行を削除]]」の移植を含みます.
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "行操作", function(f){
f[f.length] = [ "行操作", function(f){
   f[f.length] = [ "文字列追加", function(f){
   f[f.length] = [ "文字列追加", function(f){
346行目: 346行目:
   }];
   }];
}];
}];
</source>
</syntaxhighlight>
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"行操作",
   title:"行操作",
450行目: 450行目:
   }
   }
};
};
</source>
</syntaxhighlight>


=== グルーピング ===
=== グルーピング ===
選択範囲を簡易的にグルーピングします.
選択範囲を簡易的にグルーピングします.
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "機能のグルーピング", "S", function(a){var b=Prompt("グループ名","");if(!b){Quit()}var c=a.match(/^\s*/);var d="\t";return c+'f[f.length] = [ "'+b+'", function(f){\n'+d+a.split("\n").join("\n"+d)+"\n"+c+"}];"} ];
f[f.length] = [ "機能のグルーピング", "S", function(a){var b=Prompt("グループ名","");if(!b){Quit()}var c=a.match(/^\s*/);var d="\t";return c+'f[f.length] = [ "'+b+'", function(f){\n'+d+a.split("\n").join("\n"+d)+"\n"+c+"}];"} ];
</source>
</syntaxhighlight>
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"機能のグルーピング",
   title:"機能のグルーピング",
468行目: 468行目:
   }
   }
};
};
</source>
</syntaxhighlight>


=== BASE64エンコード(Unicode) ===
=== BASE64エンコード(Unicode) ===
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"BASE64エンコード(Unicode)",
   title:"BASE64エンコード(Unicode)",
486行目: 486行目:
   }
   }
};
};
</source>
</syntaxhighlight>


= 開発者向け資料 =
= 開発者向け資料 =
496行目: 496行目:


== replace ==
== replace ==
<source lang="javascript">
<syntaxhighlight lang="javascript">
function replace(
function replace(
     text : string,
     text : string,
     selection : Selection
     selection : Selection
) : string
) : string
</source>
</syntaxhighlight>
最も基本的な変換関数です.<br>
最も基本的な変換関数です.<br>
選択されている文字列,またはドキュメント全体の文字列を引数として,
選択されている文字列,またはドキュメント全体の文字列を引数として,
509行目: 509行目:


== replaceS ==
== replaceS ==
<source lang="javascript">
<syntaxhighlight lang="javascript">
function replaceS(
function replaceS(
     text : string,
     text : string,
     selection : Selection
     selection : Selection
) : string
) : string
</source>
</syntaxhighlight>
行途中の選択がされている場合に,行全体を選択し直してから実行される変換関数です.<br>
行途中の選択がされている場合に,行全体を選択し直してから実行される変換関数です.<br>
行は論理行で処理しますが,下記のように <code>view:true</code> を定義時に登録することで,
行は論理行で処理しますが,下記のように <code>view:true</code> を定義時に登録することで,
表示行で処理することもできます.
表示行で処理することもできます.
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = {
f[f.length] = {
   title:"replaceL",
   title:"replaceL",
524行目: 524行目:
   replaceS:function(text){ return text }
   replaceS:function(text){ return text }
};
};
</source>
</syntaxhighlight>


== replaceL ==
== replaceL ==
<source lang="javascript">
<syntaxhighlight lang="javascript">
function replaceL(
function replaceL(
     text : string,
     text : string,
     selection : Selection
     selection : Selection
) : string
) : string
</source>
</syntaxhighlight>
行単位で処理する場合に利用する変換関数です.<br>
行単位で処理する場合に利用する変換関数です.<br>
渡される text は,他の関数と違い'''「1 行分の文字列」'''です.<br>
渡される text は,他の関数と違い'''「1 行分の文字列」'''です.<br>
538行目: 538行目:


次の 2 つの定義は同じ処理(空白行削除)をします.
次の 2 つの定義は同じ処理(空白行削除)をします.
<source lang="javascript">
<syntaxhighlight lang="javascript">
replaceS:function(text){ return text.replace(/^\n/mg, "") }
replaceS:function(text){ return text.replace(/^\n/mg, "") }
replaceL:function(text){ if (text != "") { return text } }
replaceL:function(text){ if (text != "") { return text } }
</source>
</syntaxhighlight>
<code>replaceL</code> 関数の場合,null を返すかあるいは return しない場合に行を削除します.<br>
<code>replaceL</code> 関数の場合,null を返すかあるいは return しない場合に行を削除します.<br>


550行目: 550行目:
関数を 1 行で書きやすくするため,簡易表記を追加しました.<br>
関数を 1 行で書きやすくするため,簡易表記を追加しました.<br>
配列の形式で記述し,
配列の形式で記述し,
<source lang="javascript">
<syntaxhighlight lang="javascript">
f[f.length] = [ "機能名", "関数タイプ", function(text){ return text; }, isView  
f[f.length] = [ "機能名", "関数タイプ", function(text){ return text; }, isView  
</source>
</syntaxhighlight>
で記述します.<br>
で記述します.<br>


563行目: 563行目:
関数部分はクリップボードにコピーされるため,そのまま貼り付けるか,<br>
関数部分はクリップボードにコピーされるため,そのまま貼り付けるか,<br>
[http://dean.edwards.name/packer/ packer] などを利用して圧縮して貼り付けてください.
[http://dean.edwards.name/packer/ packer] などを利用して圧縮して貼り付けてください.
<source lang="javascript">
<syntaxhighlight lang="javascript">
// 関数の簡易表現化
// 関数の簡易表現化
// 関数部分はクリップボードにコピーする
// 関数部分はクリップボードにコピーする
596行目: 596行目:
   }
   }
};
};
</source>
</syntaxhighlight>




= ご意見・ご要望 =
= ご意見・ご要望 =
何かありましたら,右の [編集] から追記してください.対応するもかしれません.
何かありましたら,右の [編集] から追記してください.対応するもかしれません.
スポンサーリンク