Skip to content

Commit 1851c4d

Browse files
committed
simplify Series.toString
1 parent 519f846 commit 1851c4d

File tree

1 file changed

+6
-53
lines changed

1 file changed

+6
-53
lines changed

source/mir/series.d

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,53 +1292,11 @@ struct mir_series(IndexIterator_, Iterator_, size_t N_ = 1, SliceKind kind_ = Co
12921292
}
12931293

12941294
///
1295-
void toString(Writer, Spec)(auto ref Writer w, const ref Spec f) const
1295+
void toString(Writer)(scope ref Writer w) const
12961296
{
1297-
import std.format: formatValue, formatElement;
1298-
import std.range: put;
1299-
1300-
if (f.spec != 's' && f.spec != '(')
1301-
throw new Exception("incompatible format character for Mir Series argument: %" ~ f.spec);
1302-
1303-
enum defSpec = "%s" ~ f.keySeparator ~ "%s" ~ f.seqSeparator;
1304-
auto fmtSpec = f.spec == '(' ? f.nested : defSpec;
1305-
1306-
if (f.spec == 's')
1307-
put(w, f.seqBefore);
1308-
if (length) for (size_t i = 0;;)
1309-
{
1310-
auto fmt = Spec(fmtSpec);
1311-
fmt.writeUpToNextSpec(w);
1312-
if (f.flDash)
1313-
{
1314-
formatValue(w, index[i], fmt);
1315-
fmt.writeUpToNextSpec(w);
1316-
formatValue(w, data[i], fmt);
1317-
}
1318-
else
1319-
{
1320-
formatElement(w, index[i], fmt);
1321-
fmt.writeUpToNextSpec(w);
1322-
formatElement(w, data[i], fmt);
1323-
}
1324-
if (f.sep !is null)
1325-
{
1326-
fmt.writeUpToNextSpec(w);
1327-
if (++i != length)
1328-
put(w, f.sep);
1329-
else
1330-
break;
1331-
}
1332-
else
1333-
{
1334-
if (++i != length)
1335-
fmt.writeUpToNextSpec(w);
1336-
else
1337-
break;
1338-
}
1339-
}
1340-
if (f.spec == 's')
1341-
put(w, f.seqAfter);
1297+
import mir.format: print;
1298+
auto ls = lightScope;
1299+
print(w, "{ index: ", ls.index, ", data: ", ls.data, " }");
13421300
}
13431301

13441302
version(mir_test)
@@ -1348,13 +1306,8 @@ struct mir_series(IndexIterator_, Iterator_, size_t N_ = 1, SliceKind kind_ = Co
13481306
import mir.series: series, sort;
13491307
auto s = ["b", "a"].series([9, 8]).sort;
13501308

1351-
import std.conv : to;
1352-
assert(s.to!string == `["a":8, "b":9]`);
1353-
1354-
import std.format : format;
1355-
assert("%s".format(s) == `["a":8, "b":9]`);
1356-
assert("%(%s %s | %)".format(s) == `"a" 8 | "b" 9`);
1357-
assert("%-(%s,%s\n%)\n".format(s) == "a,8\nb,9\n");
1309+
import mir.format : text;
1310+
assert(s.text == `{ index: [a, b], data: [8, 9] }`, s.text);
13581311
}
13591312
}
13601313

0 commit comments

Comments
 (0)