Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] New conversion utilities.

Added conversion utilities to support decimal format in the Memory View.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.44
diff -u -r1.44 ChangeLog
--- ChangeLog 1 Nov 2002 23:17:17 -0000 1.44
+++ ChangeLog 1 Nov 2002 23:20:55 -0000
@@ -1,4 +1,8 @@
-2002-10-31 Mikhail Khodjaiants
+2002-11-01 Mikhail Khodjaiants
+ Added conversion utilities to support decimal format in the Memory View.
+ * CDebugUtils.java
+
+2002-11-01 Mikhail Khodjaiants
  Added the 'IExecFileInfo' interface to provide access to the executable file information.
  * IExecFileInfo.java: definition
  * CDebugTarget.java: implementation
Index: src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java,v
retrieving revision 1.5
diff -u -r1.5 CDebugUtils.java
--- src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 25 Oct 2002 21:57:00 -0000 1.5
+++ src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 1 Nov 2002 23:20:56 -0000
@@ -5,6 +5,8 @@
  */
 package org.eclipse.cdt.debug.internal.core;
 
+import java.util.Arrays;
+
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.debug.core.DebugPlugin;
@@ -131,5 +133,112 @@
   {
   }
   return 0;
- }
+ }

+ public static short toShort( char[] bytes, boolean le )
+ {
+  if ( bytes.length != 2 )
+   return 0;
+  return Short.parseShort( bytesToString( bytes, le, true ), 16 );
+ } 

+ public static int toUnsignedShort( char[] bytes, boolean le )
+ {
+  if ( bytes.length != 2 )
+   return 0;
+  return Integer.parseInt( bytesToString( bytes, le, false ), 16 );
+ } 

+ public static int toInt( char[] bytes, boolean le )
+ {
+  if ( bytes.length != 4 )
+   return 0;
+  return Integer.parseInt( bytesToString( bytes, le, true ), 16 );
+ } 

+ public static long toUnsignedInt( char[] bytes, boolean le )
+ {
+  if ( bytes.length != 4 )
+   return 0;
+  return Long.parseLong( bytesToString( bytes, le, false ), 16 );
+ } 

+ public static long toLong( char[] bytes, boolean le )
+ {
+  return toInt( bytes, le );
+ }

+ public static long toUnsignedLong( char[] bytes, boolean le )
+ {
+  return toUnsignedInt( bytes, le );
+ }

+ private static String bytesToString( char[] bytes, boolean le, boolean signed )
+ {
+  char[] copy = new char[bytes.length];
+  if ( le )
+  {
+   for ( int i = 0; i < bytes.length / 2; ++i )
+   {
+    copy[2 * i] = bytes[bytes.length - 2 * i - 2];
+    copy[2 * i + 1] = bytes[bytes.length - 2 * i - 1];
+   }
+  }
+  else
+  {
+   System.arraycopy( bytes, 0, copy, 0, copy.length );
+  }
+  StringBuffer sb = new StringBuffer( copy.length );
+  if ( signed )
+  {
+   switch( copy[0] )
+   {
+    case '0':
+    case '1':
+    case '2':
+    case '3':
+    case '4':
+    case '5':
+    case '6':
+    case '7':
+     break;
+    case '8':
+    case '9':
+    case 'a':
+    case 'A':
+    case 'b':
+    case 'B':
+    case 'c':
+    case 'C':
+    case 'd':
+    case 'D':
+    case 'e':
+    case 'E':
+    case 'f':
+    case 'F':
+     sb.append( '-' );
+     copy[0] -= '8';
+     break;
+   }
+  }
+  sb.append( copy );
+   return sb.toString();
+ }

+ public static String prependString( String text, int length, char ch )
+ {
+  StringBuffer sb = new StringBuffer( length );
+  if ( text.length() > length )
+  {
+   sb.append( text.substring( 0, length ) );
+  }
+  else
+  {
+   char[] prefix = new char[length - text.length()];
+   Arrays.fill( prefix, ch );
+   sb.append( prefix );
+   sb.append( text );
+  }
+  return sb.toString();
+ } 
 }


Back to the top