Skip to content

Commit

Permalink
deal with spaces in quoted attribute values #30
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Jun 27, 2024
1 parent c9d41d9 commit 8482048
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/beast/base/parser/NexusParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package beast.base.parser;



import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -1385,6 +1386,24 @@ protected String getAttValue(final String attribute, final String str) {
if (att.startsWith("\"") && att.endsWith("\"")) {
final int start = matcher.start(1);
att = str.substring(start + 1, str.indexOf('"', start + 1));
} else if (att.startsWith("\"")) { // but does not end with quote!

// we are looking for the end quote
int i = str.indexOf(attribute);
i += attribute.length();
// find start quote
i = str.indexOf('"', i);
if (i < 0) {
return att;
}
i++;
// find end quote
int j = str.indexOf('"', i);
if (j < 0) {
return att;
}
// remove spaces
att = str.substring(i, j).replaceAll("\\s", "");
}
return att;
}
Expand Down

0 comments on commit 8482048

Please sign in to comment.