Revision: 20155
          http://sourceforge.net/p/jmol/code/20155
Author:   hansonr
Date:     2014-12-05 04:03:24 +0000 (Fri, 05 Dec 2014)
Log Message:
-----------
Jmol.___JmolVersion="14.3.11_2014.12.04"

new feature: "....".split("",true) // CSV split of string to array of arrays
new feature: [...].split("",true) // CSV split of array to array of arrays
new feature: "...".split("\t",true) // tab split of string to array of arrays
new feature: [...].split("\t",true) // tab split of array to array of arrays
new feature: [...][...].join("",true) // CSV join to array of lines
new feature: [...][...].join("\t",true) // tab join to array of lines
  -- example:
   x = load("test.csv").lines.split("",true) //from CSV
   print x.join("",true) // back to CSV
   print x.join("\t",true) // to tab-separated
new feature: [...][...].col(n)
  -- extracts nth column from an array of arrays
  -- example:
   x = load("test.csv").lines.split("",true).col(3) //3rd column from CSV
  
    

Modified Paths:
--------------
    trunk/Jmol/src/javajs/util/PT.java
    trunk/Jmol/src/org/jmol/script/ScriptEval.java
    trunk/Jmol/src/org/jmol/script/T.java
    trunk/Jmol/src/org/jmol/scriptext/MathExt.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties

Modified: trunk/Jmol/src/javajs/util/PT.java
===================================================================
--- trunk/Jmol/src/javajs/util/PT.java  2014-12-02 13:02:46 UTC (rev 20154)
+++ trunk/Jmol/src/javajs/util/PT.java  2014-12-05 04:03:24 UTC (rev 20155)
@@ -548,21 +548,55 @@
     return getQuotedStringNext(line, next);
   }
   
+  /**
+   * 
+   * @param line
+   * @param next passes [current pointer]
+   * @return quoted string -- does NOT unescape characters
+   */
   public static String getQuotedStringNext(String line, int[] next) {
-    String value = line;
     int i = next[0];
-    if (i < 0 || (i = value.indexOf("\"", i)) < 0)
+    if (i < 0 || (i = line.indexOf("\"", i)) < 0)
       return "";
-    next[0] = ++i;
-    value = value.substring(i);
-    i = -1;
-    while (++i < value.length() && value.charAt(i) != '"')
-      if (value.charAt(i) == '\\')
+    int pt = i + 1;
+    int len = line.length();
+    while (++i < len && line.charAt(i) != '"')
+      if (line.charAt(i) == '\\')
         i++;
-    next[0] += i + 1;
-    return value.substring(0, i);
+    next[0] = i + 1;
+    return line.substring(pt, i);
   }
   
