Skip to content

Commit 23baae9

Browse files
committed
Ignore prefix underscore on R labels.
1 parent 9e7cb8f commit 23baae9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

storage/smiles/src/main/java/org/openscience/cdk/smiles/CxSmilesParser.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ private static boolean processAtomLabels(final CharIter iter, final Map<Integer,
7878
return true;
7979
} else {
8080
iter.pos--; // push back
81-
final int beg = iter.pos;
81+
int beg = iter.pos;
8282
int rollback = beg;
8383
while (iter.hasNext()) {
84+
85+
if (iter.pos == beg && iter.curr() == '_' &&
86+
iter.peek() == 'R') {
87+
++beg;
88+
}
89+
8490
// correct step over of escaped label
8591
if (iter.curr() == '&') {
8692
rollback = iter.pos;
@@ -677,6 +683,10 @@ char next() {
677683
return str.charAt(pos++);
678684
}
679685

686+
public char peek() {
687+
return pos < str.length() ? str.charAt(pos+1) : '\0';
688+
}
689+
680690

681691
/**
682692
* Access a substring from the iterator.

storage/smiles/src/test/java/org/openscience/cdk/smiles/CxSmilesParserTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public void atomLabelsTruncated3() {
8888
assertThat(CxSmilesParser.processCx("|$;;;Het;$", state), is(-1));
8989
}
9090

91+
@Test
92+
public void removeUnderscore() {
93+
CxSmilesState state = new CxSmilesState();
94+
CxSmilesParser.processCx("|$;;;_R1;$|", state);
95+
assertThat(state.atomLabels.get(3), is("R1"));
96+
}
97+
9198
@Test
9299
public void skipCis() {
93100
CxSmilesState state = new CxSmilesState();

0 commit comments

Comments
 (0)