Revision: 18342
          http://sourceforge.net/p/jmol/code/18342
Author:   hansonr
Date:     2013-06-17 13:54:46 +0000 (Mon, 17 Jun 2013)
Log Message:
-----------
TextFormat.simpleReplace upgrade

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/adapter/readers/xtal/VaspOutcarReader.java
    trunk/Jmol/src/org/jmol/io/XmlUtil.java
    trunk/Jmol/src/org/jmol/util/TextFormat.java
    trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java

Modified: trunk/Jmol/src/org/jmol/adapter/readers/xtal/VaspOutcarReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/xtal/VaspOutcarReader.java  
2013-06-17 01:12:50 UTC (rev 18341)
+++ trunk/Jmol/src/org/jmol/adapter/readers/xtal/VaspOutcarReader.java  
2013-06-17 13:54:46 UTC (rev 18342)
@@ -110,7 +110,7 @@
     while (readLine() != null && line.indexOf("VRHFIN") < 0) {
       int pt = (line.contains("_") ? 2 : 1);
       if (pt == 2)
-        line = line.replace("_", " ");
+        line = line.replace('_', ' ');
       String[] tokens = getTokensStr(line.substring(line.indexOf(":") + 1));
       String sym = tokens[pt];
       String key = ";" + sym + ";";

Modified: trunk/Jmol/src/org/jmol/io/XmlUtil.java
===================================================================
--- trunk/Jmol/src/org/jmol/io/XmlUtil.java     2013-06-17 01:12:50 UTC (rev 
18341)
+++ trunk/Jmol/src/org/jmol/io/XmlUtil.java     2013-06-17 13:54:46 UTC (rev 
18342)
@@ -109,7 +109,7 @@
    */
   public static String unwrapCdata(String s) {
     return (s.startsWith("<![CDATA[") && s.endsWith("]]>") ?
-        s.substring(9, s.length()-3).replace("]]]]><![CDATA[>", "]]>") : s);
+        TextFormat.simpleReplace(s.substring(9, 
s.length()-3),"]]]]><![CDATA[>", "]]>") : s);
   }
   
   /**

Modified: trunk/Jmol/src/org/jmol/util/TextFormat.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/TextFormat.java        2013-06-17 01:12:50 UTC 
(rev 18341)
+++ trunk/Jmol/src/org/jmol/util/TextFormat.java        2013-06-17 13:54:46 UTC 
(rev 18342)
@@ -561,39 +561,33 @@
   }
   
   /**
-   * Does a clean replace of strFrom in str with strTo
-   * If strTo contains strFrom, then only a single pass is done.
-   * Otherwise, multiple passes are made until no more replacements can be 
made.
+   * 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!)
    * 
    * @param str
    * @param strFrom
    * @param strTo
-   * @return  replaced string
+   * @return replaced string
    */
   public static String simpleReplace(String str, String strFrom, String strTo) 
{
-    if (str == null || str.indexOf(strFrom) < 0 || strFrom.equals(strTo))
-      return str;
-    int fromLength = strFrom.length();
-    if (fromLength == 0)
-      return str;
-    boolean isOnce = (strTo.indexOf(strFrom) >= 0);
-    int ipt;
-    while (str.indexOf(strFrom) >= 0) {
-      SB s = new SB();
-      int ipt0 = 0;
-      while ((ipt = str.indexOf(strFrom, ipt0)) >= 0) {
-        s.append(str.substring(ipt0, ipt)).append(strTo);
-        ipt0 = ipt + fromLength;
-      }
-      s.append(str.substring(ipt0));
-      str = s.toString();
-      if (isOnce)
-        break;
-    }
-
-    return str;
+    return (str == null || strFrom.length() == 0 || str.indexOf(strFrom) < 0
+        ? str : str.replace(strFrom, strTo));
   }
 
+//  static {
+//    long t = System.currentTimeMillis();
+//    for (int i = 0; i < 100000; i++)
+//      simpleReplace("2329823jadf", "a", "b");
+//    System.out.println(System.currentTimeMillis() - t);
+//    t = System.currentTimeMillis();
+//    for (int i = 0; i < 100000; i++)
+//      "2329823jadf".replace("a", "b");
+//    System.out.println(System.currentTimeMillis() - t);
+//  }
+  
   public static String trim(String str, String chars) {
     if (chars.length() == 0)
       return str.trim();

Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java
===================================================================
--- trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java        
2013-06-17 01:12:50 UTC (rev 18341)
+++ trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java        
2013-06-17 13:54:46 UTC (rev 18342)
@@ -96,7 +96,8 @@
           }
           widgetDefs += "<td>"
               + theWidgets.widgetList[j].getJavaScript(0, instance)
-                  .replace("'", "\'") + "</td>";
+                  //does nothing? .replace("'", "\'")
+                  + "</td>";
           row = row + 1;
         }
       }

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


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to