yaml_gen now gens strings with user-specified alphabet, with Unicode support.
This commit is contained in:
parent
af4245811a
commit
760e39479e
2 changed files with 11 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
|
||||
///Random YAML generator. Used to generate benchmarking inputs.
|
||||
|
||||
import std.algorithm;
|
||||
import std.conv;
|
||||
import std.datetime;
|
||||
import std.math;
|
||||
|
@ -10,9 +11,6 @@ import std.string;
|
|||
import dyaml.all;
|
||||
|
||||
|
||||
immutable alphabet = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
|
||||
immutable digits = "0123456789";
|
||||
|
||||
Node config;
|
||||
Node function(bool)[string] generators;
|
||||
auto typesScalar = ["string", "int", "float", "bool", "timestamp", "binary"];
|
||||
|
@ -65,7 +63,7 @@ real randomReal(const real min, const real max, const string distribution = "lin
|
|||
return min + (max - min) * randomNormalized(distribution);
|
||||
}
|
||||
|
||||
char randomChar(const string chars)
|
||||
dchar randomChar(const dstring chars)
|
||||
{
|
||||
return chars[randomLong(0, chars.length - 1)];
|
||||
}
|
||||
|
@ -84,17 +82,19 @@ Node genString(bool root = false)
|
|||
{
|
||||
auto range = config["string"]["range"];
|
||||
|
||||
auto alphabet = config["string"]["alphabet"].as!dstring;
|
||||
|
||||
const chars = randomLong(range["min"].as!uint, range["max"].as!uint,
|
||||
range["dist"].as!string);
|
||||
|
||||
char[] result = new char[chars];
|
||||
dchar[] result = new dchar[chars];
|
||||
result[0] = randomChar(alphabet);
|
||||
foreach(i; 1 .. chars)
|
||||
{
|
||||
result[i] = randomChar(alphabet ~ digits);
|
||||
result[i] = randomChar(alphabet);
|
||||
}
|
||||
|
||||
return Node(cast(string)result);
|
||||
return Node(result.to!string);
|
||||
}
|
||||
|
||||
Node genInt(bool root = false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue