diff --git a/Trs80.Level1Basic.Extensions/Extensions/StringExtensions.cs b/Trs80.Level1Basic.Extensions/Extensions/StringExtensions.cs index aab86ca..2410036 100644 --- a/Trs80.Level1Basic.Extensions/Extensions/StringExtensions.cs +++ b/Trs80.Level1Basic.Extensions/Extensions/StringExtensions.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Text; namespace Trs80.Level1Basic.Common.Extensions; @@ -11,83 +9,21 @@ public static class StringExtensions { public static string ToPascalCase(this string text) { - string result = HandleBaseCases(text, true); - if (!string.IsNullOrEmpty(result)) return result; + if (string.IsNullOrEmpty(text)) return text; + if (text.Length == 1) return text.ToUpper(); - string[] words = SplitWords(text); + string[] words = text.Split(new[] { '-', '_' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length > 1) return string.Concat(words.Select(word => word[..1].ToUpper() + word[1..].ToLower())); - return words[0][..1].ToUpper() + words[0][1..].ToLower(); - } - - private static string[] SplitWords(string text) - { - string[] words = text.Split(new[] { '-', '_', ' ' }, StringSplitOptions.RemoveEmptyEntries); - return words; + return words[0][..1].ToUpper() + words[0][1..]; } public static string ToCamelCase(this string text) { - string result = HandleBaseCases(text, false); - if (!string.IsNullOrEmpty(result)) return result; - - result = ToPascalCase(text); + string result = ToPascalCase(text); return result[..1].ToLower() + result[1..]; } - - public static string ToSnakeCase(this string text) - { - string result = HandleBaseCases(text, false); - if (!string.IsNullOrEmpty(result)) return result; - - string[] words = SplitWords(text); - - return CasedStringWithSeparator(words, false, '_'); - } - - public static string ToCapsCase(this string text) - { - string result = HandleBaseCases(text, true); - if (!string.IsNullOrEmpty(result)) return result; - - string[] words = SplitWords(text); - - return CasedStringWithSeparator(words, true, '_'); - } - - public static string ToKebabCase(this string text) - { - string result = HandleBaseCases(text, false); - if (!string.IsNullOrEmpty(result)) return result; - - string[] words = SplitWords(text); - - return CasedStringWithSeparator(words, false, '-'); - } - - private static string HandleBaseCases(this string text, bool isUpper) - { - if (string.IsNullOrEmpty(text)) return text; - return text.Length == 1 ? text.ConvertCase(isUpper) : string.Empty; - } - private static string ConvertCase(this string word, bool isUpper) - { - return isUpper ? word.ToUpper() : word.ToLower(); - } - - private static string CasedStringWithSeparator(IReadOnlyList words, bool isUpper, char separator) - { - if (words.Count == 1) return words[0].ConvertCase(isUpper); - - StringBuilder sb = new(); - - for (int i = 0; i < words.Count - 1; i++) - sb.Append(words[i].ConvertCase(isUpper) + separator); - - sb.Append(words[^1].ConvertCase(isUpper)); - return sb.ToString(); - } } \ No newline at end of file diff --git a/Trs80.Level1Basic.VirtualMachine/Interpreter/IInterpreter.cs b/Trs80.Level1Basic.VirtualMachine/Interpreter/IInterpreter.cs index 3375cde..06e63f0 100644 --- a/Trs80.Level1Basic.VirtualMachine/Interpreter/IInterpreter.cs +++ b/Trs80.Level1Basic.VirtualMachine/Interpreter/IInterpreter.cs @@ -4,7 +4,7 @@ namespace Trs80.Level1Basic.VirtualMachine.Interpreter; -public interface IInterpreter : IExpressionVisitor, IStatementVisitor +public interface IInterpreter : IExpressionVisitor, IStatementVisitor { Statement CurrentStatement { get; } void Interpret(ParsedLine line); diff --git a/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs b/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs index 8114dca..dde11fd 100644 --- a/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs +++ b/Trs80.Level1Basic.VirtualMachine/Interpreter/Interpreter.cs @@ -226,7 +226,7 @@ private void WriteFloatValue(dynamic value) _sb.Append(value.ToString("######")); } - public void VisitNextStatement(Next statement) + public sd VisitNextStatement(Next statement) { ForCheckCondition checkCondition = GetCheckCondition(statement); dynamic nextIndexerValue = IncrementIndexer(checkCondition); diff --git a/Trs80.Level1Basic.sln b/Trs80.Level1Basic.sln index 59a5946..4cec591 100644 --- a/Trs80.Level1Basic.sln +++ b/Trs80.Level1Basic.sln @@ -48,8 +48,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trs80.Level1Basic.TestUtili EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trs80.Level1Basic.VirtualMachine", "Trs80.Level1Basic.VirtualMachine\Trs80.Level1Basic.VirtualMachine.csproj", "{827C9838-033A-4044-B091-E0C6FE509DDC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trs80.Level1Basic.Extensions.Test", "Trs80.Level1Basic.Extensions.Test\Trs80.Level1Basic.Extensions.Test.csproj", "{464C903C-6EE4-4629-9031-5D877E0B96E6}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -104,10 +102,6 @@ Global {827C9838-033A-4044-B091-E0C6FE509DDC}.Debug|Any CPU.Build.0 = Debug|Any CPU {827C9838-033A-4044-B091-E0C6FE509DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU {827C9838-033A-4044-B091-E0C6FE509DDC}.Release|Any CPU.Build.0 = Release|Any CPU - {464C903C-6EE4-4629-9031-5D877E0B96E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {464C903C-6EE4-4629-9031-5D877E0B96E6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {464C903C-6EE4-4629-9031-5D877E0B96E6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {464C903C-6EE4-4629-9031-5D877E0B96E6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -126,7 +120,6 @@ Global {CCDDE474-9B7C-4300-9962-9C56996F91B0} = {CD571827-E0DE-4EEA-BCCE-3475124C8BB2} {C0766798-3B89-476D-A53B-2B18ACA2529E} = {CD571827-E0DE-4EEA-BCCE-3475124C8BB2} {827C9838-033A-4044-B091-E0C6FE509DDC} = {EC14AF9B-5F4B-4EFC-AE2F-0F5EF3AD0F55} - {464C903C-6EE4-4629-9031-5D877E0B96E6} = {CD571827-E0DE-4EEA-BCCE-3475124C8BB2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5EB0E852-7B78-46A4-934D-25D7E53322B7}