示例#1
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="StringCollection" /> by converting a collection of
 ///    <see cref="ByteVector" /> objects to strings with a
 ///    specified encoding.
 /// </summary>
 /// <param name="vectorList">
 ///    A <see cref="ByteVectorCollection" /> object containing
 ///    values to convert and add to the new instance.
 /// </param>
 /// <param name="type">
 ///    A <see cref="StringType" /> specifying what encoding to
 ///    use when converting the data to strings.
 /// </param>
 public StringCollection(ByteVectorCollection vectorList,
                         StringType type)
 {
     foreach (ByteVector vector in vectorList)
     {
         Add(vector.ToString(type));
     }
 }
示例#2
0
        /// <summary>
        ///    Splits a <see cref="ByteVector" /> object using a
        ///    pattern.
        /// </summary>
        /// <param name="vector">
        ///    A <see cref="ByteVector"/> object to split.
        /// </param>
        /// <param name="pattern">
        ///    A <see cref="ByteVector"/> object to use to split
        ///    <paramref name="vector" /> with.
        /// </param>
        /// <param name="byteAlign">
        ///    A <see cref="int" /> specifying the byte align to use
        ///    when splitting. In order to split when a pattern is
        ///    encountered, the index at which it is found must be
        //     divisible by <paramref name="byteAlign" />.
        /// </param>
        /// <param name="max">
        ///    A <see cref="int" /> value specifying the maximum number
        ///    of objects to return, or zero to not to limit the number.
        ///    If that that number is reached, the last value will
        ///    contain the remainder of the file even if it contains
        ///    more instances of <paramref name="pattern" />.
        /// </param>
        /// <returns>
        ///    A <see cref="ByteVectorCollection" /> object containing
        ///    the split contents of the current instance.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="vector" /> or <paramref name="pattern" />
        ///    is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    <paramref name="byteAlign" /> is less than 1.
        /// </exception>
        public static ByteVectorCollection Split(ByteVector vector,
                                                 ByteVector pattern,
                                                 int byteAlign,
                                                 int max)
        {
            if (vector == null)
            {
                throw new ArgumentNullException("vector");
            }

            if (pattern == null)
            {
                throw new ArgumentNullException("pattern");
            }

            if (byteAlign < 1)
            {
                throw new ArgumentOutOfRangeException(
                          "byteAlign",
                          "byteAlign must be at least 1.");
            }

            ByteVectorCollection list = new ByteVectorCollection();
            int previous_offset       = 0;

            for (int offset = vector.Find(pattern, 0, byteAlign);
                 offset != -1 && (max < 1 ||
                                  max > list.Count + 1);
                 offset = vector.Find(pattern,
                                      offset + pattern.Count, byteAlign))
            {
                list.Add(vector.Mid(previous_offset,
                                    offset - previous_offset));
                previous_offset = offset + pattern.Count;
            }

            if (previous_offset < vector.Count)
            {
                list.Add(vector.Mid(previous_offset,
                                    vector.Count - previous_offset));
            }

            return(list);
        }
示例#3
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="StringCollection" /> by converting a collection of
 ///    <see cref="ByteVector" /> objects to strings using the
 ///    UTF-8 encoding.
 /// </summary>
 /// <param name="vectorList">
 ///    A <see cref="ByteVectorCollection" /> object containing
 ///    values to convert and add to the new instance.
 /// </param>
 public StringCollection(ByteVectorCollection vectorList)
     : this(vectorList, StringType.UTF8)
 {
 }