feat: ROU成型参数替换功能 — 支持 .rou/.rou1/.rou2/.roux 文件从参数 txt 自动补充 S/F/R/Z/H
This commit is contained in:
@@ -9,7 +9,6 @@ namespace DrillTools
|
||||
internal static class DrillTapeParameterCleaner
|
||||
{
|
||||
private const int Gb2312CodePage = 936;
|
||||
private static readonly char[] LineEndChars = { '\r', '\n' };
|
||||
private static readonly Regex HeaderToolDefinitionStartPattern = new(
|
||||
@"^T\d+C",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
@@ -19,7 +18,7 @@ namespace DrillTools
|
||||
|
||||
public static bool CanClearParameters(string drillTapeContent)
|
||||
{
|
||||
var lines = SplitLines(drillTapeContent);
|
||||
var lines = DrillTapeLineParser.SplitLines(drillTapeContent);
|
||||
if (lines.Count < 2)
|
||||
return false;
|
||||
|
||||
@@ -45,7 +44,7 @@ namespace DrillTools
|
||||
if (!CanClearParameters(drillTapeContent))
|
||||
throw new InvalidOperationException("钻带文件不符合清空参数条件");
|
||||
|
||||
var lines = SplitLines(drillTapeContent);
|
||||
var lines = DrillTapeLineParser.SplitLines(drillTapeContent);
|
||||
var builder = new StringBuilder(drillTapeContent.Length);
|
||||
|
||||
for (int i = 0; i < lines.Count; i++)
|
||||
@@ -81,42 +80,6 @@ namespace DrillTools
|
||||
writer.Write(cleanedContent);
|
||||
}
|
||||
|
||||
private static List<DrillTapeLine> SplitLines(string content)
|
||||
{
|
||||
var lines = new List<DrillTapeLine>();
|
||||
int index = 0;
|
||||
|
||||
while (index < content.Length)
|
||||
{
|
||||
int lineEndIndex = content.IndexOfAny(LineEndChars, index);
|
||||
if (lineEndIndex < 0)
|
||||
{
|
||||
lines.Add(new DrillTapeLine(content[index..], string.Empty));
|
||||
return lines;
|
||||
}
|
||||
|
||||
string text = content[index..lineEndIndex];
|
||||
string lineEnding;
|
||||
if (content[lineEndIndex] == '\r' && lineEndIndex + 1 < content.Length && content[lineEndIndex + 1] == '\n')
|
||||
{
|
||||
lineEnding = "\r\n";
|
||||
index = lineEndIndex + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
lineEnding = content[lineEndIndex].ToString();
|
||||
index = lineEndIndex + 1;
|
||||
}
|
||||
|
||||
lines.Add(new DrillTapeLine(text, lineEnding));
|
||||
}
|
||||
|
||||
if (content.Length == 0)
|
||||
lines.Add(new DrillTapeLine(string.Empty, string.Empty));
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
private static List<DrillTapeLine> GetHeaderToolDefinitionLines(IReadOnlyList<DrillTapeLine> lines)
|
||||
{
|
||||
var toolDefinitionLines = new List<DrillTapeLine>();
|
||||
@@ -150,6 +113,5 @@ namespace DrillTools
|
||||
return Encoding.GetEncoding(Gb2312CodePage);
|
||||
}
|
||||
|
||||
private readonly record struct DrillTapeLine(string Text, string LineEnding);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user