Skip to content

Commit

Permalink
Fixed issue with CRLF encoded files causing unintended blank lines to…
Browse files Browse the repository at this point in the history
… be returned as output from the Semi-Random File Text Includer operator.

Also a few more small changes to code as suggested by the compiler.
  • Loading branch information
ajcolson committed Dec 4, 2023
1 parent 7efa58b commit 66c0dd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion QTCLConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class QTCLConfigLoader
{
"RandomFileTextLookupOperator":
{
"Directory": "{{QTCLH.APP_DIR}}data\random-text-files\",
"Directory": "{{QTCLH.APP_DIR}}data\random-text-files\",
"FileType": ".txt"
}
}
Expand Down
2 changes: 1 addition & 1 deletion QTCLH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void CheckForAppDir()
public static void ShowHelp()
{
string[] helpText = [
"qtcl v1.0 (Beta 1)",
"qtcl v1.0 (Beta 2)",
"",
"Possible Arguments:",
"<inputFilepath>\n\tRun the parser and intrepreter from the specified inputFilepath.",
Expand Down
2 changes: 1 addition & 1 deletion QTCLInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public string Interpret(string commandString)
string[] commandWords = commandString.Split(' ');
for (int i = 0; i < commandWords.Length; i++)
{
bool HasOperator = QTCLStandardLibrary.QTCLOperatorRegex().IsMatch(commandWords[i].Substring(0, 1));
bool HasOperator = QTCLStandardLibrary.QTCLOperatorRegex().IsMatch(commandWords[i][..1]);
if ( HasOperator )
{
var foundOperator = QTCLStandardLibrary.Operators.Where((c => c.OperatorWord == commandWords[i][..1]));
Expand Down
17 changes: 14 additions & 3 deletions QTCLStandardLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,20 @@ internal static partial class QTCLStandardLibrary
if (QTCLH.FILE.Exists(fName))
{
string[] fileContents = QTCLH.FILE.GetAllContent(fName).Split('\n');
Random r = new();
int ind = r.Next(0, fileContents.Length);
ret = fileContents[ind];
List<string> lineOptions = [];
//check for return carriages. Don't include the as a possible option.
for (int i = 0; i < fileContents.Length; i++)
{
if (fileContents[i] != "\r")
lineOptions.Add(fileContents[i]);
}
if (lineOptions.Count > 0)
{
Random r = new();
int ind = r.Next(0, lineOptions.Count);
ret = lineOptions[ind];
}
} else
{
QTCLH.CLI.PrintWarning($"Unable to parse the requsted text inclusion for the input named \"{input}\". A blank value will be inserted instead.\nPlease check the following file: \"{fName}\"");
Expand Down

0 comments on commit 66c0dd0

Please sign in to comment.