// SakuraEditor JScript macro // sakura 2.x 以上 function URIEncodingToOctet() { var i = 0; var uristr = Editor.GetSelectedString( 0 ); var insmode = Editor.IsInsMode(); if( "" == uristr ){ return; } //上書きモードだったら、一時挿入モードに変更 if( false == insmode ){ Editor.ChgmodINS(); } Editor.AddRefUndoBuffer(); var draw = Editor.SetDrawSwitch( 0 ); Editor.Delete(); // 範囲選択内を削除。選択解除 Editor.CharIme( 0x20 ); // スペースを挿入 Editor.Left(); // 左へ移動 Editor.MoveHistSet(); for( i = 0; i < uristr.length; i++ ){ if( uristr.charAt( i ) == "%" ){ if( i + 2 < uristr.length ){ var Hex1 = uristr.charAt(i+1).toUpperCase(); var Hex2 = uristr.charAt(i+2).toUpperCase(); if( ((Hex1 >= "0" && Hex1 <= "9") || (Hex1 >= "A" && Hex1 <= "F")) && ((Hex2 >= "0" && Hex2 <= "9") || (Hex2 >= "A" && Hex2 <= "F")) ){ // サロゲート断片にする var c = 0xdc00 + parseInt( Hex1 + Hex2, 16 ); Editor.Char( c ); i += 2; continue; } } } // 改行コード対策処理 if( uristr.charCodeAt( i ) < 0x20 ){ if( uristr.charCodeAt( i ) == 0x0d ){ if( i + 1 < uristr.length && uristr.charCodeAt( i + 1 ) == 0x0a ){ Editor.InsText( "\r\n" ); i += 1; continue; } } Editor.InsText( uristr.charAt( i ) ); }else{ Editor.Char( uristr.charCodeAt( i ) ); } } Editor.Delete(); // 追加しておいたスペースを削除 Editor.MoveHistPrev(); Editor.BeginSelect(); Editor.MoveHistNext(); Editor.Left(); Editor.Right(); Editor.CommitUndoBuffer(); // UTF-8専用にするには、UTF8ToSJIS()に変えてください。 Editor.AutoToSJIS(); Editor.SetUndoBuffer(); Editor.SetDrawSwitch( draw ); Editor.Redraw( 0 ); if( false == insmode ){ Editor.ChgmodINS(); } } URIEncodingToOctet();