Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[js] Implement nqp::replace.
  • Loading branch information
pmurias committed Jan 13, 2016
1 parent d667c8e commit da7532a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -607,6 +607,8 @@ class QAST::OperationsJS {
nqp::defined($length) ?? "$string.substr($start,$length)" !! "$string.substr($start)";
});

add_simple_op('replace', $T_STR, [$T_STR, $T_INT, $T_INT, $T_STR]);

# TODO portability to JScript (according to mdn it doesn't support negative offset - check it)
add_simple_op('eqat', $T_BOOL, [$T_STR, $T_STR, $T_INT], sub ($haystack, $needle, $offset) {
"($haystack.substr($offset, $needle.length) === $needle)"
Expand Down
4 changes: 4 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -843,6 +843,10 @@ op.bitxor_s = function(a, b) {
}
};

op.replace = function(str, offset, count, repl) {
return str.substr(0, offset) + repl + str.substr(offset + count);
};

op.getcodelocation = function(code) {
var hash = new Hash();
hash.content.set('file', 'unknown');
Expand Down

0 comments on commit da7532a

Please sign in to comment.