Skip to content

Commit

Permalink
Merge pull request #8 from chrisjbreisch/dev
Browse files Browse the repository at this point in the history
Undid earlier change to generateAst
  • Loading branch information
chrisjbreisch authored May 11, 2022
2 parents 6ed8293 + a61ed45 commit 527b47e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 78 deletions.
74 changes: 5 additions & 69 deletions Trs80.Level1Basic.Extensions/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<string> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Trs80.Level1Basic.VirtualMachine.Interpreter;

public interface IInterpreter : IExpressionVisitor, IStatementVisitor
public interface IInterpreter : IExpressionVisitor<object>, IStatementVisitor<object>
{
Statement CurrentStatement { get; }
void Interpret(ParsedLine line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions Trs80.Level1Basic.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit 527b47e

Please sign in to comment.