예제 #1
0
        /// <summary>
        /// Converts a hex string at the specified index and length of <paramref name="hex"/>
        /// into an <see cref="int"/>.
        /// <para/>
        /// NOTE: This was hexToInt() in Lucene
        /// </summary>
        /// <param name="hex">
        /// A string in capital or lower case hex, of no more then 16
        /// characters.
        /// </param>
        /// <param name="startIndex">The index of the first character to begin parsing.</param>
        /// <param name="length">The number of characters to parse.</param>
        /// <exception cref="FormatException">if the string is more than 16 characters long, or if any
        /// character is not in the set [0-9a-fA-f]</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="startIndex"/> or <paramref name="length"/> is less than zero.
        /// <para/>
        /// -or-
        /// <para/>
        /// <paramref name="startIndex"/> and <paramref name="length"/> refer to a location outside of <paramref name="hex"/>.
        /// </exception>
        // LUCENENET specific overload
        public static int HexToInt32(string hex, int startIndex, int length)
        {
            if ((length > 16) || !Integer.TryParse(hex, startIndex, length, radix: 16, out int result))
            {
                throw NumberFormatException.Create();
            }

            return(result);
        }
예제 #2
0
        internal static int Get(int i, string s)
        {
            // LUCENENET: Optimized so we don't alocate a substring
            if (!Integer.TryParse(s, i, 1, radix: 10, out int result))
            {
                return(1);
            }

            return(result);
        }