Patches from Robert Kraske (robekras):
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPDBGEvalString.java
index 4225702..40afdb0 100644 (file)
@@ -25,17 +25,17 @@ public class PHPDBGEvalString {
 
        String workStr;
        private PHPStackFrame fStackFrame;
-       
+
        public PHPDBGEvalString(PHPStackFrame stack,String dataStr) {
                fStackFrame=stack;
                workStr=dataStr;
        }
-       
+
        String ExtractSubStr(char chstart, char chend,int startIdx) throws DebugException {
                int idx=startIdx;
                String rslt;
                if (idx >= (workStr.length() - 1) || workStr.charAt(idx) != chstart) {
-                       Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"worng startIdx!",null); 
+                       Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"worng startIdx!",null);
                        throw new DebugException(status);
                }
                int i = ++idx;
@@ -49,11 +49,11 @@ public class PHPDBGEvalString {
                workStr=workStr.substring(i+1);
                return rslt;
        }
-       
+
        String ExtractQuotedSubStr(int slen,int startIdx) throws DebugException {
                int idx=startIdx;
                String rslt;
-               if (idx+slen+1 >= workStr.length() || 
+               if (idx+slen+1 >= workStr.length() ||
                                workStr.charAt(idx)!= '"' ||
                                workStr.charAt(idx+slen+1) != '"') {
                        Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no quoted substring found!",null);
@@ -64,7 +64,7 @@ public class PHPDBGEvalString {
                return rslt;
        }
 
-       
+
        int ExtractInt(char chstart, char chend,int startIdx) throws DebugException {
                String subs;
                int rslt;
@@ -91,7 +91,7 @@ public class PHPDBGEvalString {
                if (arritems > 0) {
                        subitems = new Vector();
                } else
-                       if (workStr.charAt(0)!='}') 
+                       if (workStr.charAt(0)!='}')
                        {
                                Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array endcharecter!",null);
                                throw new DebugException(status);
@@ -106,18 +106,18 @@ public class PHPDBGEvalString {
                        }
                        // value
                        parse(((PHPVariable)tmplst.elementAt(0)).getValue().getValueString(),item, subitems, var_list, true,0);
-                       
+
                }
                ((PHPValue)item.getValue()).addVariable(subitems);
                workStr=workStr.substring(1);
                return item;
        }
-       
+
        void ParseEvalNULL(String name,PHPVariable parent,Vector list, Vector var_list, int startIdx) throws DebugException {
                int idx=startIdx;
                if (idx >= workStr.length() || workStr.charAt(idx) != ';') {
                        Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"NULL not found!",null);
-                       throw new DebugException(status);       
+                       throw new DebugException(status);
                }
                workStr=workStr.substring(1);
                PHPVariable item= new PHPVariable(fStackFrame, name,parent,"NULL",PHPValue.PEVT_UNKNOWN,null);
@@ -125,7 +125,7 @@ public class PHPDBGEvalString {
                if (var_list!=null)
                        var_list.add(item);
        }
-       
+
        boolean ParseEvalInt( String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
                String subs=null;
                PHPVariable item;
@@ -136,7 +136,7 @@ public class PHPDBGEvalString {
                        var_list.add(item);
                return true;
        }
-       
+
        boolean ParseEvalDouble(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
                String subs=null;
                PHPVariable item;
@@ -147,7 +147,7 @@ public class PHPDBGEvalString {
                        var_list.add(item);
                return true;
        }
-       
+
        boolean ParseEvalString(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx)
                                        throws DebugException{
                int slen;
@@ -176,7 +176,7 @@ public class PHPDBGEvalString {
                        var_list.add(item);
                return true;
        }
-       
+
        boolean ParseEvalBool(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
                        throws DebugException{
                long v;
@@ -186,8 +186,8 @@ public class PHPDBGEvalString {
                if (var_list!=null)
                        list.add(item);
                return true;
-       }       
-       
+       }
+
        boolean ParseEvalObject(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
                        throws DebugException{
                int slen;
@@ -199,7 +199,7 @@ public class PHPDBGEvalString {
                ParseEvalArray(name,parent, list, var_list, classname,PHPValue.PEVT_OBJECT);
                return true;
        }
-       
+
        boolean ParseEvalResource(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
                        throws DebugException{
                int v, slen;
@@ -213,18 +213,18 @@ public class PHPDBGEvalString {
                return true;
        }
 
-       
+
        boolean ParseEvalRef(String name,PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx)
                        throws DebugException{
                int v;
 
                v=ExtractInt(':', ';',startIdx);
 
-               PHPVariable item= new PHPVariable(fStackFrame, name,parent,"",(isSoftRef)? (PHPValue.PEVT_SOFTREF): (PHPValue.PEVT_REF),null);          
+               PHPVariable item= new PHPVariable(fStackFrame, name,parent,"",(isSoftRef)? (PHPValue.PEVT_SOFTREF): (PHPValue.PEVT_REF),null);
                v--; // ref ID is 1-based, EvalList is 0-based
 
 
-               if ((var_list==null) || (v<0) || (v >= var_list.size())) { 
+               if ((var_list==null) || (v<0) || (v >= var_list.size())) {
 //                     item.ref = item; // self-resolving
                        return true;
                }       else {
@@ -237,63 +237,77 @@ public class PHPDBGEvalString {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
-                       list.add(item);                 
+                       list.add(item);
                }
-                       
+
 
                return true;
        }
-       
-       public PHPVariable[] getVars(){
-               Vector list=new Vector();
-               Vector var_list=new Vector();
-               parse("",null,list,var_list,false,0);
-               return (PHPVariable[])list.toArray(new PHPVariable[list.size()]);
+
+       /**
+        *
+        * @return The array of PHPVariables
+        */
+       public PHPVariable[] getVars () {
+               Vector list     = new Vector ();
+               Vector var_list = new Vector ();
+
+               parse ("", null, list, var_list, false, 0);
+
+               return (PHPVariable[]) list.toArray (new PHPVariable[list.size ()]);    // Convert the list to an array and return the array
+       }
+
+       /**
+        *
+        * @return The array of PHPVariables
+        */
+       public Vector getVariables () {
+               Vector list     = new Vector ();
+               Vector var_list = new Vector ();
+
+               parse ("", null, list, var_list, false, 0);
+
+               return list;                                                                                                                    // return the PHPVariable list
        }
-       
-       boolean parse(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr,int startIdx) {
+
+       /**
+        *
+        * @param name
+        * @param parent
+        * @param list
+        * @param var_list
+        * @param MakePhpStr
+        * @param startIdx
+        */
+       boolean parse (String name, PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx) {
                boolean ret_val = false;
+               char    ch;
+
+               if (startIdx >= workStr.length ()) {
+                       return false;
+               }
+
+               ch              = workStr.charAt (startIdx);
+               workStr = workStr.substring (1);
 
-               if (startIdx >= workStr.length()) return false;
-               char ch = workStr.charAt(startIdx);
-               workStr=workStr.substring(1);
                try {
                        switch (ch) {
-                               case 'N': 
-                                       ParseEvalNULL(name,parent, list, var_list, startIdx);
-                                       break;
-                               case 'i': 
-                                       ParseEvalInt(name,parent, list, var_list, startIdx);
-                                       break;
-                               case 'd': 
-                                       ParseEvalDouble(name,parent, list, var_list, startIdx);
-                                       break;
-                               case 's': 
-                                       ParseEvalString(name,parent, list, var_list, MakePhpStr, startIdx);
-                                       break;
-                               case 'a': 
-                                       ParseEvalArray(name,parent, list, var_list, "", PHPValue.PEVT_ARRAY);
-                                       break;
-                               case 'O': 
-                                       ParseEvalObject(name,parent, list, var_list, startIdx);
-                                       break;
-                               case 'b': 
-                                       ParseEvalBool(name,parent, list, var_list, startIdx);
-                                       break;
-                               case 'z': 
-                                       ParseEvalResource(name,parent, list, var_list, startIdx);
-                                       break;
-                               case 'R': 
-                                       ParseEvalRef(name,parent, list, var_list, false, startIdx);
-                                       break;
-                               case 'r': 
-                                       ParseEvalRef(name,parent, list, var_list, true, startIdx);
-                                       break;
+                               case 'N': ParseEvalNULL         (name, parent, list, var_list, startIdx);                                break;
+                               case 'i': ParseEvalInt          (name, parent, list, var_list, startIdx);                                break;
+                               case 'd': ParseEvalDouble       (name, parent, list, var_list, startIdx);                                break;
+                               case 's': ParseEvalString       (name, parent, list, var_list, MakePhpStr, startIdx);    break;
+                               case 'a': ParseEvalArray        (name, parent, list, var_list, "", PHPValue.PEVT_ARRAY); break;
+                               case 'O': ParseEvalObject       (name, parent, list, var_list, startIdx);                                break;
+                               case 'b': ParseEvalBool         (name, parent, list, var_list, startIdx);                                break;
+                               case 'z': ParseEvalResource (name, parent, list, var_list, startIdx);                            break;
+                               case 'R': ParseEvalRef          (name, parent, list, var_list, false, startIdx);                 break;
+                               case 'r': ParseEvalRef          (name, parent, list, var_list, true, startIdx);                  break;
                        }
                } catch (DebugException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
+
 /*             if (!ret_val) { // try to recover
                        unsigned int i=*startIdx;
                        while (i<str.length() && str[i]!='{' && str[i]!=';') i++;
@@ -303,7 +317,7 @@ public class PHPDBGEvalString {
                                while (i<str.length() && cnt!=0) {
                                        if (str[i] == '{')
                                                cnt++;
-                                       else if (str[i] == '}') 
+                                       else if (str[i] == '}')
                                                cnt--;
                                        i++;
                                }
@@ -313,6 +327,4 @@ public class PHPDBGEvalString {
 */
                return  ret_val;
        }
-
-       
 }