mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-04 00:56:31 +02:00
Rename SaveString to SafeString
This commit is contained in:
@@ -81,16 +81,16 @@ namespace YesNt.Interpreter.Runtime
|
||||
{
|
||||
if (IsTask)
|
||||
{
|
||||
parentRuntimeInformation!.WriteLine(output.FromSaveString(), forceWrite);
|
||||
parentRuntimeInformation!.WriteLine(output.FromSafeString(), forceWrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDebugOutput?.Invoke(output.FromSaveString() + Environment.NewLine);
|
||||
OnDebugOutput?.Invoke(output.FromSafeString() + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(output.FromSaveString());
|
||||
Console.WriteLine(output.FromSafeString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,16 +105,16 @@ namespace YesNt.Interpreter.Runtime
|
||||
{
|
||||
if (IsTask)
|
||||
{
|
||||
parentRuntimeInformation!.Write(output.FromSaveString(), forceWrite);
|
||||
parentRuntimeInformation!.Write(output.FromSafeString(), forceWrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDebugOutput?.Invoke(output.FromSaveString());
|
||||
OnDebugOutput?.Invoke(output.FromSafeString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write(output.FromSaveString());
|
||||
Console.Write(output.FromSafeString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace YesNt.Interpreter.Runtime
|
||||
DebugEventArgs debugEventArgs = new DebugEventArgs()
|
||||
{
|
||||
LineNumber = runtimeInfo.LineNumber + 1,
|
||||
OriginalLine = runtimeInfo.CurrentLine.FromSaveString(),
|
||||
OriginalLine = runtimeInfo.CurrentLine.FromSafeString(),
|
||||
IsTask = runtimeInfo.IsTask,
|
||||
TaskId = runtimeInfo.TaskId
|
||||
};
|
||||
@@ -229,7 +229,7 @@ namespace YesNt.Interpreter.Runtime
|
||||
}
|
||||
if (runtimeInfo.IsDebugMode && notSearchingLabel)
|
||||
{
|
||||
debugEventArgs.CurrentLine = runtimeInfo.CurrentLine.FromSaveString();
|
||||
debugEventArgs.CurrentLine = runtimeInfo.CurrentLine.FromSafeString();
|
||||
runtimeInfo.LineExecuted(debugEventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace YesNt.Interpreter.Statements
|
||||
RuntimeInfo.Exit("Terminated by external process", true);
|
||||
return;
|
||||
}
|
||||
args = args.ReplaceFirstOccurrence("%crl ", input.ToSaveString() + " ");
|
||||
args = args.ReplaceFirstOccurrence("%crl ", input.ToSafeString() + " ");
|
||||
}
|
||||
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace YesNt.Interpreter.Statements
|
||||
while (args.Contains("%cr "))
|
||||
{
|
||||
string input = ConsoleExtentions.ReadKey(RuntimeInfo).ToString();
|
||||
args = args.ReplaceFirstOccurrence("%cr ", input.ToSaveString() + " ");
|
||||
args = args.ReplaceFirstOccurrence("%cr ", input.ToSafeString() + " ");
|
||||
}
|
||||
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
|
||||
[Statement("!calc", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.High)]
|
||||
public void Calculate(string args)
|
||||
{
|
||||
MatchCollection matches = CalculationRegex().Matches(args.FromSaveString());
|
||||
MatchCollection matches = CalculationRegex().Matches(args.FromSafeString());
|
||||
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
|
||||
RuntimeInfo.Exit("Invalid operation", true);
|
||||
return;
|
||||
}
|
||||
args = args.FromSaveString().Replace(matches[i].Value, res);
|
||||
args = args.FromSafeString().Replace(matches[i].Value, res);
|
||||
}
|
||||
|
||||
RuntimeInfo.CurrentLine = args;
|
||||
@@ -35,7 +35,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
|
||||
[Statement("!eval", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.VeryHigh)]
|
||||
public void Evaluate(string args)
|
||||
{
|
||||
RuntimeInfo.CurrentLine = args.FromSaveString();
|
||||
RuntimeInfo.CurrentLine = args.FromSafeString();
|
||||
}
|
||||
|
||||
[Statement("!!", SearchMode.Contains, SpaceAround.None, ConsoleColor.DarkYellow, Priority = Priority.PreProcessing, KeepStatementInArgs = true)]
|
||||
@@ -49,7 +49,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
|
||||
{
|
||||
char charToEscape = args[index];
|
||||
args = args.Remove(index, 1);
|
||||
args = args.Insert(index, charToEscape.ToString().ToSaveString());
|
||||
args = args.Insert(index, charToEscape.ToString().ToSafeString());
|
||||
}
|
||||
}
|
||||
RuntimeInfo.CurrentLine = args;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace YesNt.Interpreter.Statements
|
||||
[Statement("exc", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Magenta, Priority = Priority.Low, Seperator = "|")]
|
||||
public void ExecuteProgramWithArgs(string input)
|
||||
{
|
||||
string[] parts = input.FromSaveString().Split('|');
|
||||
string[] parts = input.FromSafeString().Split('|');
|
||||
parts[0] = parts[0].Trim();
|
||||
|
||||
string[] functionArgumets = parts[1].Split(',');
|
||||
|
||||
@@ -8,11 +8,11 @@ internal static partial class Evaluator
|
||||
{
|
||||
public static bool? EvaluateCondition(string input)
|
||||
{
|
||||
if (input.ToLower().FromSaveString().Trim() == "true")
|
||||
if (input.ToLower().FromSafeString().Trim() == "true")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (input.ToLower().FromSaveString().Trim() == "false")
|
||||
else if (input.ToLower().FromSafeString().Trim() == "false")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -20,16 +20,16 @@ internal static partial class Evaluator
|
||||
string[] parts = input.Split("==");
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
string part1 = parts[0].FromSaveString().Trim();
|
||||
string part2 = parts[1].FromSaveString().Trim();
|
||||
string part1 = parts[0].FromSafeString().Trim();
|
||||
string part2 = parts[1].FromSafeString().Trim();
|
||||
return part1 == part2;
|
||||
}
|
||||
|
||||
parts = input.Split("!=");
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
string part1 = parts[0].FromSaveString().Trim();
|
||||
string part2 = parts[1].FromSaveString().Trim();
|
||||
string part1 = parts[0].FromSafeString().Trim();
|
||||
string part2 = parts[1].FromSafeString().Trim();
|
||||
return part1 != part2;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ internal static partial class Evaluator
|
||||
return null;
|
||||
}
|
||||
|
||||
input = input.FromSaveString();
|
||||
input = input.FromSafeString();
|
||||
|
||||
MatchCollection matches = ParenthesesRegex().Matches(input);
|
||||
while (matches.Count > 0)
|
||||
|
||||
@@ -2,52 +2,51 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace YesNt.Interpreter.Utilities
|
||||
namespace YesNt.Interpreter.Utilities;
|
||||
|
||||
public static class StringExtentions
|
||||
{
|
||||
public static class StringExtentions
|
||||
public static string ToSafeString(this string input)
|
||||
{
|
||||
public static string ToSaveString(this string input)
|
||||
StringBuilder output = new StringBuilder();
|
||||
foreach (char c in input)
|
||||
{
|
||||
StringBuilder output = new StringBuilder();
|
||||
foreach (char c in input)
|
||||
{
|
||||
_ = output.Append($"\v{c}\v");
|
||||
}
|
||||
return output.ToString();
|
||||
_ = output.Append($"\v{c}\v");
|
||||
}
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
public static string FromSafeString(this string input)
|
||||
{
|
||||
return input.Replace("\v", "");
|
||||
}
|
||||
|
||||
public static bool ToStandardizedNumber(this string input, out double result)
|
||||
{
|
||||
return double.TryParse(input.FromSafeString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
}
|
||||
|
||||
public static string ReplaceFirstOccurrence(this string input, string oldValue, string newValue)
|
||||
{
|
||||
int place = input.IndexOf(oldValue);
|
||||
return input.Remove(place, oldValue.Length).Insert(place, newValue);
|
||||
}
|
||||
|
||||
public static string ReplaceLastOccurrence(this string input, string oldValue, string newValue)
|
||||
{
|
||||
int place = input.LastIndexOf(oldValue);
|
||||
return input.Remove(place, Math.Min(oldValue.Length, input.Length - place)).Insert(place, newValue);
|
||||
}
|
||||
|
||||
public static int WhiteSpaceAtEnd(this string input)
|
||||
{
|
||||
int count = 0;
|
||||
int index = input.Length - 1;
|
||||
while (index >= 0 && char.IsWhiteSpace(input[index--]))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
public static string FromSaveString(this string input)
|
||||
{
|
||||
return input.Replace("\v", "");
|
||||
}
|
||||
|
||||
public static bool ToStandardizedNumber(this string input, out double result)
|
||||
{
|
||||
return double.TryParse(input.FromSaveString().Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
}
|
||||
|
||||
public static string ReplaceFirstOccurrence(this string input, string oldValue, string newValue)
|
||||
{
|
||||
int place = input.IndexOf(oldValue);
|
||||
return input.Remove(place, oldValue.Length).Insert(place, newValue);
|
||||
}
|
||||
|
||||
public static string ReplaceLastOccurrence(this string input, string oldValue, string newValue)
|
||||
{
|
||||
int place = input.LastIndexOf(oldValue);
|
||||
return input.Remove(place, Math.Min(oldValue.Length, input.Length - place)).Insert(place, newValue);
|
||||
}
|
||||
|
||||
public static int WhiteSpaceAtEnd(this string input)
|
||||
{
|
||||
int count = 0;
|
||||
int index = input.Length - 1;
|
||||
while (index >= 0 && char.IsWhiteSpace(input[index--]))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user