Ejemplo n.º 1
0
        /// <summary>
        /// 是否为空值
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns></returns>
        public virtual bool IsNullValue(ArraySegmentValue buffer)
        {
            if (buffer.Length == 4 && buffer[1] <= 'u' &&
                (buffer[0] == 'n' || buffer[0] == 'N') &&
                (buffer[1] == 'u' || buffer[1] == 'U') &&
                (buffer[2] == 'l' || buffer[2] == 'L') &&
                (buffer[3] == 'l' || buffer[3] == 'L'))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取有符号的数值
        /// </summary>
        /// <param name="buffer">值数组</param>
        /// <param name="minus">是否为负数</param>
        /// <param name="max">最大值</param>
        /// <param name="min">最小值</param>
        /// <param name="bufferLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
        /// <returns></returns>
        public static long ParseGigit(ArraySegmentValue buffer, bool minus, long max, long min, int bufferLength)
        {
            if (buffer.IsEmpty)
            {
                return(0);
            }

            long result = 0;

            if (minus)
            {
                var minu = min == long.MinValue ? 9223372036854775807 : -min;
                for (var i = 1; i < bufferLength; i++)
                {
                    switch (buffer[i])
                    {
                    case '0':
                    case '\x0':
                    {
                        result += (long)GetInteger(bufferLength - i) * 0;
                    }
                    break;

                    case '1':
                    case '\x1':
                    {
                        result += (long)GetInteger(bufferLength - i) * 1;
                    }
                    break;

                    case '2':
                    case '\x2':
                    {
                        result += (long)GetInteger(bufferLength - i) * 2;
                    }
                    break;

                    case '3':
                    case '\x3':
                    {
                        result += (long)GetInteger(bufferLength - i) * 3;
                    }
                    break;

                    case '4':
                    case '\x4':
                    {
                        result += (long)GetInteger(bufferLength - i) * 4;
                    }
                    break;

                    case '5':
                    case '\x5':
                    {
                        result += (long)GetInteger(bufferLength - i) * 5;
                    }
                    break;

                    case '6':
                    case '\x6':
                    {
                        result += (long)GetInteger(bufferLength - i) * 6;
                    }
                    break;

                    case '7':
                    case '\x7':
                    {
                        result += (long)GetInteger(bufferLength - i) * 7;
                    }
                    break;

                    case '8':
                    case '\x8':
                    {
                        result += (long)GetInteger(bufferLength - i) * 8;
                    }
                    break;

                    case '9':
                    case '\x9':
                    {
                        result += (long)GetInteger(bufferLength - i) * 9;
                    }
                    break;

                    default:
                    {
                        throw new ArgumentException("");
                    }
                    }

                    if (result > minu)
                    {
                        throw new ArgumentOutOfRangeException("");
                    }
                }

                return(-result);
            }

            for (var i = 0; i < bufferLength; i++)
            {
                switch (buffer[i])
                {
                case '0':
                case '\x0':
                {
                    result += (long)GetInteger(bufferLength - i) * 0;
                }
                break;

                case '1':
                case '\x1':
                {
                    result += (long)GetInteger(bufferLength - i) * 1;
                }
                break;

                case '2':
                case '\x2':
                {
                    result += (long)GetInteger(bufferLength - i) * 2;
                }
                break;

                case '3':
                case '\x3':
                {
                    result += (long)GetInteger(bufferLength - i) * 3;
                }
                break;

                case '4':
                case '\x4':
                {
                    result += (long)GetInteger(bufferLength - i) * 4;
                }
                break;

                case '5':
                case '\x5':
                {
                    result += (long)GetInteger(bufferLength - i) * 5;
                }
                break;

                case '6':
                case '\x6':
                {
                    result += (long)GetInteger(bufferLength - i) * 6;
                }
                break;

                case '7':
                case '\x7':
                {
                    result += (long)GetInteger(bufferLength - i) * 7;
                }
                break;

                case '8':
                case '\x8':
                {
                    result += (long)GetInteger(bufferLength - i) * 8;
                }
                break;

                case '9':
                case '\x9':
                {
                    result += (long)GetInteger(bufferLength - i) * 9;
                }
                break;

                default:
                {
                    throw new ArgumentException("");
                }
                }

                if (result > max)
                {
                    throw new ArgumentOutOfRangeException("");
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取无符号的数值
        /// </summary>
        /// <param name="buffer">值数组</param>
        /// <param name="max">最大值</param>
        /// <param name="bufferLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
        /// <returns></returns>
        public static ulong ParseUnsignedGigit(ArraySegmentValue buffer, ulong max, int bufferLength)
        {
            if (buffer.IsEmpty)
            {
                return(0);
            }

            if (buffer[0] == '-')
            {
                throw new ArgumentException("正数取值第一位不可能为'-'");
            }

            ulong result = 0;

            for (var i = 0; i < bufferLength; i++)
            {
                switch (buffer[i])
                {
                case '0':
                case '\x0':
                {
                    result += GetInteger(bufferLength - i) * 0;
                }
                break;

                case '1':
                case '\x1':
                {
                    result += GetInteger(bufferLength - i) * 1;
                }
                break;

                case '2':
                case '\x2':
                {
                    result += GetInteger(bufferLength - i) * 2;
                }
                break;

                case '3':
                case '\x3':
                {
                    result += GetInteger(bufferLength - i) * 3;
                }
                break;

                case '4':
                case '\x4':
                {
                    result += GetInteger(bufferLength - i) * 4;
                }
                break;

                case '5':
                case '\x5':
                {
                    result += GetInteger(bufferLength - i) * 5;
                }
                break;

                case '6':
                case '\x6':
                {
                    result += GetInteger(bufferLength - i) * 6;
                }
                break;

                case '7':
                case '\x7':
                {
                    result += GetInteger(bufferLength - i) * 7;
                }
                break;

                case '8':
                case '\x8':
                {
                    result += GetInteger(bufferLength - i) * 8;
                }
                break;

                case '9':
                case '\x9':
                {
                    result += GetInteger(bufferLength - i) * 9;
                }
                break;

                default:
                {
                    throw new ArgumentException("");
                }
                }

                if (result > max)
                {
                    throw new ArgumentOutOfRangeException("");
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取int的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static uint ParseUInt32(ArraySegmentValue buffer, int endLength)
 {
     return((uint)ParseUnsignedGigit(buffer, uint.MaxValue, endLength));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 获取int的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static ushort ParseUInt16(ArraySegmentValue buffer, int endLength)
 {
     return((ushort)ParseUnsignedGigit(buffer, ushort.MaxValue, endLength));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 获取long的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static ulong ParseUInt64(ArraySegmentValue buffer, int endLength)
 {
     return(ParseUnsignedGigit(buffer, ulong.MaxValue, endLength));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 获取int的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static byte ParseByte(ArraySegmentValue buffer, int endLength)
 {
     return((byte)ParseGigit(buffer, false, byte.MaxValue, byte.MinValue, endLength));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 获取int的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static short ParseInt16(ArraySegmentValue buffer, int endLength)
 {
     return((short)ParseGigit(buffer, buffer[0] == '-', short.MaxValue, short.MinValue, endLength));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 获取int的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static int ParseInt32(ArraySegmentValue buffer, int endLength)
 {
     return((int)ParseGigit(buffer, buffer[0] == '-', int.MaxValue, int.MinValue, endLength));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 获取long的数值
 /// </summary>
 /// <param name="buffer">值数组</param>
 /// <param name="endLength">数组长度,通常是buffer参数的长度,但由于一些空格原因,不会处理空格的</param>
 /// <returns></returns>
 public static long ParseInt64(ArraySegmentValue buffer, int endLength)
 {
     return(ParseGigit(buffer, buffer[0] == '-', long.MaxValue, long.MinValue, endLength));
 }