示例#1
0
        public static RangeHeader Parse([NotNull][ItemNotNull] IEnumerable <string> ranges)
        {
            var    rangeItems = new List <RangeHeaderItem>();
            var    firstEntry = true;
            string unit       = null;

            foreach (var range in ranges)
            {
                string rangeValue;
                if (firstEntry)
                {
                    var parts = range.Split(_splitEqualChar, 2);
                    if (parts.Length == 1)
                    {
                        rangeValue = parts[0];
                    }
                    else
                    {
                        unit       = parts[0].TrimEnd();
                        rangeValue = parts[1].TrimStart();
                    }

                    firstEntry = false;
                }
                else
                {
                    rangeValue = range;
                }

                foreach (var rangeValueItem in rangeValue.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)))
                {
                    var item = RangeHeaderItem.Parse(rangeValueItem);
                    rangeItems.Add(item);
                }
            }

            return(new RangeHeader(unit ?? "bytes", true, rangeItems));
        }
示例#2
0
 public virtual string ToString(RangeHeaderItem rangeItem, long?length)
 {
     return($"{Unit} {rangeItem}/{length?.ToString(CultureInfo.InvariantCulture) ?? "*"}");
 }
示例#3
0
 public virtual string ToString(RangeHeaderItem rangeItem)
 {
     return(ToString(rangeItem, null));
 }