From 06efa23c85a2964644fd0b45ad2cdda48c9ee1eb Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 21 Jun 2023 14:09:32 +0200 Subject: [PATCH] Messages - Implemented `stripIllegalCharacters(string)` which provided an input string this will strip any illegal characters present within it --- source/birchwood/protocol/messages.d | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/source/birchwood/protocol/messages.d b/source/birchwood/protocol/messages.d index 9cfdd8e..e143181 100644 --- a/source/birchwood/protocol/messages.d +++ b/source/birchwood/protocol/messages.d @@ -146,13 +146,49 @@ public final class Message parameterParse(); } - /* TODO: Implement encoder function */ + /** + * Encodes this `Message` into a CRLF delimited + * byte array + * + * If `ChecksMode` is set to `EASY` (default) then + * any invalid characters will be stripped prior + * to encoding + * + * Throws: + * `BirchwoodException` if `ChecksMode` is set to + * `HARDCORE` and invalid characters are present + * Returns: + */ public string encode() { string fullLine = from~" "~command~" "~params; return fullLine; } + /** + * Provided an input string this will strip any illegal + * characters present within it + * + * Params: + * input = the string to filter + * Returns: the filtered string + */ + private static string stripIllegalCharacters(string input) + { + string stripped; + foreach(char character; input) + { + if(character == '\n' || character == '\r') + { + continue; + } + + stripped ~= character; + } + + return stripped; + } + public static Message parseReceivedMessage(string message) { /* TODO: testing */