mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2024-12-21 16:30:19 +00:00
Fix bug in LEFT$ MID$ and RIGHT$ (#45)
"The message ?ILLEGAL QUANTITY ERROR is displayed if \aexpr\<1 or \aexpr\>255. Co-authored-by: Colin Leroy-Mira <colin.leroy-mira@sigfox.com>
This commit is contained in:
parent
252b39dc08
commit
3d37fc357a
24
basic.js
24
basic.js
@ -1131,9 +1131,27 @@ this.basic = (function() {
|
||||
return state.prng.last;
|
||||
}, 'number', 'number');
|
||||
|
||||
funlib[kws.LEFT$] = funcsign(function LEFT$(s, n) { return s.substring(0, n); }, 'string', 'string', 'number');
|
||||
funlib[kws.MID$] = funcsign(function MID$(s, n, n2) { return n2 === (void 0) ? s.substring(n - 1) : s.substring(n - 1, n + n2 - 1); }, 'string', 'string', 'number', 'number?');
|
||||
funlib[kws.RIGHT$] = funcsign(function RIGHT$(s, n) { return s.length < n ? s : s.substring(s.length - n); }, 'string', 'string', 'number');
|
||||
funlib[kws.LEFT$] = funcsign(function LEFT$(s, n) {
|
||||
if (n < 1 || n > 255) {
|
||||
runtime_error(ERRORS.ILLEGAL_QUANTITY);
|
||||
}
|
||||
return s.substring(0, n);
|
||||
}, 'string', 'string', 'number');
|
||||
funlib[kws.MID$] = funcsign(function MID$(s, n, n2) {
|
||||
if (n < 1 || n > 255) {
|
||||
runtime_error(ERRORS.ILLEGAL_QUANTITY);
|
||||
}
|
||||
if (n2 < 1 || n2 > 255) {
|
||||
runtime_error(ERRORS.ILLEGAL_QUANTITY);
|
||||
}
|
||||
return n2 === (void 0) ? s.substring(n - 1) : s.substring(n - 1, n + n2 - 1);
|
||||
}, 'string', 'string', 'number', 'number?');
|
||||
funlib[kws.RIGHT$] = funcsign(function RIGHT$(s, n) {
|
||||
if (n < 1 || n > 255) {
|
||||
runtime_error(ERRORS.ILLEGAL_QUANTITY);
|
||||
}
|
||||
return s.length < n ? s : s.substring(s.length - n);
|
||||
}, 'string', 'string', 'number');
|
||||
|
||||
funlib[kws.POS] = funcsign(function POS(n) { return env.tty.getCursorPosition().x; }, 'number', 'number');
|
||||
funlib[kws.SCRN] = funcsign(function SCRN(x, y) {
|
||||
|
Loading…
Reference in New Issue
Block a user