mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 14:23:38 +02:00
Messages
- 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:
parent
c1bf76df19
commit
b34eaf0e4e
@ -138,6 +138,9 @@ public final class Message
|
|||||||
logger.log(e);
|
logger.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse the parameters into key-value pairs (if any) and trailing text (if any) */
|
||||||
|
parameterParse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Implement encoder function */
|
/* TODO: Implement encoder function */
|
||||||
@ -276,6 +279,62 @@ public final class Message
|
|||||||
return params;
|
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
|
* Returns whether or not this message was
|
||||||
* a numeric response
|
* a numeric response
|
||||||
|
Loading…
Reference in New Issue
Block a user