Добавьте файлы проекта.
This commit is contained in:
98
SQLLinter/Common/FileLineActions.cs
Normal file
98
SQLLinter/Common/FileLineActions.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
namespace SQLLinter.Common;
|
||||
|
||||
public class FileLineActions
|
||||
{
|
||||
private readonly List<string> FileLines;
|
||||
|
||||
private readonly List<IRuleViolation> RuleViolations;
|
||||
|
||||
public FileLineActions(List<IRuleViolation> ruleViolations, List<string> fileLines)
|
||||
{
|
||||
RuleViolations = ruleViolations;
|
||||
FileLines = fileLines;
|
||||
}
|
||||
|
||||
public void Insert(int index, string line)
|
||||
{
|
||||
InsertRange(index, new string[1] { line });
|
||||
}
|
||||
|
||||
public void InsertInLine(int lineIndex, int charIndex, string content)
|
||||
{
|
||||
string text = FileLines[lineIndex];
|
||||
text = text.Insert(charIndex, content);
|
||||
FileLines[lineIndex] = text;
|
||||
foreach (IRuleViolation item in RuleViolations.Where((IRuleViolation x) => x.Line == lineIndex + 1 && x.Column > charIndex))
|
||||
{
|
||||
item.Column += content.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertRange(int index, IList<string> lines)
|
||||
{
|
||||
FileLines.InsertRange(index, lines);
|
||||
foreach (IRuleViolation item in RuleViolations.Where((IRuleViolation x) => x.Line > index))
|
||||
{
|
||||
item.Line += lines.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAll(Func<string, bool> where)
|
||||
{
|
||||
for (int num = FileLines.Count - 1; num >= 0; num--)
|
||||
{
|
||||
if (where(FileLines[num]))
|
||||
{
|
||||
RemoveAt(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
RemoveRange(index, 1);
|
||||
}
|
||||
|
||||
public void RemoveInLine(int lineIndex, int charIndex, int length)
|
||||
{
|
||||
string text = FileLines[lineIndex];
|
||||
text = text.Remove(charIndex, length);
|
||||
FileLines[lineIndex] = text;
|
||||
foreach (IRuleViolation item in RuleViolations.Where((IRuleViolation x) => x.Column == lineIndex + 1 && x.Column > charIndex))
|
||||
{
|
||||
item.Column -= length;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveRange(int index, int count)
|
||||
{
|
||||
FileLines.RemoveRange(index, count);
|
||||
foreach (IRuleViolation item in RuleViolations.Where((IRuleViolation x) => x.Line > index))
|
||||
{
|
||||
item.Line -= count;
|
||||
}
|
||||
}
|
||||
|
||||
public void RepaceInlineAt(int lineIndex, int charIndex, string content, int? replaceLength = null)
|
||||
{
|
||||
string text = FileLines[lineIndex];
|
||||
text = text.Remove(charIndex, replaceLength ?? content.Length);
|
||||
text = text.Insert(charIndex, content);
|
||||
FileLines[lineIndex] = text;
|
||||
if (!replaceLength.HasValue || replaceLength == content.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int? num = content.Length - replaceLength;
|
||||
foreach (IRuleViolation item in RuleViolations.Where((IRuleViolation x) => x.Line == lineIndex + 1 && x.Column > charIndex + content.Length))
|
||||
{
|
||||
item.Column += num.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLine(int lineIndex, string content)
|
||||
{
|
||||
FileLines[lineIndex] = content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user