From 9d51f28619242f6ea2deb13ed5dec706201c94e4 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Tue, 16 May 2017 14:34:42 +0200 Subject: [PATCH] Added docs for the public stuff in fahrplanparser.d and substitution.d --- source/fahrplanparser.d | 6 ++++++ source/substitution.d | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/source/fahrplanparser.d b/source/fahrplanparser.d index 7860e86..d2961ba 100644 --- a/source/fahrplanparser.d +++ b/source/fahrplanparser.d @@ -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; diff --git a/source/substitution.d b/source/substitution.d index 66e7b9d..07c239f 100644 --- a/source/substitution.d +++ b/source/substitution.d @@ -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[""] = "";