Merge branch 'JAL-1378_jb2.1cli' into RNAalifold
[jalview.git] / src / jalview / io / NewickFile.java
index d664dcf..9ed1491 100755 (executable)
@@ -292,6 +292,7 @@ public class NewickFile extends FileParse
 
     int nextcp = 0;
     int ncp = cp;
+    boolean parsednodename=false;
     while (majorsyms.searchFrom(nf, cp) && (Error == null))
     {
       int fcp = majorsyms.matchedFrom();
@@ -349,14 +350,20 @@ public class NewickFile extends FileParse
       case '\'':
 
         com.stevesoft.pat.Regex qnodename = new com.stevesoft.pat.Regex(
-                "([^']|'')+'");
+                "'([^']|'')+'");
 
         if (qnodename.searchFrom(nf, fcp))
         {
           int nl = qnodename.stringMatched().length();
-          nodename = new String(qnodename.stringMatched().substring(0,
+          nodename = new String(qnodename.stringMatched().substring(1,
                   nl - 1));
-          cp = fcp + nl + 1;
+          // unpack any escaped colons
+          com.stevesoft.pat.Regex xpandquotes = com.stevesoft.pat.Regex.perlCode("s/''/'/");
+          String widernodename = xpandquotes.replaceAll(nodename);
+          nodename=widernodename;
+          // jump to after end of quoted nodename
+          nextcp = fcp + nl + 1;
+          parsednodename=true;
         }
         else
         {
@@ -425,7 +432,7 @@ public class NewickFile extends FileParse
         com.stevesoft.pat.Regex ndist = new com.stevesoft.pat.Regex(
                 ":([-0-9Ee.+]+)");
 
-        if (uqnodename.search(fstring)
+        if (!parsednodename && uqnodename.search(fstring)
                 && ((uqnodename.matchedFrom(1) == 0) || (fstring
                         .charAt(uqnodename.matchedFrom(1) - 1) != ':'))) // JBPNote
         // HACK!
@@ -584,6 +591,7 @@ public class NewickFile extends FileParse
         distance = DefDistance;
         bootstrap = DefBootstrap;
         commentString2 = null;
+        parsednodename=false;
       }
       if (nextcp == 0)
       {