Esempio n. 1
0
        public void ValidateFloat()
        {
            try
            {
                int numLength = _unmanagedWriteBuffer.SizeInBytes;
                var tmpBuff   = stackalloc byte[numLength];
                _unmanagedWriteBuffer.CopyTo(tmpBuff);
                _ctx.ParseDouble(tmpBuff, numLength);
            }
#pragma warning disable RDB0004 // Exception handler is empty or just logging
            catch (Exception e)
            {
                ThrowException("Could not parse double", e);
            }
#pragma warning restore RDB0004 // Exception handler is empty or just logging
        }
Esempio n. 2
0
        public void ValidateFloat()
        {
            if (_unmanagedWriteBuffer.SizeInBytes > 100)
            {
                ThrowException("Too many characters in double: " + _unmanagedWriteBuffer.SizeInBytes);
            }

            if (_doubleStringBuffer == null || _unmanagedWriteBuffer.SizeInBytes > _doubleStringBuffer.Length)
            {
                _doubleStringBuffer = new string(' ', _unmanagedWriteBuffer.SizeInBytes);
            }

            var tmpBuff = stackalloc byte[_unmanagedWriteBuffer.SizeInBytes];

            // here we assume a clear char <- -> byte conversion, we only support
            // utf8, and those cleanly transfer
            fixed(char *pChars = _doubleStringBuffer)
            {
                int i = 0;

                _unmanagedWriteBuffer.CopyTo(tmpBuff);
                for (; i < _unmanagedWriteBuffer.SizeInBytes; i++)
                {
                    pChars[i] = (char)tmpBuff[i];
                }
                for (; i < _doubleStringBuffer.Length; i++)
                {
                    pChars[i] = ' ';
                }
            }

            try
            {
                // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                double.Parse(_doubleStringBuffer, NumberStyles.Any, CultureInfo.InvariantCulture);
            }
            catch (Exception e)
            {
                ThrowException("Could not parse double", e);
            }
        }