Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
STRLEN now correctly respect escape sequences #29
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Nov 22, 2017
1 parent 19ae218 commit e7d5738
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ifj2017/interpreter/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def operands(self):
state.get_value(op0),
state.get_value(op1),
))),
'STRLEN': lambda state, target, string: state.set_value(target, len(state.get_value(string))),
'STRLEN': State.str_len,
'GETCHAR': lambda state, target, string, index: state.set_value(
target,
state.get_value(string)[state.get_value(index)]
Expand Down
3 changes: 3 additions & 0 deletions ifj2017/interpreter/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def set_char(self, where, index, from_):
changed[self.get_value(index)] = self.get_value(from_)[0]
self.set_value(where, changed)

def str_len(self, target, string):
return self.set_value(target, len(self.ESCAPE_RE.sub('_', self.get_value(string))))

def read(self, to, type_):
# type: (Operand, Operand) -> None
self.stdout.write('? ')
Expand Down

0 comments on commit e7d5738

Please sign in to comment.