From 23529181b25735522c949a5e8fd9dc9fa54e25a2 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 25 Oct 2002 21:57:00 +0000 Subject: [PATCH] Utilities to convert textual presentation of memory to bytes. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 3 ++ .../cdt/debug/internal/core/CDebugUtils.java | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 9744ce71a72..a115d69ab19 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,6 @@ +2002-10-25 Mikhail Khodjaiants + * CDebugUtils.java: Added utilities to convert textual presentation of memory to bytes. + 2002-10-25 Mikhail Khodjaiants * IFormattedMemoryBlock.java: Replaced 'MEMORY_BYTES_PER_ROW_...' constants by 'MEMORY_NUMBER_OF_COLUMNS_...'. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java index 65a48b605de..fee5fb49f9e 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java @@ -84,6 +84,17 @@ public class CDebugUtils charFromByte( (byte)(b & 0x0f) ) }; } + public static byte textToByte( char[] text ) + { + byte result = 0; + if ( text.length == 2 ) + { + byte[] bytes = { charToByte( text[0] ), charToByte( text[1] ) }; + result = (byte)((bytes[0] << 4) + bytes[1]); + } + return result; + } + public static char charFromByte( byte value ) { if ( value >= 0x0 && value <= 0x9 ) @@ -93,6 +104,23 @@ public class CDebugUtils return '0'; } + public static byte charToByte( char ch ) + { + if ( Character.isDigit( ch ) ) + { + return (byte)(ch - '0'); + } + if ( ch >= 'a' && ch <= 'f' ) + { + return (byte)(0xa + ch - 'a'); + } + if ( ch >= 'A' && ch <= 'F' ) + { + return (byte)(0xa + ch - 'A'); + } + return 0; + } + public static char bytesToChar( byte[] bytes ) { try