mirror of
https://github.com/louisrubet/rpn
synced 2024-11-16 07:47:26 +01:00
Merge pull request #272 from louisrubet/#269/command-endl
Add endl command
This commit is contained in:
commit
916fb097ff
4 changed files with 20 additions and 0 deletions
|
@ -121,6 +121,7 @@ vector<Program::keyword_t> Program::keywords_{
|
|||
{kKeyword, "size", &Program::RpnStrsize, "return the length of the string"},
|
||||
{kKeyword, "pos", &Program::RpnStrpos, "seach for the string in level 1 within the string in level 2"},
|
||||
{kKeyword, "sub", &Program::RpnStrsub, "return a substring of the string in level 3"},
|
||||
{kKeyword, "endl", &Program::RpnEndl, "end line character"},
|
||||
|
||||
// BRANCH
|
||||
{kUndef, "", nullptr, "\nBRANCH"},
|
||||
|
|
|
@ -223,6 +223,7 @@ class Program : public deque<Object*>, public Lexer, public Object {
|
|||
void RpnStrsize();
|
||||
void RpnStrpos();
|
||||
void RpnStrsub();
|
||||
void RpnEndl();
|
||||
|
||||
// test-core
|
||||
void RpnTest();
|
||||
|
|
|
@ -94,3 +94,9 @@ void Program::RpnStrsub() {
|
|||
stack_.push(new String(stack_.value<String>(2).substr(first, len)));
|
||||
stack_.erase(1, 3);
|
||||
}
|
||||
|
||||
/// @brief endline character
|
||||
///
|
||||
void Program::RpnEndl() {
|
||||
stack_.push_front(new String("\n"));
|
||||
}
|
||||
|
|
|
@ -305,3 +305,15 @@
|
|||
-> stack should be "sub"
|
||||
|
||||
`del`
|
||||
|
||||
## endl 1
|
||||
`endl type`
|
||||
|
||||
-> stack should be "string"
|
||||
|
||||
`del`
|
||||
|
||||
## endl 2
|
||||
`endl num`
|
||||
|
||||
-> stack should be 10
|
||||
|
|
Loading…
Reference in a new issue