1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 14:23:38 +02:00
- Added work-in-progress `parameterParse()` which attempts to parse parameters and trailing text (if any of both)
- Added `ppTrailing` for any possible trailing text
- Added `ppKVPairs` for any potential key-value pairs
- Call `parameterParse()` on initialization of a new `Message` object
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-16 13:45:56 +02:00
parent c1bf76df19
commit b34eaf0e4e

View File

@ -138,6 +138,9 @@ public final class Message
logger.log(e);
}
}
/* Parse the parameters into key-value pairs (if any) and trailing text (if any) */
parameterParse();
}
/* TODO: Implement encoder function */
@ -276,6 +279,62 @@ public final class Message
return params;
}
private string ppTrailing;
private string[string] ppKVPairs;
private void parameterParse()
{
/* Only parse if there are params */
if(params.length)
{
logger.debug_("Message: ", this);
logger.debug_("ParamsSTring in: ", params);
/* Key-value pairs */
string kvPairs;
/* Trailing text */
string trailing;
/* Find the first (and should be only) : (if any) */
long trailingIdx = indexOf(params, ":");
/* If there is trailing */
if(trailingIdx > -1)
{
/* Then read till (and not including the `:` indicator) */
kvPairs = params[0..trailingIdx];
/* Save the trailing text */
trailing = params[trailingIdx+1..params.length];
}
/* If there is no trailing */
else
{
/* Read the entire parameter string */
kvPairs = params;
}
/* Generate the key-value pairs */
string[] pairs = split(kvPairs, " ");
logger.debug_("Pairs: ", pairs);
foreach(string pair; pairs)
{
/* Only do this if we have an `=` in the current pair */
if(indexOf(pair, "=") > -1)
{
string key = split(pair, "=")[0];
string value = split(pair, "=")[1];
ppKVPairs[key] = value;
}
}
/* Save the trailing */
ppTrailing = trailing;
}
}
/**
* Returns whether or not this message was
* a numeric response