Ejemplo n.º 1
0
        public void testInt4_1()
        {
            Assert.AreEqual(0, RawParseUtils.parseHexInt4((byte)'0'));
            Assert.AreEqual(1, RawParseUtils.parseHexInt4((byte)'1'));
            Assert.AreEqual(2, RawParseUtils.parseHexInt4((byte)'2'));
            Assert.AreEqual(3, RawParseUtils.parseHexInt4((byte)'3'));
            Assert.AreEqual(4, RawParseUtils.parseHexInt4((byte)'4'));
            Assert.AreEqual(5, RawParseUtils.parseHexInt4((byte)'5'));
            Assert.AreEqual(6, RawParseUtils.parseHexInt4((byte)'6'));
            Assert.AreEqual(7, RawParseUtils.parseHexInt4((byte)'7'));
            Assert.AreEqual(8, RawParseUtils.parseHexInt4((byte)'8'));
            Assert.AreEqual(9, RawParseUtils.parseHexInt4((byte)'9'));
            Assert.AreEqual(10, RawParseUtils.parseHexInt4((byte)'a'));
            Assert.AreEqual(11, RawParseUtils.parseHexInt4((byte)'b'));
            Assert.AreEqual(12, RawParseUtils.parseHexInt4((byte)'c'));
            Assert.AreEqual(13, RawParseUtils.parseHexInt4((byte)'d'));
            Assert.AreEqual(14, RawParseUtils.parseHexInt4((byte)'e'));
            Assert.AreEqual(15, RawParseUtils.parseHexInt4((byte)'f'));

            Assert.AreEqual(10, RawParseUtils.parseHexInt4((byte)'A'));
            Assert.AreEqual(11, RawParseUtils.parseHexInt4((byte)'B'));
            Assert.AreEqual(12, RawParseUtils.parseHexInt4((byte)'C'));
            Assert.AreEqual(13, RawParseUtils.parseHexInt4((byte)'D'));
            Assert.AreEqual(14, RawParseUtils.parseHexInt4((byte)'E'));
            Assert.AreEqual(15, RawParseUtils.parseHexInt4((byte)'F'));

            assertNotHex('q');
            assertNotHex(' ');
            assertNotHex('.');
        }
Ejemplo n.º 2
0
        ///	<summary>
        /// Test a string of characters to verify it is a hex format.
        ///	<para />
        ///	If true the string can be parsed with <seealso cref="FromString(string)"/>.
        ///	</summary>
        ///	<param name="id">the string to test.</param>
        ///	<returns> true if the string can converted into an <see cref="ObjectId"/>.
        /// </returns>
        public static bool IsId(string id)
        {
            if (id.Length != Constants.OBJECT_ID_STRING_LENGTH)
            {
                return(false);
            }

            try
            {
                for (int i = 0; i < Constants.OBJECT_ID_STRING_LENGTH; i++)
                {
                    RawParseUtils.parseHexInt4((byte)id[i]);
                }

                return(true);
            }
            catch (IndexOutOfRangeException)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        ///	<summary>
        /// Test a string of characters to verify it is a hex format.
        ///	<para />
        ///	If true the string can be parsed with <seealso cref="FromString(string)"/>.
        ///	</summary>
        ///	<param name="id">the string to test.</param>
        ///	<returns> true if the string can converted into an <see cref="ObjectId"/>.
        /// </returns>
        public static bool IsId(string id)
        {
            if (id.Length != 2 * ObjectIdLength)
            {
                return(false);
            }

            try
            {
                for (int i = 0; i < StringLength; i++)
                {
                    RawParseUtils.parseHexInt4((byte)id[i]);
                }

                return(true);
            }
            catch (IndexOutOfRangeException)
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 private static void assertNotHex(char c)
 {
     AssertHelper.Throws <IndexOutOfRangeException>(() => RawParseUtils.parseHexInt4((byte)c));
 }