daily update on 20240203 by nitload youmu, ExpComment Comment Splitter ok, case code(* comment[comment*)code--comment and comment*)code--comment not added, may use span optimize all programme

This commit is contained in:
Nitload
2025-02-03 23:27:54 +08:00
parent 4ee675669f
commit 4e5a1b0dfb
48 changed files with 1247 additions and 662 deletions
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script
{
public static class CodeLineHelper
{
public static string SliceAndTrim(this string line, int startIndex, int length)
{
if (line == null) throw new ArgumentNullException(nameof(line));
if (startIndex < 0 || startIndex >= line.Length)
throw new ArgumentOutOfRangeException(nameof(startIndex));
if (length < 0 || startIndex + length > line.Length)
throw new ArgumentOutOfRangeException(nameof(length));
ReadOnlySpan<char> sourceSpan = line.AsSpan();
ReadOnlySpan<char> subSpan = sourceSpan.Slice(startIndex, length);
int start = 0;
while (start < subSpan.Length && char.IsWhiteSpace(subSpan[start]))
{
start++;
}
int end = subSpan.Length - 1;
while (end >= start && char.IsWhiteSpace(subSpan[end]))
{
end--;
}
if (start > end)
{
return string.Empty;
}
int finalLength = end - start + 1;
return new string(subSpan.Slice(start, finalLength));
}
public static string SliceAndTrim(this string line, int startIndex)
{
if (line == null) throw new ArgumentNullException(nameof(line));
if (startIndex < 0 || startIndex >= line.Length)
throw new ArgumentOutOfRangeException(nameof(startIndex));
ReadOnlySpan<char> sourceSpan = line.AsSpan();
ReadOnlySpan<char> subSpan = sourceSpan.Slice(startIndex);
int start = 0;
while (start < subSpan.Length && char.IsWhiteSpace(subSpan[start]))
{
start++;
}
int end = subSpan.Length - 1;
while (end >= start && char.IsWhiteSpace(subSpan[end]))
{
end--;
}
if (start > end)
{
return string.Empty;
}
int finalLength = end - start + 1;
return new string(subSpan.Slice(start, finalLength));
}
}
}