Merge pull request #272 from louisrubet/#269/command-endl

Add endl command
This commit is contained in:
Louis Rubet 2022-03-31 11:00:39 +02:00 committed by GitHub
commit 916fb097ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View file

@ -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"},

View file

@ -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();

View file

@ -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"));
}

View file

@ -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