From 377485b1dd07a0e09cff5acca4b86367176c2d95 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 11 Sep 2002 22:42:49 +0000 Subject: [PATCH] Display the values of character arrays as characters. --- .../org/eclipse/cdt/debug/core/ICValue.java | 1 + .../cdt/debug/internal/core/model/CValue.java | 49 ++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICValue.java index 9ff06a52f9a..36a10aff0a6 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICValue.java @@ -24,6 +24,7 @@ public interface ICValue extends IValue static final public int TYPE_POINTER = 4; static final public int TYPE_ARRAY_PARTITION = 5; static final public int TYPE_ARRAY_ENTRY = 7; + static final public int TYPE_CHAR = 8; /** * Returns the type of this value. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java index e793747ffb6..fed6a1babd9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java @@ -52,11 +52,10 @@ public class CValue extends CDebugElement implements ICValue * Constructor for CValue. * @param target */ - public CValue( CDebugTarget target, ICDIValue cdiValue ) throws DebugException + public CValue( CDebugTarget target, ICDIValue cdiValue ) { super( target ); fCDIValue = cdiValue; - calculateType(); } /* (non-Javadoc) @@ -185,13 +184,16 @@ public class CValue extends CDebugElement implements ICValue return Collections.EMPTY_LIST; } - protected void calculateType() throws DebugException + protected void calculateType( String stringValue ) { - String stringValue = getValueString(); if ( stringValue != null && stringValue.trim().length() > 0 ) { stringValue = stringValue.trim(); - if ( stringValue.charAt( 0 ) == '[' ) + if ( stringValue.charAt( stringValue.length() - 1 ) == '\'' ) + { + fType = TYPE_CHAR; + } + else if ( stringValue.charAt( 0 ) == '[' ) { fType = TYPE_ARRAY; } @@ -230,7 +232,17 @@ public class CValue extends CDebugElement implements ICValue protected String processCDIValue( String cdiValue ) { - return cdiValue; + String result = null; + if ( cdiValue != null ) + { + result = cdiValue.trim(); + calculateType( result ); + if ( getType() == TYPE_CHAR ) + { + result = getCharValue( result ); + } + } + return result; } public synchronized void setChanged( boolean changed ) throws DebugException @@ -254,4 +266,29 @@ public class CValue extends CDebugElement implements ICValue ((CVariable)it.next()).dispose(); } } + + private String getCharValue( String value ) + { + char result = '.'; + int index = value.indexOf( ' ' ); + if ( index > 0 ) + { + try + { + short shortValue = Short.parseShort( value.substring( 0, index ), 10 ); + if ( shortValue >= 0 ) + { + result = (char)shortValue; + if ( Character.isISOControl( result ) ) + { + result = '.'; + } + } + } + catch( NumberFormatException e ) + { + } + } + return String.valueOf( result ); + } }