-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maxime Labelle
committed
Apr 15, 2019
1 parent
fdd38b9
commit 04e5335
Showing
9 changed files
with
1,394 additions
and
803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace Microsoft.PowerShell | ||
{ | ||
public class Range | ||
{ | ||
public int Offset { get; set; } | ||
public int Count { get; set; } | ||
} | ||
|
||
public static class StringBuilderLinewiseExtensions | ||
{ | ||
/// <summary> | ||
/// Determines the offset and the length of the fragment | ||
/// in the specified buffer that corresponds to a | ||
/// given number of lines starting from the specified line index | ||
/// </summary> | ||
/// <param name="buffer" /> | ||
/// <param name="lineIndex" /> | ||
/// <param name="lineCount" /> | ||
public static Range GetRange(this StringBuilder buffer, int lineIndex, int lineCount) | ||
{ | ||
var length = buffer.Length; | ||
|
||
var startPosition = 0; | ||
var startPositionIdentified = false; | ||
|
||
var endPosition = length - 1; | ||
var endPositionIdentified = false; | ||
|
||
var currentLine = 0; | ||
|
||
for (var position = 0; position < length; position++) | ||
{ | ||
if (currentLine == lineIndex && !startPositionIdentified) | ||
{ | ||
startPosition = position; | ||
startPositionIdentified = true; | ||
} | ||
|
||
if (buffer[position] == '\n') | ||
{ | ||
currentLine++; | ||
} | ||
|
||
if (currentLine == lineIndex + lineCount && !endPositionIdentified) | ||
{ | ||
endPosition = position; | ||
endPositionIdentified = true; | ||
} | ||
} | ||
|
||
return new Range | ||
{ | ||
Offset = startPosition, | ||
Count = endPosition - startPosition + 1, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.