Skip to content

Commit 07caf47

Browse files
committed
'H+' is also okay
1 parent 56777bc commit 07caf47

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

tool/formula/src/main/java/org/openscience/cdk/tools/manipulator/MolecularFormulaManipulator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ private static IMolecularFormula getMolecularFormula(String stringMF, IMolecular
750750

751751
// Extract charge from String when contains []X- format
752752
Integer charge = null;
753-
if ((stringMF.contains("[") && stringMF.contains("]")) && (stringMF.contains("+") || stringMF.contains(HYPHEN_STR) || stringMF.contains(MINUS_STR))) {
753+
if ((stringMF.contains("+") || stringMF.contains(HYPHEN_STR) || stringMF.contains(MINUS_STR))) {
754754
int pos = findChargePosition(stringMF);
755-
if (pos >= 0) {
755+
if (pos >= 0 && pos != stringMF.length()) {
756756
charge = parseCharge(new CharIter(pos, stringMF));
757757
stringMF = stringMF.substring(0, pos);
758758
if (stringMF.charAt(0) == '[' &&
@@ -827,7 +827,6 @@ private static int findChargePosition(String formula) {
827827
pos--;
828828
if (pos == mark2 && formula.charAt(pos) != ']')
829829
pos = mark1; // not a charge CH3- we sucked up a number
830-
if (pos == 0) return -1;
831830
return pos+1;
832831
}
833832

tool/formula/src/test/java/org/openscience/cdk/tools/manipulator/MolecularFormulaManipulatorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,5 +1481,6 @@ public void roundtrip(String mfStr, String expected) {
14811481
roundtrip("[2]H2+", "[[2]H2]+");
14821482
// +2 => 2+ with brackets
14831483
roundtrip("[2H]2+2", "[[2]H2]2+");
1484+
roundtrip("H+", "[H]+");
14841485
}
14851486
}

0 commit comments

Comments
 (0)