1
0

Implement PRGDEL

This commit is contained in:
otya128
2016-12-28 16:09:06 +09:00
parent 50470d60fa
commit e7237190bf
2 changed files with 69 additions and 0 deletions

View File

@@ -3182,6 +3182,18 @@ class BuiltinFunction
{ {
p.program.insert(line, cast(bool)isBack); p.program.insert(line, cast(bool)isBack);
} }
static void PRGDEL(PetitComputer p)
{
PRGDEL(p, 1);
}
static void PRGDEL(PetitComputer p, int count)
{
if (count == 0)
{
throw new OutOfRange("PRGDEL", 1);
}
p.program.delete_(count);
}
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc; //alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
static BuiltinFunctions[wstring] builtinFunctions; static BuiltinFunctions[wstring] builtinFunctions;
static wstring getBasicName(BFD)(const wstring def) static wstring getBasicName(BFD)(const wstring def)

View File

@@ -120,6 +120,45 @@ unittest
assert(slot.get() == "\n"); assert(slot.get() == "\n");
assert(slot.get() == ""); assert(slot.get() == "");
//PRGDEL
slot.currentLine = 1;
slot.delete_(1);
assert(slot.get() == "5\n");
assert(slot.get() == "6\n");
assert(slot.get() == "4\n");
assert(slot.get() == "A\n");
assert(slot.get() == "I\n");
assert(slot.get() == "J\n");
assert(slot.get() == "\n");
assert(slot.get() == "");
slot.currentLine = 1;
assert(slot.get() == "5\n");
assert(slot.get() == "6\n");
assert(slot.get() == "4\n");
assert(slot.get() == "A\n");
assert(slot.get() == "I\n");
assert(slot.get() == "J\n");
assert(slot.get() == "\n");
assert(slot.get() == "");
slot.currentLine = 2;
slot.delete_(2);
assert(slot.get() == "A\n");
assert(slot.get() == "I\n");
assert(slot.get() == "J\n");
assert(slot.get() == "\n");
assert(slot.get() == "");
slot.currentLine = 1;
assert(slot.get() == "5\n");
assert(slot.get() == "A\n");
assert(slot.get() == "I\n");
assert(slot.get() == "J\n");
assert(slot.get() == "\n");
assert(slot.get() == "");
slot.delete_(-1);
assert(slot.get() == "");
slot.currentLine = 1;
assert(slot.get() == "\n");
assert(slot.get() == "");
} }
struct Slot struct Slot
@@ -261,6 +300,18 @@ struct Slot
range.popFront(); range.popFront();
} }
} }
void delete_(int count)
{
if (count < 0)
{
init();
range.popFront();
}
else
{
range = program.linearRemove(range.take(count));
}
}
} }
class Program class Program
@@ -301,4 +352,10 @@ class Program
throw new UsePRGEDITBeforeAnyPRGFunction("PRGINS"); throw new UsePRGEDITBeforeAnyPRGFunction("PRGINS");
this.slot[currentSlot].insert(line, isBack); this.slot[currentSlot].insert(line, isBack);
} }
void delete_(int count)
{
if (!PRGEDITused)
throw new UsePRGEDITBeforeAnyPRGFunction("PRGDEL");
this.slot[currentSlot].delete_(count);
}
} }