Merge branch '001_create_documentation' into 'master'

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

fixes #1 .

See merge request !3
This commit is contained in:
Johannes Loher 2017-07-12 15:25:21 +02:00
commit 969df165c5
2 changed files with 17 additions and 0 deletions

View file

@ -28,6 +28,11 @@ enum directionXPath = "/m/des";
public: 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) auto parsedFahrplan(in string data)
{ {
// dfmt off // dfmt off
@ -40,6 +45,7 @@ auto parsedFahrplan(in string data)
// dfmt on // dfmt on
} }
///
@system unittest @system unittest
{ {
import std.array : array; import std.array : array;

View file

@ -6,6 +6,10 @@ import std.traits : Parameters;
public: public:
/***********************************
* Loads a substitution dictonary from a file.
*/
void loadSubstitutionFile(alias slurpFun = slurp)(string fileName) void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
if (is(Parameters!(slurpFun!(string, string)) == AliasSeq!(string, const char[]))) 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]); slurpFun!(string, string)(fileName, `"%s" = "%s"`).each!(pair => map[pair[0]] = pair[1]);
} }
///
@safe unittest @safe unittest
{ {
import std.typecons : Tuple, tuple; import std.typecons : Tuple, tuple;
@ -65,11 +70,17 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
assert(map["Text in"] == "wird durch diesen ersetzt"); 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 auto substitute(string s) @safe nothrow
{ {
return s in map ? map[s] : s; return s in map ? map[s] : s;
} }
///
@safe unittest @safe unittest
{ {
map[""] = ""; map[""] = "";