fork download
  1. import std.stdio;
  2. import std.ascii;
  3. import std.algorithm;
  4. import std.array;
  5. import std.typecons;
  6. import std.string;
  7.  
  8. void main()
  9. {
  10. string[] lines = [
  11. "key1: valueA",
  12. "key2: valueB",
  13. "key3: valueC", "\tvalueD", " valueE",
  14. "key4: valueF",
  15. ];
  16.  
  17. auto aa = lines
  18. .fold!((a, b) => b.startsWith!isWhite ? a[0..$-1] ~ (a[$-1] ~ b) : a ~ b)(string[].init)
  19. .map!(a => a.findSplit(`:`))
  20. .map!(a => tuple(a[0], a[2]))
  21. .assocArray;
  22. aa.writeln;
  23. }
Success #stdin #stdout 0s 4428KB
stdin
Standard input is empty
stdout
["key1":" valueA", "key2":" valueB", "key3":" valueC\tvalueD   valueE", "key4":" valueF"]