dnSpy.Contracts.Hex.HexBuffer.GetNextValidSpan C# (CSharp) Method

GetNextValidSpan() public method

Gets the next valid span or null if there's none left. This includes the input (position) if it happens to lie within this valid span. This method merges all consecutive valid spans.
public GetNextValidSpan ( HexPosition position, HexPosition upperBounds, bool fullSpan ) : HexSpan?
position HexPosition Start position to check
upperBounds HexPosition End position
fullSpan bool true if positions before should be included /// in the returned result. This could result in worse performance.
return HexSpan?
		public HexSpan? GetNextValidSpan(HexPosition position, HexPosition upperBounds, bool fullSpan) {
			if (position >= HexPosition.MaxEndPosition)
				throw new ArgumentOutOfRangeException(nameof(position));
			if (upperBounds > HexPosition.MaxEndPosition)
				throw new ArgumentOutOfRangeException(nameof(upperBounds));
			bool checkBackwards = true;
			while (position < upperBounds) {
				var info = GetSpanInfo(position);
				if (info.HasData) {
					var start = info.Span.Start;
					var end = info.Span.End;
					// We use MaxEndPosition and not upperBounds here since we must merge
					// all consecutive spans even if some of them happen to be outside the
					// requested range.
					while (end < HexPosition.MaxEndPosition) {
						info = GetSpanInfo(end);
						if (!info.HasData)
							break;
						end = info.Span.End;
					}
					if (fullSpan && checkBackwards)
						start = GetStartOfData(start, validData: true);
					return HexSpan.FromBounds(start, end);
				}
				checkBackwards = false;
				position = info.Span.End;
			}
			return null;
		}

Same methods

HexBuffer::GetNextValidSpan ( HexPosition position, bool fullSpan ) : HexSpan?

Usage Example

示例#1
0
		protected IEnumerable<HexSpan> GetValidSpans(HexBuffer buffer, HexPosition start, HexPosition upperBounds) {
			var pos = start;
			bool fullSpan = true;
			while (pos < HexPosition.MaxEndPosition) {
				var span = buffer.GetNextValidSpan(pos, upperBounds, fullSpan);
				if (span == null)
					break;

				var newStart = HexPosition.Max(pos, span.Value.Start);
				var newEnd = HexPosition.Min(upperBounds, span.Value.End);
				if (newStart < newEnd)
					yield return HexSpan.FromBounds(newStart, newEnd);

				pos = span.Value.End;
				fullSpan = false;
			}
		}