From 4d482b803364f659f176d1d2409497b190125d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Kir=C3=A1ly?= Date: Sat, 17 Sep 2022 15:11:05 +0200 Subject: [PATCH] issue #164: PICA: Parsing PICA Plain with $ in field values --- .../gwdg/metadataqa/marc/utils/pica/PicaLine.java | 13 ++++++++++++- .../metadataqa/marc/utils/pica/PicaLineTest.java | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/gwdg/metadataqa/marc/utils/pica/PicaLine.java b/src/main/java/de/gwdg/metadataqa/marc/utils/pica/PicaLine.java index dd5e063d3..b36703516 100644 --- a/src/main/java/de/gwdg/metadataqa/marc/utils/pica/PicaLine.java +++ b/src/main/java/de/gwdg/metadataqa/marc/utils/pica/PicaLine.java @@ -17,6 +17,7 @@ public class PicaLine { private static final String EINGABE = "Eingabe"; private static final String WARNUNG = "Warnung"; private String subfieldSeparator = DEFAULT_SEPARATOR; + private static String DOLLAR_REPLACEMENT = "%26%26"; private String tag; private String occurrence; @@ -107,9 +108,19 @@ private void parse(String raw) { private void parseSubfields() { subfields = new ArrayList<>(); - String[] parts = content.split(Pattern.quote(subfieldSeparator)); + boolean dollarReplacement = false; + String[] parts = null; + if (subfieldSeparator.equals("$") && content.contains("$$")) { + dollarReplacement = true; + parts = content.replace("$$", DOLLAR_REPLACEMENT).split(Pattern.quote(subfieldSeparator)); + } else { + parts = content.split(Pattern.quote(subfieldSeparator)); + } for (String part : parts) { if (StringUtils.isNotBlank(part)) { + if (dollarReplacement) { + part = part.replace(DOLLAR_REPLACEMENT, "$"); + } subfields.add(new PicaSubfield(part.substring(0, 1), part.substring(1))); } } diff --git a/src/test/java/de/gwdg/metadataqa/marc/utils/pica/PicaLineTest.java b/src/test/java/de/gwdg/metadataqa/marc/utils/pica/PicaLineTest.java index 541358d2e..ee71f269b 100644 --- a/src/test/java/de/gwdg/metadataqa/marc/utils/pica/PicaLineTest.java +++ b/src/test/java/de/gwdg/metadataqa/marc/utils/pica/PicaLineTest.java @@ -86,4 +86,10 @@ public void defaultSeparator() { assertEquals("$", PicaLine.DEFAULT_SEPARATOR); } + + @Test + public void dollarsign() { + PicaLine line = new PicaLine("005A $00263-9254$f: L 230.00 (jährl., EU), $$ 435.00 (jährl.)"); + assertEquals(": L 230.00 (jährl., EU), $ 435.00 (jährl.)", line.getSubfields().get(1).getValue()); + } }