StatsLine

Struct that parses a stats line

Members

Functions

dup
StatsLine dup()

Copy the structure

opIndex
cstring opIndex(cstring key)

Returns the value associated to a key

Static functions

opCall
StatsLine opCall(cstring line)

Create an StatsLine

Variables

date
cstring date;

The line date

time
cstring time;

The line time

Examples

Parsing a valid stat line

auto line = StatsLine("2018-09-12 10:03:07,598 cpu_usage:64.96 memory:330.19");

/// It should not extract a missing key
testThrown!(Exception)(line["missing_key"]);

/// It should not extract a key when the name is not fully provided
testThrown!(Exception)(line["pu_usage"]);
testThrown!(Exception)(line["cpu_usag"]);

/// Valid indexes
test!("==")(line["cpu_usage"], "64.96");
test!("==")(line["memory"], "330.19");
test!("==")(line.date, "2018-09-12");
test!("==")(line.time, "10:03:07,598");

Parsing a stat line with missing values

auto line = StatsLine("2018-09-12 10:03:07,598 cpu_usage: memory:");

/// It should return an empty string
test!("==")(line["cpu_usage"], "");
test!("==")(line["memory"], "");

Parsing a stat line with missing space separator

auto line = StatsLine("2018-09-12 10:03:07,598 2018-09-12 10:03:07,598 cpu_usage:64.96memory:330.19");

/// It should return the value after column
test!("==")(line["cpu_usage"], "64.96memory:330.19");

/// It should not find the key memory, since is parsed as a value for cpu_usage
testThrown!(Exception)(line["memory"]);

Duplicating a stat line

auto line = StatsLine("2018-09-12 10:03:07,598 2018-09-12 10:03:07,598 cpu_usage:64.96 memory:330.19");
auto line_copy = line.dup;

line.line.length = 0;
line.date.length = 0;
line.time.length = 0;

/// It should return an empty string
test!("==")(line_copy["cpu_usage"], "64.96");
test!("==")(line_copy.date, "2018-09-12");
test!("==")(line_copy.time, "10:03:07,598");

Meta