Skip to content

Commit

Permalink
Minor tweak to correctly handle labels where the first character is e…
Browse files Browse the repository at this point in the history
…scaped.
  • Loading branch information
johnmay committed Jul 24, 2016
1 parent 241f4fe commit 26ed0ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Expand Up @@ -76,27 +76,29 @@ private static boolean processAtomLabels(final CharIter iter, final Map<Integer,
// end of atom label
return true;
} else {
final int beg = iter.pos - 1;
iter.pos--; // push back
final int beg = iter.pos;
int rollback = beg;
while (iter.hasNext()) {

// correct step over of escaped label
if (iter.curr() == '&') {
rollback = iter.pos;
if (iter.nextIf('&') && iter.nextIf('#') && iter.nextIfDigit()) {
while (iter.nextIfDigit()){} // more digits
if (!iter.nextIf(';'))
if (!iter.nextIf(';')) {
iter.pos = rollback;
} else {
}
} else {
iter.pos = rollback;
}
}

if (iter.curr() == ';')
else if (iter.curr() == ';')
break;
if (iter.curr() == '$')
else if (iter.curr() == '$')
break;
iter.next();
else
iter.next();
}
dest.put(atomIdx, unescape(iter.substr(beg, iter.pos)));
atomIdx++;
Expand Down
Expand Up @@ -53,6 +53,13 @@ public void escapedAtomLabels() {
assertThat(state.atomLabels, hasEntry(0, "R'"));
}

@Test
public void escapedAtomLabels2() {
CxSmilesState state = new CxSmilesState();
assertThat(CxSmilesParser.processCx("|$;;;&#40;C&#40;R41&#41;&#40;R41&#41;&#41;n;;R41;R41;R41;;_AP1;R41;R41;;_AP1$|", state), is(not(-1)));
assertThat(state.atomLabels, hasEntry(3, "(C(R41)(R41))n"));
}

@Test
public void atomValues() {
CxSmilesState state = new CxSmilesState();
Expand Down

0 comments on commit 26ed0ab

Please sign in to comment.