fork download
  1. import std.stdio;
  2. import std.ascii;
  3. import std.algorithm;
  4. import std.array;
  5. import std.string;
  6.  
  7. void main()
  8. {
  9. string[] lines = [
  10. "key1: valueA", "key2: valueB", "key3: valueC", "\tvalueD", " valueE",
  11. "key4: valueF",
  12. ];
  13.  
  14. string currKey;
  15. string currValue;
  16.  
  17. string[string] keyValueAA;
  18.  
  19. foreach (line; lines)
  20. {
  21. if (line.canFind(":"))
  22. {
  23. if (currKey != "" && currValue != "")
  24. {
  25. keyValueAA[currKey] = currValue;
  26. }
  27.  
  28. auto keyValue = line.split(":");
  29. currKey = keyValue[0].strip();
  30. currValue = keyValue[1].strip();
  31. }
  32. else if (line.startsWith!isWhite)
  33. {
  34. currValue = currValue ~ " " ~ line.strip();
  35. }
  36. }
  37. if (currKey != "" && currValue != "")
  38. {
  39. keyValueAA[currKey] = currValue;
  40. }
  41. writeln(keyValueAA);
  42. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
["key1":"valueA", "key2":"valueB", "key3":"valueC valueD valueE", "key4":"valueF"]