feat: ROU成型参数替换功能 — 支持 .rou/.rou1/.rou2/.roux 文件从参数 txt 自动补充 S/F/R/Z/H
This commit is contained in:
57
DrillTapeLineParser.cs
Normal file
57
DrillTapeLineParser.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DrillTools
|
||||
{
|
||||
/// <summary>
|
||||
/// 钻带文本行结构,保留原始文本和行尾换行符。
|
||||
/// </summary>
|
||||
internal readonly record struct DrillTapeLine(string Text, string LineEnding);
|
||||
|
||||
/// <summary>
|
||||
/// 钻带行解析器,将钻带文本按行拆分,保留原始换行符。
|
||||
/// </summary>
|
||||
internal static class DrillTapeLineParser
|
||||
{
|
||||
private static readonly char[] LineEndChars = { '\r', '\n' };
|
||||
|
||||
/// <summary>
|
||||
/// 将文本内容按行拆分,保留每行的换行符。
|
||||
/// </summary>
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user