From 84820486d5d9864e40a9639d4be7c11232ccacbb Mon Sep 17 00:00:00 2001 From: Remco Bouckaert Date: Fri, 28 Jun 2024 11:02:33 +1200 Subject: [PATCH] deal with spaces in quoted attribute values #30 --- src/beast/base/parser/NexusParser.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/beast/base/parser/NexusParser.java b/src/beast/base/parser/NexusParser.java index f96fbee8..7c10b6a3 100644 --- a/src/beast/base/parser/NexusParser.java +++ b/src/beast/base/parser/NexusParser.java @@ -1,6 +1,7 @@ package beast.base.parser; + import java.io.*; import java.util.*; import java.util.regex.Matcher; @@ -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; }