Skip to content

Commit b19584b

Browse files
Kapil Borledaviwil
Kapil Borle
authored andcommitted
Add a static method to split a string into lines
1 parent 294ce71 commit b19584b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/PowerShellEditorServices/Workspace/ScriptFile.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ public ScriptFile (
192192

193193
#region Public Methods
194194

195+
/// <summary>
196+
/// Get the lines in a string.
197+
/// </summary>
198+
/// <param name="text">Input string to be split up into lines.</param>
199+
/// <returns>The lines in the string.</returns>
200+
public static IEnumerable<string> GetLines(string text)
201+
{
202+
if (text == null)
203+
{
204+
throw new ArgumentNullException(nameof(text));
205+
}
206+
207+
return text.Split('\n').Select(line => line.TrimEnd('\r'));
208+
}
209+
195210
/// <summary>
196211
/// Gets a line from the file's contents.
197212
/// </summary>
@@ -479,11 +494,7 @@ private void SetFileContents(string fileContents)
479494
{
480495
// Split the file contents into lines and trim
481496
// any carriage returns from the strings.
482-
this.FileLines =
483-
fileContents
484-
.Split('\n')
485-
.Select(line => line.TrimEnd('\r'))
486-
.ToList();
497+
this.FileLines = GetLines(fileContents).ToList();
487498

488499
// Parse the contents to get syntax tree and errors
489500
this.ParseFileContents();

0 commit comments

Comments
 (0)