internal Region CreateRegion(RegionVersionOne v1Region) { Region region = null; if (v1Region != null) { region = new Region { ByteLength = v1Region.Length, ByteOffset = v1Region.Offset, EndColumn = v1Region.EndColumn, EndLine = v1Region.EndLine, StartColumn = v1Region.StartColumn, StartLine = v1Region.StartLine }; bool startIsTextBased = v1Region.StartLine > 0; bool endIsTextBased = v1Region.EndLine > 0 || v1Region.EndColumn > 0; if (startIsTextBased && endIsTextBased && v1Region.EndColumn == 0) { region.EndColumn = v1Region.StartColumn; } } return(region); }
internal RegionVersionOne CreateRegionVersionOne(Region v2Region, Uri uri) { RegionVersionOne region = null; if (v2Region != null) { region = new RegionVersionOne(); if (v2Region.StartLine > 0 || v2Region.EndLine > 0 || v2Region.StartColumn > 0 || v2Region.EndColumn > 0 || v2Region.CharOffset > 0 || v2Region.CharLength > 0) { if (v2Region.StartLine > 0) { // The start of the region is described by line/column region.StartLine = v2Region.StartLine; region.StartColumn = v2Region.StartColumn > 0 ? v2Region.StartColumn : 1; } else { // The start of the region is described by character offset // Try to get the byte offset using the file encoding and contents region.Offset = ConvertCharOffsetToByteOffset(v2Region.CharOffset, uri); } if (v2Region.CharLength > 0) { // The end of the region is described by character length // Try to get the byte length using the file encoding and contents region.Length = GetRegionByteLength(v2Region, uri); } else if (v2Region.EndLine > 0) { region.EndLine = v2Region.EndLine; if (v2Region.EndColumn > 0) { region.EndColumn = v2Region.EndColumn; } else { // In v2, if endColumn is missing, then the region extends to the end // of the line (exclusive of any newline sequence). Use the file contents // and encoding to determine how many columns are in the end line. region.EndColumn = GetRegionEndColumn(v2Region, uri); } } else if (v2Region.EndColumn > 0) { region.EndColumn = v2Region.EndColumn; } else { // THIS IS A PROBLEM. IF ALL THE "END" PROPERTIES ARE MISSING, // IT MEANS "THE REST OF THE StartLine". BUT IF CHARLENGTH IS // PRESENT BUT 0, IT MEANS "INSERTION POINT". AND WE CAN'T TELL // THE DIFFERENCE. // TODO: Issue #932 // Assume it's an insertion point region.EndLine = region.EndColumn = region.Length = 0; } } else { // There are no text-related properties. Therefore either the region is // described entirely by binary-related properties, or the region is an // insertion point at the start of the file. region.Length = v2Region.ByteLength; region.Offset = v2Region.ByteOffset; } } return(region); }