예제 #1
0
 /// <summary>
 /// Initializes a new instance of a FixedLengthParserOptions.
 /// </summary>
 public FixedLengthOptions()
 {
     FillCharacter      = ' ';
     alignment          = FixedAlignment.LeftAligned;
     HasRecordSeparator = true;
     truncationPolicy   = OverflowTruncationPolicy.TruncateLeading;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of a Window.
 /// </summary>
 /// <param name="width">The maximum possible width of the column.</param>
 public Window(int width)
 {
     if (width < 0)
     {
         throw new ArgumentOutOfRangeException("width", width, SharedResources.InvalidColumnWidth);
     }
     this.width = width;
     this.alignment = FixedAlignment.LeftAligned;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of a Window.
 /// </summary>
 /// <param name="width">The maximum possible width of the column.</param>
 public Window(int width)
 {
     if (width < 0)
     {
         throw new ArgumentOutOfRangeException("width", width, Resources.InvalidColumnWidth);
     }
     this.width     = width;
     this.alignment = FixedAlignment.LeftAligned;
 }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <param name="alignment"></param>
        /// <param name="padding"></param>
        /// <returns></returns>
        public static byte[] GetFixedBytes(string str, int length, FixedAlignment alignment, byte padding)
        {
            var bytes = Instance.GetBytes(str);
            if (bytes.Length == length)
            {
                return bytes;
            }

            if (bytes.Length > length)
            {
                // 切り捨て
                var newBytes = new byte[length];
                if (((bytes[length - 1] >= 0x81) && (bytes[length - 1] <= 0x9f)) ||
                    ((bytes[length - 1] >= 0xe0) && (bytes[length - 1] <= 0xfc)))
                {
                    Buffer.BlockCopy(bytes, 0, newBytes, 0, length - 1);
                    newBytes[length - 1] = padding;
                }
                else
                {
                    Buffer.BlockCopy(bytes, 0, newBytes, 0, length);
                }

                return newBytes;
            }
            else
            {
                // パディング
                var newBytes = new byte[length];
                if (alignment == FixedAlignment.Left)
                {
                    Buffer.BlockCopy(bytes, 0, newBytes, 0, bytes.Length);
                    for (var i = bytes.Length; i < length; i++)
                    {
                        newBytes[i] = padding;
                    }
                }
                else if (alignment == FixedAlignment.Right)
                {
                    var i = 0;
                    for (; i < length - bytes.Length; i++)
                    {
                        newBytes[i] = padding;
                    }

                    Buffer.BlockCopy(bytes, 0, newBytes, i, bytes.Length);
                }
                else
                {
                    var i = 0;
                    for (; i < (length - bytes.Length) / 2; i++)
                    {
                        newBytes[i] = padding;
                    }

                    Buffer.BlockCopy(bytes, 0, newBytes, i, bytes.Length);
                    for (i = i + bytes.Length; i < length; i++)
                    {
                        newBytes[i] = padding;
                    }
                }

                return newBytes;
            }
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="str"></param>
 /// <param name="length"></param>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public static byte[] GetFixedBytes(string str, int length, FixedAlignment alignment)
 {
     return GetFixedBytes(str, length, alignment, 0x20);
 }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <param name="alignment"></param>
        /// <param name="padding"></param>
        /// <returns></returns>
        public static byte[] GetFixedBytes(string str, int length, FixedAlignment alignment, byte padding)
        {
            var bytes = Instance.GetBytes(str);

            if (bytes.Length == length)
            {
                return(bytes);
            }

            if (bytes.Length > length)
            {
                // 切り捨て
                var newBytes = new byte[length];
                if (((bytes[length - 1] >= 0x81) && (bytes[length - 1] <= 0x9f)) ||
                    ((bytes[length - 1] >= 0xe0) && (bytes[length - 1] <= 0xfc)))
                {
                    Buffer.BlockCopy(bytes, 0, newBytes, 0, length - 1);
                    newBytes[length - 1] = padding;
                }
                else
                {
                    Buffer.BlockCopy(bytes, 0, newBytes, 0, length);
                }

                return(newBytes);
            }
            else
            {
                // パディング
                var newBytes = new byte[length];
                if (alignment == FixedAlignment.Left)
                {
                    Buffer.BlockCopy(bytes, 0, newBytes, 0, bytes.Length);
                    for (var i = bytes.Length; i < length; i++)
                    {
                        newBytes[i] = padding;
                    }
                }
                else if (alignment == FixedAlignment.Right)
                {
                    var i = 0;
                    for (; i < length - bytes.Length; i++)
                    {
                        newBytes[i] = padding;
                    }

                    Buffer.BlockCopy(bytes, 0, newBytes, i, bytes.Length);
                }
                else
                {
                    var i = 0;
                    for (; i < (length - bytes.Length) / 2; i++)
                    {
                        newBytes[i] = padding;
                    }

                    Buffer.BlockCopy(bytes, 0, newBytes, i, bytes.Length);
                    for (i = i + bytes.Length; i < length; i++)
                    {
                        newBytes[i] = padding;
                    }
                }

                return(newBytes);
            }
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="str"></param>
 /// <param name="length"></param>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public static byte[] GetFixedBytes(string str, int length, FixedAlignment alignment)
 {
     return(GetFixedBytes(str, length, alignment, 0x20));
 }