update of javajs package; adds org.apache.harmony, org.xml.sax.helpers
[jalview.git] / src / javajs / util / PT.java
index c544967..81653cf 100644 (file)
@@ -31,7 +31,6 @@ import java.lang.reflect.Array;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import javajs.J2SIgnoreImport;
 import javajs.api.JSONEncodable;
 
 /**
@@ -41,7 +40,6 @@ import javajs.api.JSONEncodable;
  * 
  */
 
-@J2SIgnoreImport(value = { java.lang.reflect.Array.class })
 public class PT {
 
   public static int parseInt(String str) {
@@ -427,33 +425,34 @@ public class PT {
     return (ichLast < ich ? "" : str.substring(ich, ichLast + 1));
   }
 
-  public static double dVal(String s) throws NumberFormatException {
-    /**
-     * @j2sNative
-     * 
-     * if(s==null)
-     *   throw new NumberFormatException("null");
-     * var d=parseFloat(s);
-     * if(isNaN(d))
-     *  throw new NumberFormatException("Not a Number : "+s);
-     * return d 
-     * 
-     */
-    {
-      return Double.valueOf(s).doubleValue();
-    }
-  }
-
-  public static float fVal(String s) throws NumberFormatException {
-    /**
-     * @j2sNative
-     * 
-     * return this.dVal(s);
-     */
-    {
-      return Float.parseFloat(s);
-    }
-  }
+//  public static double dVal(String s) throws NumberFormatException {
+//    /**
+//     * @j2sNative
+//     * 
+//     * if(s==null)
+//     *   throw new NumberFormatException("null");
+//     * var d=parseFloat(s);
+//     * if(isNaN(d))
+//     *  throw new NumberFormatException("Not a Number : "+s);
+//     * return d 
+//     * 
+//     */
+//    {
+//      return Double.valueOf(s).doubleValue();
+//    }
+//  }
+//
+//  public static float fVal(String s) throws NumberFormatException {
+//    /**
+//     * @j2sNative
+//     * 
+//     * return this.dVal(s);
+//     */
+//    {
+//      
+//      return Float.parseFloat(s);
+//    }
+//  }
 
   public static int parseIntRange(String str, int ichMax, int[] next) {
     int cch = str.length();
@@ -567,6 +566,34 @@ public class PT {
   }
   
   /**
+   * single- or double-quoted string or up to the first space -- like HTML5
+   * not case-sensitive
+   * 
+   * @param line
+   * @param key
+   * @return attribute
+   */
+  public static String getQuotedOrUnquotedAttribute(String line, String key) {
+    if (line == null || key == null)
+      return null;
+    int pt = line.toLowerCase().indexOf(key.toLowerCase() + "=");
+    if (pt < 0 || (pt = pt + key.length() + 1) >= line.length())
+      return "";
+    char c = line.charAt(pt);
+    switch (c) {
+    case '\'':
+    case '"':
+      pt++;
+      break;
+    default:
+      c = ' ';
+      line += " ";
+    }
+    int pt1 = line.indexOf(c, pt);
+    return (pt1 < 0 ? null : line.substring(pt, pt1));
+  }
+  
+  /**
    * CSV format -- escaped quote is "" WITHIN "..."
    *
    * 
@@ -763,21 +790,21 @@ public class PT {
     return info instanceof Number || info instanceof Boolean;
   }
 
-  private static Object arrayGet(Object info, int i) {
-    /**
-     * 
-     * Note that info will be a primitive in JavaScript
-     * but a wrapped primitive in Java.
-     * 
-     * @j2sNative
-     * 
-     *            return info[i];
-     */
-    {
-      return Array.get(info, i);
-    }
-  }
-  
+//  private static Object arrayGet(Object info, int i) {
+//    /**
+//     * 
+//     * Note that info will be a primitive in JavaScript
+//     * but a wrapped primitive in Java.
+//     * 
+//     * @j2sNative
+//     * 
+//     *            return info[i];
+//     */
+//    {
+//      return Array.get(info, i);
+//    }
+//  }
+//  
   @SuppressWarnings("unchecked")
   public static String toJSON(String infoType, Object info) {
     if (info == null)
@@ -855,7 +882,7 @@ public class PT {
         for (int i = 0; i < n; i++) {
           if (i > 0)
             sb.appendC(',');
-          sb.append(toJSON(null, arrayGet(info, i)));
+          sb.append(toJSON(null, Array.get(info, i)));
         }
         sb.append("]");
         break;
@@ -876,7 +903,7 @@ public class PT {
     /**
      * @j2sNative
      * 
-     * return (x.constructor == Array || x.__BYTESIZE ? null : x.toString());
+     * return (x.constructor == Array || x.BYTES_PER_ELEMENT ? null : x.toString());
      * 
      */
     {