- 论坛徽章:
- 0
|
因为对jEdit现有Hex相关功能插件(Hex、HexEdit、HexTools)功能不太满意,写了一个简单的macro提供Dump Hex功能,设置一个快捷键或者添加到右键菜单的话会更方便,效果见附图,另外jedit-cn讨论组链接为: http://t.cn/zl8AOWG
macro代码如下
- char[] hex_digit = new char[] {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
- String byte_to_hex( byte b ) {
- char[] chars = new char[] {
- hex_digit[ (b >> 4) & 0x0f ],
- hex_digit[ b & 0x0f ]
- };
- return new String( chars );
- }
- String dump_hex( String target ) {
- byte[] string = target.getBytes();
- StringBuffer hex = new StringBuffer();
- int tail = 0;
- String src = "";
- int length = string.length;
- for ( int i=0; i<length; ++i ) {
-
- char curr = string[i];
- if ( curr == '\r' || curr=='\n' || curr=='\t' ) {
- src += " ";
- } else {
- src += curr;
- }
-
- hex.append( byte_to_hex(string[i]) + " " );
- if ( ((i+1)%19) == 0 ) {
- hex.append( " | " + src + "\n" );
- src = "";
- tail = 1;
- } else {
- tail = 0;
- }
- }
-
- if ( tail==0 && src!="" ) {
- int align = 19 - src.length();
- String blank = "";
- for ( int i=0; i<align; ++i ) {
- blank += " ";
- }
- hex.append( blank + " | " + src );
- }
-
- return hex.toString();
- }
- String text = textArea.getSelectedText();
- if ( text==null || text=="" ) {
- textArea.selectAll();
- text = textArea.getSelectedText();
- textArea.selectNone();
- }
- if ( text != null ) {
- String hex = dump_hex( text );
- newbuf = jEdit.newFile( view );
- newbuf.insert( 0, hex );
- }
复制代码 |
|