Beispiel #1
0
        public void GetAsDigit()
        {
            CharBuffer buffer = CharBuffer.FromString("c1");

            Assert.IsFalse(buffer.NextIsDigit());
            Assert.AreEqual(buffer.Get(), 'c');
            Assert.IsTrue(buffer.NextIsDigit());
            Assert.AreEqual(buffer.GetAsDigit(), 1);
            Assert.IsFalse(buffer.NextIsDigit());
        }
Beispiel #2
0
 /// <summary>
 /// Internal method for parsing charge, to allow concatenated signs (--, ++)
 /// the method recursively invokes increment or decrementing an accumulator.
 /// </summary>
 /// <param name="acc">   accumulator</param>
 /// <param name="buffer">a character buffer</param>
 /// <returns>the charge value</returns>
 private static int ReadCharge(int acc, CharBuffer buffer)
 {
     if (buffer.GetIf('+'))
     {
         return(buffer.NextIsDigit() ? acc + buffer.GetNumber()
                                     : ReadCharge(acc + 1, buffer));
     }
     if (buffer.GetIf('-'))
     {
         return(buffer.NextIsDigit() ? acc - buffer.GetNumber()
                                     : ReadCharge(acc - 1, buffer));
     }
     return(acc);
 }
Beispiel #3
0
 /// <summary>
 /// Read the atom class of a bracket atom and progress the buffer (if read).
 /// The atom class is the last attribute of the bracket atom and is
 /// identified by a ':' followed by one or more digits. The atom class may be
 /// padded such that ':005' and ':5' are equivalent.
 /// </summary>
 /// <seealso href="http://www.opensmiles.org/opensmiles.html#atomclass">Atom Class - OpenSMILES Specification</seealso >
 /// <param name="buffer">a character buffer</param>
 /// <returns>the atom class, or 0</returns>
 public static int ReadClass(CharBuffer buffer)
 {
     if (buffer.GetIf(':'))
     {
         if (buffer.NextIsDigit())
         {
             return(buffer.GetNumber());
         }
         throw new InvalidSmilesException("invalid atom class, <digit>+ must follow ':'", buffer);
     }
     return(0);
 }