1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 13:02:54 +02:00
- Implemented `splitting(string)` which returns a `string[]` of split parameters according to the rfc1459's ENBF
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-17 08:35:23 +02:00
parent 75f3f7b867
commit fc9301f632

View File

@ -293,6 +293,73 @@ public final class Message
private string ppTrailing; private string ppTrailing;
private string[string] ppKVPairs; private string[string] ppKVPairs;
unittest
{
import std.stdio;
string testInput = "A:=1 A=2 :Hello this is text";
writeln("Input: ", testInput);
string[] splitted = splitting(testInput);
writeln("Input (split): ", splitted);
}
/**
* Imagine: `A:=1 A=2 :Hello`
*
* Params:
* input =
* Returns:
*/
private static string[] splitting(string input)
{
string[] splits;
bool trailingMode;
string buildUp;
for(ulong idx = 0; idx < input.length; idx++)
{
/* Get current character */
char curCHar = input[idx];
if(trailingMode)
{
buildUp ~= curCHar;
continue;
}
if(buildUp.length == 0)
{
if(curCHar == ':')
{
trailingMode = true;
continue;
}
}
if(curCHar == ' ')
{
/* Flush */
splits ~= buildUp;
buildUp = "";
}
else
{
buildUp ~= curCHar;
}
}
if(buildUp.length)
{
splits ~= buildUp;
}
return splits;
}
/** /**
* NOTE: This needs more work with trailing support * NOTE: This needs more work with trailing support
* we must make sure we only look for lastInex of `:` * we must make sure we only look for lastInex of `:`
@ -307,6 +374,8 @@ public final class Message
logger.debug_("Message: ", this); logger.debug_("Message: ", this);
logger.debug_("ParamsSTring in: ", params); logger.debug_("ParamsSTring in: ", params);
logger.debug_("Custom splitter: ", splitting(params));
/* Key-value pairs */ /* Key-value pairs */
string kvPairs; string kvPairs;