From ec9ce614d87a47137cfbbb0f6d13aa30e4a1239c Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Sat, 14 Aug 2021 17:37:56 -0400
Subject: completed save/load feature
---
source/spots.d | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
(limited to 'source/spots.d')
diff --git a/source/spots.d b/source/spots.d
index f57ba8f..49b9c85 100644
--- a/source/spots.d
+++ b/source/spots.d
@@ -28,16 +28,17 @@ struct Spot
_contents = c;
}
+ import std.format : format, formattedRead;
+
string toString()
{
- import std.format : format;
- return format("'%c'", _contents);
+ return format!`'%c'`(_contents);
}
- void fromString(S)(S s) if (isSomeString!S)
+ void fromString(Range)(auto ref Range s)
{
- _contents = cast(char) s[1];
+ s.formattedRead!`'%c'`(_contents);
}
@property contents()
@@ -165,7 +166,7 @@ class OverlaySource : SpotSource
_base.save(f);
foreach (coord; _overlay.keys())
{
- f.writefln!"%s, %s: %s"(coord[0], coord[1], _overlay[coord]);
+ f.writefln!"%s %s: %s"(coord[0], coord[1], _overlay[coord]);
}
f.write(terminator);
}
@@ -173,21 +174,23 @@ class OverlaySource : SpotSource
void load(File f)
{
import std.conv : to;
- import std.algorithm.iteration;
+ import std.algorithm;
+ //_overlay = _overlay.init;
_base.load(f);
foreach (char[] line; f.lines)
{
if (line == terminator)
break;
- auto trim = line.filter!(a => a == ' ' || a == '\r' || a == '\n').array;
- auto parts = trim.splitter(':');
- auto ints = parts.moveFront.splitter(',').map!(to!BigInt);
+
+ auto ints = line.until(':').array.splitter(' ').map!(to!BigInt);
BigInt[2] coord;
- coord[0] = ints.moveFront;
+ coord[0] = ints.front;
+ ints.popFront;
coord[1] = ints.front;
+
auto s = new Spot();
- (*s).fromString(parts.front);
+ (*s).fromString(line.find(':').find('\''));
_overlay[coord] = *s;
}
}
--
cgit