+  /**
+   * CSV format -- escaped quote is "" WITHIN "..."
+   *
+   * 
+   * @param line
+   * @param next int[2] filled with [ptrQuote1, ptrAfterQuote2]
+   * @return unescaped string or null
+   */
+  public static String getCSVString(String line, int[] next) {
+    int i = next[1];
+    if (i < 0 || (i = line.indexOf("\"", i)) < 0)
+      return null;
+    int pt = next[0] = i;
+    int len = line.length();
+    boolean escaped = false;
+    boolean haveEscape = false;
+    while (++i < len 
+        && (line.charAt(i) != '"' || (escaped = (i + 1 < len && line.charAt(i 
+ 1) == '"'))))
+      if (escaped) {
+        escaped = false;
+        haveEscape = true;
+        i++;
+      }
+    if (i >= len)
+      return null; // unmatched
+    next[1] = i + 1;
+    String s = line.substring(pt + 1, i);
+    return (haveEscape ? rep(rep(s, "\"\"", "\0"), "\0","\"") : s);
+  }
+  
   public static boolean isOneOf(String key, String semiList) {
     if (semiList.length() == 0)
       return false;
@@ -581,11 +615,8 @@
   }
 
   /**
-   * Does a clean replace of strFrom in str with strTo. This method has far
-   * faster performance than just String.replace() when str does not contain
-   * strFrom, but is about 15% slower when it does. (Note that
-   * String.replace(CharSeq, CharSeq) was introduced in Java 1.5. Finally
-   * getting around to using it in Jmol!)
+   * Does a clean ITERATIVE replace of strFrom in str with strTo. 
+   * Thus, rep("Testttt", "tt","t") becomes "Test".
    * 
    * @param str
    * @param strFrom

Modified: trunk/Jmol/src/org/jmol/script/ScriptEval.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/ScriptEval.java      2014-12-02 13:02:46 UTC 
(rev 20154)
+++ trunk/Jmol/src/org/jmol/script/ScriptEval.java      2014-12-05 04:03:24 UTC 
(rev 20155)
@@ -8585,9 +8585,9 @@
       if (key.startsWith("_"))
         invArg();
       if (key.indexOf("/") >= 0)
-        contextVariables.put(key, t = SV.newI(0));
+        contextVariables.put(key.toLowerCase(), t = SV.newI(0));
       else
-      t = vwr.g.getOrSetNewVariable(key, true);
+        t = vwr.g.getOrSetNewVariable(key, true);
     }
     return t;
   }

Modified: trunk/Jmol/src/org/jmol/script/T.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/T.java       2014-12-02 13:02:46 UTC (rev 
20154)
+++ trunk/Jmol/src/org/jmol/script/T.java       2014-12-05 04:03:24 UTC (rev 
20155)
@@ -742,10 +742,8 @@
   
   public final static int div          = 0 | 1 << 9 | mathfunc | mathproperty;
   public final static int dot          = 1 | 1 << 9 | mathfunc | mathproperty;
-  public final static int join         = 2 | 1 << 9 | mathfunc | mathproperty;
   public final static int mul          = 3 | 1 << 9 | mathfunc | mathproperty;
   public final static int mul3         = 4 | 1 << 9 | mathfunc | mathproperty;
-  public final static int split        = 6 | 1 << 9 | mathfunc | mathproperty;
   public final static int sub          = 7 | 1 << 9 | mathfunc | mathproperty;
   public final static int trim         = 8 | 1 << 9 | mathfunc | mathproperty; 
 
   public final static int volume       = 9 | 1 << 9 | mathfunc | mathproperty 
| floatproperty;  
@@ -755,7 +753,7 @@
   // xxx(a,b)
   
   public final static int cross = 1 | 2 << 9 | mathfunc;
-  public final static int load         = 2 | 2 << 9 | mathfunc | scriptCommand;
+  public final static int load         = 3 | 2 << 9 | mathfunc | scriptCommand;
   public final static int random       = 4 | 2 << 9 | mathfunc;
   public final static int script       = 5 | 2 << 9 | mathfunc | scriptCommand;
   public final static int substructure = 6 | 2 << 9 | mathfunc | intproperty | 
strproperty;
@@ -775,7 +773,9 @@
   public final static int add          = 1 | 2 << 9 | mathfunc | mathproperty;
   public final static int distance     = 2 | 2 << 9 | mathfunc | mathproperty;
   public final static int push         = 3 | 2 << 9 | mathfunc | mathproperty 
| scriptCommand | noArgs; //internal only;
-
+  public final static int join         = 4 | 2 << 9 | mathfunc | mathproperty;
+  public final static int split        = 5 | 2 << 9 | mathfunc | mathproperty;
+  
   // xxx(a,b,c)
   
   public final static int hkl          = 1 | 3 << 9 | mathfunc;

Modified: trunk/Jmol/src/org/jmol/scriptext/MathExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/MathExt.java      2014-12-02 13:02:46 UTC 
(rev 20154)
+++ trunk/Jmol/src/org/jmol/scriptext/MathExt.java      2014-12-05 04:03:24 UTC 
(rev 20155)
@@ -1124,7 +1124,8 @@
 
   /**
    * array.add(x) array.add(sep, x) array.sub(x) array.mul(x) array.mul3(x)
-   * array.div(x) array.push() array.pop()
+   * array.div(x) array.push() array.pop() array.split("")
+   * array.split("\t",true)
    * 
    * @param mp
    * @param tok
@@ -1140,13 +1141,16 @@
     SV x2;
     switch (tok) {
     case T.push:
-      return (len == 2 && mp.addX(x1.pushPop(args[1], args[0])) || len == 1 && 
mp.addX(x1.pushPop(args[0], null)));
+      return (len == 2 && mp.addX(x1.pushPop(args[1], args[0])) || len == 1
+          && mp.addX(x1.pushPop(args[0], null)));
     case T.pop:
-      return (len == 1 && mp.addX(x1.pushPop(null, args[0])) || len == 0 && 
mp.addX(x1.pushPop(null, null)));
+      return (len == 1 && mp.addX(x1.pushPop(null, args[0])) || len == 0
+          && mp.addX(x1.pushPop(null, null)));
     case T.add:
       if (len != 1 && len != 2)
         return false;
       break;
+    case T.split:
     case T.join:
       break;
     default:
@@ -1156,14 +1160,89 @@
     String[] sList1 = null, sList2 = null, sList3 = null;
 
     if (len == 2) {
-      // [xxxx].add("\t", [...])
+      // [...].add("\t", [...])
+      // [...].split("\t", true) [split individual elements as strings]
+      // [...].split("", true) [CSV split]
+      // [...][...].join("x", true) [2D-array line join]
+      // [...][...].join("", true)  [CSV join]
       int itab = (args[0].tok == T.string ? 0 : 1);
       String tab = SV.sValue(args[itab]);
-      sList1 = (isArray1 ? SV.strListValue(x1) : PT.split(SV.sValue(x1),
-          "\n"));
+      if (len == 2) {
+        Lst<SV> l = x1.getList();
+        boolean isCSV = (tab.length() == 0);
+        if (isCSV)
+          tab = ",";
+        if (tok == T.join) {
+          SV[] s2 = new SV[l.size()];
+          for (int i = l.size(); --i >= 0;) {
+            Lst<SV> a = l.get(i).getList();
+            if (a == null)
+              s2[i] = l.get(i);
+            else {
+              SB sb = new SB();
+              for (int j = 0, n = a.size(); j < n; j++) {
+                if (j > 0)
+                  sb.append(tab);
+                SV sv = a.get(j);
+                sb.append(isCSV && sv.tok == T.string ? "\"" + PT.rep(
+                    (String) sv.value, "\"", "\"\"") + "\"" 
+                    : "" + sv.asString());
+              }
+              s2[i] = SV.newS(sb.toString());
+            }
+          }
+          return mp.addXAV(s2);
+        }
+        SV[] sa = new SV[l.size()];
+        if (isCSV)
+          tab = "\0";
+        int[] next = new int[2];
+        for (int i = l.size(); --i >= 0;) {
+          String line = l.get(i).asString();
+          if (isCSV) {
+            next[1] = 0;
+            next[0] = 0;
+            int last = 0;
+            while (true) {
+              String s = PT.getCSVString(line, next);
+              if (s == null) {
+                line = line.substring(0, last)
+                    + line.substring(last).replace(',', '\0');
+                break;
+              }
+              line = line.substring(0, last)
+                  + line.substring(last, next[0]).replace(',', '\0') + s
+                  + line.substring(next[1]);
+              next[1] = last = next[0] + s.length();
+            }
+          }
+          String[] linaa = line.split(tab);
+          Lst<SV> la = new Lst<SV>();
+          for (int j = 0, n = linaa.length; j < n; j++) {
+            String s = linaa[j];
+            if (s.indexOf(".") < 0)
+              try {
+                la.addLast(SV.newI(Integer.parseInt(s)));
+                continue;
+              } catch (Exception e) {
+              }
+            else
+              try {
+                la.addLast(SV.getVariable(Float.valueOf(Float.parseFloat(s))));
+                continue;
+              } catch (Exception ee) {
+              }
+            la.addLast(SV.newS(s));
+          }
+          sa[i] = SV.getVariableList(la);
+        }
+        return mp.addXObj(SV.getVariable(sa));
+      }
+
+      sList1 = (isArray1 ? SV.strListValue(x1) : PT.split(SV.sValue(x1), 
"\n"));
       x2 = args[1 - itab];
-      sList2 = (x2.tok == T.varray ? SV.strListValue(x2) : 
PT.split(SV.sValue(x2),
-          "\n"));
+      sList2 = (x2.tok == T.varray ? SV.strListValue(x2) : PT.split(
+          SV.sValue(x2), "\n"));
       sList3 = new String[len = Math.max(sList1.length, sList2.length)];
       for (int i = 0; i < len; i++)
         sList3[i] = (i >= sList1.length ? "" : sList1[i]) + tab
@@ -1230,7 +1309,7 @@
 
     SV[] olist = new SV[len];
     if (isArray1 && isAll) {
-      Lst<SV>  llist = new Lst<SV>();
+      Lst<SV> llist = new Lst<SV>();
       return mp.addXList(addAllLists(x1.getList(), llist));
     }
     SV a = (isScalar1 ? x1 : null);
@@ -1926,6 +2005,17 @@
         m4.getColumn(n, f);
         return mp.addXAF(f);
       }
+    case T.varray:
+      // column of a[][]
+      Lst<SV> l1 = x1.getList();
+      Lst<SV> l2 = new Lst<SV>();
+      for (int i = 0, len = l1.size(); i < len; i++) {
+        Lst<SV> l3 = l1.get(i).getList();
+        if (l3 == null)
+          return mp.addXStr("");
+        l2.addLast(n < l3.size() ? l3.get(n) : SV.newS(""));   
+      }
+      return mp.addXList(l2);
     }
     return false;
 
@@ -2086,17 +2176,31 @@
 
   private boolean evaluateString(ScriptMathProcessor mp, int tok, SV[] args)
       throws ScriptException {
-    if (args.length > 1)
-      return false;
     SV x = mp.getX();
-    if (x.tok == T.varray && tok != T.split && tok != T.trim) {
+    String sArg = (args.length > 0 ? SV.sValue(args[0]) : tok == T.trim ? ""
+        : "\n");
+    switch (args.length) {
+    case 0:
+    case 1:
+      break;
+    case 2:
+      if (x.tok == T.varray)
+        break;
+      if (tok == T.split) {
+        x = SV.getVariable(PT.split(PT.rep((String) x.value, "\n\r", 
"\n").replace('\r', '\n'), "\n"));
+        break;
+      }
+      //$FALL-THROUGH$
+    default:
+      return false;      
+    }
+      
+    if (x.tok == T.varray && tok != T.trim && (tok != T.split || args.length 
== 2)) {
       mp.addX(x);
       return evaluateList(mp, tok, args);
     }
-    String s = (tok == T.split && x.tok == T.bitset || tok == T.trim
-        && x.tok == T.varray ? null : SV.sValue(x));
-    String sArg = (args.length == 1 ? SV.sValue(args[0]) : tok == T.trim ? ""
-        : "\n");
+    String s = (tok == T.split && x.tok == T.bitset 
+        || tok == T.trim && x.tok == T.varray ? null : SV.sValue(x));
     switch (tok) {
     case T.split:
       if (x.tok == T.bitset) {
@@ -2110,7 +2214,7 @@
           bs.and(bsSelected);
           s += Escape.eBS(bs);
         }
-      }
+      }      
       return mp.addXAS(PT.split(s, sArg));
     case T.join:
       if (s.length() > 0 && s.charAt(s.length() - 1) == '\n')

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2014-12-02 13:02:46 UTC 
(rev 20154)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2014-12-05 04:03:24 UTC 
(rev 20155)
@@ -17,6 +17,7 @@
 
 Jmol.___JmolVersion="14.3.11_2014.12.02"
 
+bug fix: for (x in yUpperCase) fails
 bug fix: draw SYMOP fails for incommensurate space groups
 bug fix: incommensurate magnetic CIF reading does not apply magnetic spin 
operation to spin modulations
 bug fix: CIF reader can cycle infinitely if loop_ keywords are not followed by 
any data
@@ -29,6 +30,8 @@
 new feature: readers for ESS input types: CFILE, VFILE, MOPAC, NWChem, 
Gaussian, GAMESS, Orca, PQS
   -- CFILE and VFILE require CFI:: and VFI:: (or C:: and V::)
   -- MOPAC requires MND::  
+  -- any of these could also use ZMATRIX:: or INPUT::
+  
 
 bug fix: dynamicMeasurements deprecated in 14.1.1 but 
          not left in as a valid token to allow use
@@ -45,6 +48,8 @@
 
 released as 14.3.10
 
+(note - these were not fixed in 14.2)
+
 bug fix: SPIN BRANCH {atomno=2} {atomno=1}   does not work
 
 code: scriptExt.IsoExt splits CmdExt into two parts 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to