Added docs for the public stuff in fahrplanparser.d and substitution.d

This commit is contained in:
Johannes Loher 2017-05-16 14:34:42 +02:00
parent e4f2bc1f3f
commit 9d51f28619
2 changed files with 17 additions and 0 deletions

View file

@ -28,6 +28,11 @@ enum directionXPath = "/m/des";
public:
/***********************************
* Parses the departure monitor data and returns it as an associative array.
* data is expected to contain valid XML as returned by queries sent to http://mobile.defas-fgi.de/beg/.
*/
auto parsedFahrplan(in string data)
{
// dfmt off
@ -40,6 +45,7 @@ auto parsedFahrplan(in string data)
// dfmt on
}
///
@system unittest
{
import std.array : array;

View file

@ -6,6 +6,10 @@ import std.traits : Parameters;
public:
/***********************************
* Loads a substitution dictonary from a file.
*/
void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
if (is(Parameters!(slurpFun!(string, string)) == AliasSeq!(string, const char[])))
{
@ -15,6 +19,7 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
slurpFun!(string, string)(fileName, `"%s" = "%s"`).each!(pair => map[pair[0]] = pair[1]);
}
///
@safe unittest
{
import std.typecons : Tuple, tuple;
@ -65,11 +70,17 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
assert(map["Text in"] == "wird durch diesen ersetzt");
}
/***********************************
* Substitutes a string with its corresponding replacement, if one is available.
* Otherwise just returns the original string.
*/
auto substitute(string s) @safe nothrow
{
return s in map ? map[s] : s;
}
///
@safe unittest
{
map[""] = "";