Исправлен RegexHandler
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
@@ -59,25 +59,50 @@ namespace SaveWizard_rewritten
|
||||
|
||||
public static string GetValue(int line)
|
||||
{
|
||||
return Regex.Match(": (.+)$", lines[line]).Value;
|
||||
return Regex.Match(lines[line], ": (.+)$").Groups[1].ToString();
|
||||
}
|
||||
|
||||
public static void SetValue(int line, string value)
|
||||
{
|
||||
string name = Regex.Match("(.+):", lines[line]).Value;
|
||||
//string name = Regex.Match(lines[line], "(.+):").Value;
|
||||
string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString();
|
||||
lines[line] = $"{name}: {value}";
|
||||
}
|
||||
|
||||
//public static string GetUnitName(int line)
|
||||
//{
|
||||
// return Regex.Match(lines[line], " : (.+) {$").Groups[1].ToString();
|
||||
//}
|
||||
|
||||
public static int GetArrayLength(int line)
|
||||
{
|
||||
return Convert.ToInt32(Regex.Match(": ([0-9]+)$", lines[line]).Value);
|
||||
//return Convert.ToInt32(Regex.Match(lines[line], ": ([0-9]+)$").Value);
|
||||
return Convert.ToInt32(GetValue(line));
|
||||
}
|
||||
|
||||
//public static string GetArrayValueByIndex(int line, int index)
|
||||
//{
|
||||
// return Regex.Match(lines[line + index + 1], ": (.+)$").Groups[1].ToString();
|
||||
//}
|
||||
|
||||
//public static int GetArrayIndexByValue(int line, string value)
|
||||
//{
|
||||
// int count = 0;
|
||||
// for (int i = 0; i < GetArrayLength(line); i++)
|
||||
// {
|
||||
// if (GetValue(line + count + 1) == value)
|
||||
// return count;
|
||||
// count += 1;
|
||||
// }
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
public static List<string> GetArrayItems(int line)
|
||||
{
|
||||
List<string> items = new List<string>();
|
||||
for (int i = 0; i < GetArrayLength(line); i++)
|
||||
items.Add(Regex.Match(": (.+)$", lines[line + i + 1]).Value);
|
||||
//items.Add(Regex.Match(lines[line + i + 1], ": (.+)$").Value);
|
||||
items.Add(Regex.Match(lines[line + i + 1], ": (.+)$").Groups[1].ToString());
|
||||
if (items.Count == 0)
|
||||
return null;
|
||||
return items;
|
||||
@@ -85,10 +110,28 @@ namespace SaveWizard_rewritten
|
||||
|
||||
public static void AddArrayValue(int line, string value)
|
||||
{
|
||||
string name = Regex.Match("(.+):", lines[line]).Value;
|
||||
//string name = Regex.Match(lines[line], "(.+):").Value;
|
||||
string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString();
|
||||
int length = GetArrayLength(line);
|
||||
lines[line] = $"{name}: {length + 1}";
|
||||
lines.Insert(line + length + 1, $"{name}[{length}]: {value}");
|
||||
}
|
||||
|
||||
//public static void RemoveArrayValue(int line, string value)
|
||||
//{
|
||||
// string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString();
|
||||
// lines.Remove(lines[line + 1 + GetArrayIndexByValue(line, value)]);
|
||||
// int count = GetArrayLength(line);
|
||||
// lines[line] = $"{name}: {count - 1}";
|
||||
// for (int i = 0; i < count; i++)
|
||||
// //lines[line + i + 1] = ("")
|
||||
// lines[line + i + 1].Replace("[[0-9]+]", $"{i}");
|
||||
//}
|
||||
|
||||
//public static void ChangeArrayValue(int line, int index, string value)
|
||||
//{
|
||||
// line += index + 1;
|
||||
// SetValue(line, value);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user