1
0

Implement PRGSET

This commit is contained in:
otya128
2016-12-27 23:01:28 +09:00
parent c3b06ae5e3
commit bfedd461d4
2 changed files with 42 additions and 1 deletions

View File

@@ -1,14 +1,20 @@
module otya.smilebasic.program;
import std.range;
import std.container;
import std.algorithm;
struct Slot
{
DList!wstring program;
DList!wstring.Range range;
this(T)(T)
{
program = make!(DList!wstring);
range = program[];
}
void load(wstring data)
{
import std.algorithm;
program.clear();
foreach(l; splitter(data, "\n"))
{
@@ -78,6 +84,29 @@ struct Slot
range.popFront();
return a;
}
void set(wstring v)
{
int i;
foreach(l; splitter(v, "\n"))
{
if (!range.empty && i == 0)
{
range.put(l ~ "\n");
}
else
{
if (range.empty)
{
program.insertAfter(range, l ~ "\n");
}
else
{
program.insertBefore(range, l ~ "\n");
}
}
i++;
}
}
}
class Program
@@ -88,6 +117,10 @@ class Program
this()
{
slot = new Slot[5];
foreach(ref s; slot)
{
s = Slot(slot);
}
}
void edit(int slot, int line)
{
@@ -98,4 +131,8 @@ class Program
{
return this.slot[currentSlot].get;
}
void set(wstring v)
{
this.slot[currentSlot].set = v;
}
}