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)); }
public virtual string ToString(RangeHeaderItem rangeItem, long?length) { return($"{Unit} {rangeItem}/{length?.ToString(CultureInfo.InvariantCulture) ?? "*"}"); }
public virtual string ToString(RangeHeaderItem rangeItem) { return(ToString(rangeItem, null)); }