「テキスト整形」の版間の差分
細 拡張コードの<source> overflow を word-wrap に変更。 |
コマンド追加1個・変更2(+2)個。 |
||
| 25行目: | 25行目: | ||
[[ファイル:テキスト整形.zip]] | [[ファイル:テキスト整形.zip]] | ||
<div style="height:30em; overflow:auto; border:1px dashed #999;"> | <div style="height:30em; overflow:auto; border:1px dashed #999;"> | ||
* <b>2014/05/22</b> | |||
** コマンド追加 - 2進接頭辞換算(Ki,Mi,Gi...) | |||
** コマンド変更 - Unicode \x{hex} → 文字/Unicode &#dec; → 文字 | |||
**: サロゲートペアの String.fromCharCode() の引数を複数指定に改修、ビット演算に変更。 | |||
* <b>2014/05/16</b> | * <b>2014/05/16</b> | ||
** コマンド変更 - Unicode 文字 → \x{hex}/Unicode 文字 → &#dec; | ** コマンド変更 - Unicode 文字 → \x{hex}/Unicode 文字 → &#dec; | ||
| 589行目: | 593行目: | ||
a.ChangeCase(meCaseLowerCase) }]); | a.ChangeCase(meCaseLowerCase) }]); | ||
</source> | </source> | ||
;半角に変換/全角に変換 | ;半角に変換/全角に変換 | ||
:Mery の「選択範囲の変換」機能の一部を再現したものです。 | :Mery の「選択範囲の変換」機能の一部を再現したものです。 | ||
| 678行目: | 683行目: | ||
f.push(["16→10進数","R",function(a){ | f.push(["16→10進数","R",function(a){ | ||
return a.replace(/(?:0x)?([0-9A-Fa-f]+)/g,function(s,s1){return Number("0x"+s1)}) }]); | return a.replace(/(?:0x)?([0-9A-Fa-f]+)/g,function(s,s1){return Number("0x"+s1)}) }]); | ||
</source> | |||
;2進接頭辞換算(Ki,Mi,Gi...) | |||
:2<sup>10</sup> = 1024 の倍量単位に変換します(小数点第3位を四捨五入)。 | |||
:例> <span style="background:#bfdfff;">1023/1024/54321/1,048,576/1,073,741,824</span> → 1023/1.00Ki/53.05Ki/1.00Mi/1.00Gi | |||
<source lang="javascript" style="word-wrap:break-word;"> | |||
f.push(["2進接頭辞換算(Ki,Mi,Gi...)","R",function(a){ | |||
return a.replace(/\d+(?:,?\d{3})+(?:\.\d+)?/g,function(s){var n=s.replace(/,/g,""); if(n<1024)return s; var x=0; while(x<8&&n>=1024){x++;n/=1024} return n.toFixed(2)+" KMGTPEZY".charAt(x)+"i"}) }]); | |||
</source> | </source> | ||
| 710行目: | 723行目: | ||
<source lang="javascript" style="word-wrap:break-word;"> | <source lang="javascript" style="word-wrap:break-word;"> | ||
f.push(["Unicode 文字 → \\x{hex}","R",function(a){ | f.push(["Unicode 文字 → \\x{hex}","R",function(a){ | ||
return a.replace(/.+/g,function(s){var r=[]; for(var i=0;i<s.length;i++){var u=s.charCodeAt(i); if(0xD800<=u&&u<=0xDBFF){var v=s.charCodeAt(i+1); if(0xDC00<=v&&v<=0xDFFF){i++;u=0x10000+(u-0xD800) | return a.replace(/.+/g,function(s){var r=[]; for(var i=0;i<s.length;i++){var u=s.charCodeAt(i); if(0xD800<=u&&u<=0xDBFF){var v=s.charCodeAt(i+1); if(0xDC00<=v&&v<=0xDFFF){i++;u=0x10000+(u-0xD800<<10)+(v-0xDC00)}} r.push("\\x{"+u.toString(16)+"}")} return r.join("")}) }]); | ||
</source> | </source> | ||
;Unicode \x{hex} ⇒ 文字 | ;Unicode \x{hex} ⇒ 文字 | ||
| 716行目: | 729行目: | ||
<source lang="javascript" style="word-wrap:break-word;"> | <source lang="javascript" style="word-wrap:break-word;"> | ||
f.push(["Unicode \\x{hex} → 文字","R",function(a){ | f.push(["Unicode \\x{hex} → 文字","R",function(a){ | ||
return a.replace(/\\x{([0-9A-Fa-f]{1,6})}/g,function(s,s1){s1=Number("0x"+s1); return (s1<=0xFFFF)?String.fromCharCode(s1): (s1<=0x10FFFF)?String.fromCharCode((s1-0x10000) | return a.replace(/\\x{([0-9A-Fa-f]{1,6})}/g,function(s,s1){s1=Number("0x"+s1); return (s1<=0xFFFF)?String.fromCharCode(s1): (s1<=0x10FFFF)?String.fromCharCode((s1-0x10000>>10)+0xD800,(s1-0x10000&0x3FF)+0xDC00): s}) }]); | ||
</source> | </source> | ||
| 724行目: | 737行目: | ||
<source lang="javascript" style="word-wrap:break-word;"> | <source lang="javascript" style="word-wrap:break-word;"> | ||
f.push(["Unicode 文字 → &&#dec;","R",function(a){ | f.push(["Unicode 文字 → &&#dec;","R",function(a){ | ||
return a.replace(/.+/g,function(s){var r=[]; for(var i=0;i<s.length;i++){var u=s.charCodeAt(i); if(0xD800<=u&&u<=0xDBFF){var v=s.charCodeAt(i+1); if(0xDC00<=v&&v<=0xDFFF){i++;u=0x10000+(u-0xD800) | return a.replace(/.+/g,function(s){var r=[]; for(var i=0;i<s.length;i++){var u=s.charCodeAt(i); if(0xD800<=u&&u<=0xDBFF){var v=s.charCodeAt(i+1); if(0xDC00<=v&&v<=0xDFFF){i++;u=0x10000+(u-0xD800<<10)+(v-0xDC00)}} r.push("&#"+u+";")} return r.join("")}) }]); | ||
</source> | </source> | ||
;Unicode &#dec; ⇒ 文字 | ;Unicode &#dec; ⇒ 文字 | ||
| 730行目: | 743行目: | ||
<source lang="javascript" style="word-wrap:break-word;"> | <source lang="javascript" style="word-wrap:break-word;"> | ||
f.push(["Unicode &&#dec; → 文字","R",function(a){ | f.push(["Unicode &&#dec; → 文字","R",function(a){ | ||
return a.replace(/&#([0-9]{1,7});/g,function(s,s1){s1=Number(s1); return (s1<=0xFFFF)?String.fromCharCode(s1): (s1<=0x10FFFF)?String.fromCharCode((s1-0x10000) | return a.replace(/&#([0-9]{1,7});/g,function(s,s1){s1=Number(s1); return (s1<=0xFFFF)?String.fromCharCode(s1): (s1<=0x10FFFF)?String.fromCharCode((s1-0x10000>>10)+0xD800,(s1-0x10000&0x3FF)+0xDC00): s}) }]); | ||
</source> | </source> | ||
スポンサーリンク