• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkiraly / metadata-qa-marc / #1527

22 Aug 2025 02:21PM UTC coverage: 90.345%. Remained the same
#1527

push

pkiraly
Improve timeline handling

5191 of 6416 new or added lines in 219 files covered. (80.91%)

886 existing lines in 78 files now uncovered.

36717 of 40641 relevant lines covered (90.34%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.33
/src/main/java/de/gwdg/metadataqa/marc/utils/marcspec/MarcSpecParser.java
1
package de.gwdg.metadataqa.marc.utils.marcspec;
2

3
import java.util.logging.Logger;
4
import java.util.regex.Matcher;
5
import java.util.regex.Pattern;
6

NEW
7
public class MarcSpecParser {
×
8
  private static final Logger logger = Logger.getLogger(MarcSpecParser.class.getCanonicalName());
1✔
9

10
  private static Pattern FIELD = Pattern.compile("^([A-Z\\d\\.]{3}|[a-z\\d\\.]{3})");
1✔
11
  private static Pattern INDICATOR = Pattern.compile("^\\^([12])");
1✔
12
  private static Pattern POSITION = Pattern.compile("^(/(\\d+|#)(?:-(\\d+|#))?)");
1✔
13
  // private static Pattern SUBFIELD = Pattern.compile("^(\\$(.)(?:-(.))?)");
14
  private static Pattern SUBFIELD = Pattern.compile("^(\\$(.))");
1✔
15
  private static Pattern INDEX = Pattern.compile("^(\\[(\\d+|#)(?:-(\\d+|#))?\\])");
1✔
16

17
  public static MarcSpec parse(String input) {
18
    MarcSpec spec = null;
1✔
19
    Subfield subfield = null;
1✔
20
    String context = "tag";
1✔
21
    Matcher matcher;
22
    while (input.length() > 0) {
1✔
23
      if (spec == null) {
1✔
24
        spec = new MarcSpec();
1✔
25
        matcher = FIELD.matcher(input);
1✔
26
        if (matcher.find()) {
1✔
27
          spec.setTag(matcher.group(1));
1✔
28
          input = input.substring(3, input.length());
1✔
29
        }
30
      } else {
31
        matcher = INDICATOR.matcher(input);
1✔
32
        if (matcher.find()) {
1✔
33
          String value = matcher.group(1);
1✔
34
          spec.setIndicator(value);
1✔
35
          if (input.length() > 2) {
1✔
NEW
36
            input = input.substring(2, input.length());
×
NEW
37
            continue;
×
38
          } else {
39
            break;
40
          }
41
        }
42

43
        matcher = SUBFIELD.matcher(input);
1✔
44
        if (matcher.find()) {
1✔
45
          String value = matcher.group(1);
1✔
46
          subfield = new Subfield(matcher.group(2));
1✔
47
          spec.getSubfields().add(subfield);
1✔
48
          context = "subfield";
1✔
49

50
          if (input.length() > value.length()) {
1✔
51
            input = input.substring(value.length(), input.length());
1✔
52
            continue;
1✔
53
          } else {
54
            break;
55
          }
56
        }
57

58
        matcher = POSITION.matcher(input);
1✔
59
        if (matcher.find()) {
1✔
60
          String value = matcher.group(1);
1✔
61
          Range position = new Range(matcher.group(2));
1✔
62
          if (matcher.group(3) != null)
1✔
63
            position.setEnd(matcher.group(3));
1✔
64

65
          if (context.equals("tag"))
1✔
66
            spec.setPosition(position);
1✔
67
          else
68
            subfield.setPosition(position);
1✔
69

70
          if (input.length() > value.length()) {
1✔
NEW
71
            input = input.substring(value.length(), input.length());
×
NEW
72
            continue;
×
73
          } else {
74
            break;
75
          }
76
        }
77

78
        matcher = INDEX.matcher(input);
1✔
79
        if (matcher.find()) {
1✔
80
          String value = matcher.group(1);
1✔
81
          Range index = new Range(matcher.group(2));
1✔
82
          if (matcher.group(3) != null)
1✔
83
            index.setEnd(matcher.group(3));
1✔
84
          if (context.equals("tag"))
1✔
85
            spec.setIndex(index);
1✔
86
          else
87
            subfield.setIndex(index);
1✔
88

89
          if (input.length() > value.length()) {
1✔
90
            input = input.substring(value.length(), input.length());
1✔
91
            continue;
1✔
92
          } else {
93
            break;
94
          }
95
        }
96

NEW
97
        logger.warning("unhandled part: " + input);
×
NEW
98
        break;
×
99
      }
100
    }
101
    return spec;
1✔
102
  }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc