mirror of
https://github.com/louisrubet/rpn
synced 2025-01-28 19:58:01 +01:00
#107: new STRING keyword size
This commit is contained in:
parent
73bc66c683
commit
a1a427422b
4 changed files with 27 additions and 0 deletions
|
@ -146,6 +146,7 @@ rpn>
|
|||
|str->| convert a string into an object
|
||||
|chr| convert ASCII character code in stack level 1 into a string
|
||||
|num| return ASCII code of the first character of the string in stack level 1 as a real number
|
||||
|size| return the length of the string
|
||||
|
||||
#### branch
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ program::keyword_t program::s_keywords[] =
|
|||
{ cmd_keyword, "str->", &program::strout, "convert a string into an object" },
|
||||
{ cmd_keyword, "chr", &program::chr, "convert ASCII character code in stack level 1 into a string" },
|
||||
{ cmd_keyword, "num", &program::num, "return ASCII code of the first character of the string in stack level 1 as a real number" },
|
||||
{ cmd_keyword, "size", &program::strsize, "return the length of the string" },
|
||||
|
||||
//BRANCH
|
||||
{ cmd_undef, "", NULL, "\nBRANCH"},
|
||||
|
|
|
@ -70,3 +70,13 @@ void num()
|
|||
number* numb = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
numb->_value = the_chr;
|
||||
}
|
||||
|
||||
void strsize()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
||||
double len = ((ostring*)_stack->pop_back())->_len;
|
||||
number* numb = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
numb->_value = len;
|
||||
}
|
||||
|
|
|
@ -142,3 +142,18 @@ erase
|
|||
"" num
|
||||
-> stack should be 0
|
||||
erase
|
||||
|
||||
# size (1)
|
||||
"hello" size
|
||||
-> stack should be 5
|
||||
erase
|
||||
|
||||
# size (2)
|
||||
"" size
|
||||
-> stack should be 0
|
||||
erase
|
||||
|
||||
# size, str->, ->str
|
||||
"hello" str-> ->str size
|
||||
-> stack should be 7
|
||||
erase
|
||||
|
|
Loading…
Add table
Reference in a new issue