diff --git a/LuaScript/Compat/AviUtlParameterLayout.cs b/LuaScript/Compat/AviUtlParameterLayout.cs index ef4c92a..3cca856 100644 --- a/LuaScript/Compat/AviUtlParameterLayout.cs +++ b/LuaScript/Compat/AviUtlParameterLayout.cs @@ -49,13 +49,13 @@ namespace LuaScript.Compat int sectionEnd = lines.Length; for (int i = 0; i < lines.Length; i++) { - if (!IsSectionHeader(lines[i])) + if (!ScriptParserHelper.IsSectionHeader(lines[i])) continue; sectionStart = i + 1; sectionEnd = lines.Length; for (int j = sectionStart; j < lines.Length; j++) { - if (IsSectionHeader(lines[j])) + if (ScriptParserHelper.IsSectionHeader(lines[j])) { sectionEnd = j; break; @@ -72,7 +72,7 @@ namespace LuaScript.Compat private void ParseLine(string line) { - int i = SkipSpaces(line, 0); + int i = ScriptParserHelper.SkipSpaces(line, 0); if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-') return; i += 2; @@ -80,7 +80,7 @@ namespace LuaScript.Compat return; int nameStart = i; - while (i < line.Length && IsNameChar(line[i])) + while (i < line.Length && ScriptParserHelper.IsNameChar(line[i])) i++; if (i >= line.Length || line[i] != ':') return; @@ -174,27 +174,11 @@ namespace LuaScript.Compat private static string FirstToken(string content) { - int start = SkipSpaces(content, 0); + int start = ScriptParserHelper.SkipSpaces(content, 0); int i = start; while (i < content.Length && content[i] != ',' && content[i] != ' ' && content[i] != '\t') i++; return content.Substring(start, i - start); } - - private static bool IsSectionHeader(string line) - { - int i = SkipSpaces(line, 0); - return i < line.Length && line[i] == '@'; - } - - private static int SkipSpaces(string text, int index) - { - while (index < text.Length && (text[index] == ' ' || text[index] == '\t')) - index++; - return index; - } - - private static bool IsNameChar(char c) => - (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } } diff --git a/LuaScript/Compat/AviUtlScript.cs b/LuaScript/Compat/AviUtlScript.cs index af71045..681a66a 100644 --- a/LuaScript/Compat/AviUtlScript.cs +++ b/LuaScript/Compat/AviUtlScript.cs @@ -26,7 +26,7 @@ namespace LuaScript.Compat for (int i = 0; i < lines.Length; i++) { - if (!IsSectionHeader(lines[i])) + if (!ScriptParserHelper.IsSectionHeader(lines[i])) continue; hasSection = true; @@ -34,7 +34,7 @@ namespace LuaScript.Compat sectionEnd = lines.Length; for (int j = sectionStart; j < lines.Length; j++) { - if (IsSectionHeader(lines[j])) + if (ScriptParserHelper.IsSectionHeader(lines[j])) { sectionEnd = j; break; @@ -59,15 +59,9 @@ namespace LuaScript.Compat return builder.ToString(); } - private static bool IsSectionHeader(string line) - { - int i = SkipSpaces(line, 0); - return i < line.Length && line[i] == '@'; - } - private static void AppendDeclarations(string line, List prelude) { - int i = SkipSpaces(line, 0); + int i = ScriptParserHelper.SkipSpaces(line, 0); if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-') return; i += 2; @@ -75,7 +69,7 @@ namespace LuaScript.Compat return; int nameStart = i; - while (i < line.Length && IsNameChar(line[i])) + while (i < line.Length && ScriptParserHelper.IsNameChar(line[i])) i++; if (i >= line.Length || line[i] != ':') return; @@ -125,15 +119,5 @@ namespace LuaScript.Compat if (trimmed.Length != 0) prelude.Add(trimmed); } - - private static int SkipSpaces(string text, int index) - { - while (index < text.Length && (text[index] == ' ' || text[index] == '\t')) - index++; - return index; - } - - private static bool IsNameChar(char c) => - (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } } diff --git a/LuaScript/Compat/ScriptParserHelper.cs b/LuaScript/Compat/ScriptParserHelper.cs new file mode 100644 index 0000000..2842c34 --- /dev/null +++ b/LuaScript/Compat/ScriptParserHelper.cs @@ -0,0 +1,21 @@ +namespace LuaScript.Compat +{ + internal static class ScriptParserHelper + { + public static bool IsSectionHeader(string line) + { + int i = SkipSpaces(line, 0); + return i < line.Length && line[i] == '@'; + } + + public static int SkipSpaces(string text, int index) + { + while (index < text.Length && (text[index] == ' ' || text[index] == '\t')) + index++; + return index; + } + + public static bool IsNameChar(char c) => + (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); + } +}