From e7d5738c58984cba5f5b0dd192411c1a8202832d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Kol=C3=A1=C5=99?= Date: Wed, 22 Nov 2017 17:34:18 +0100 Subject: [PATCH] STRLEN now correctly respect escape sequences #29 --- ifj2017/interpreter/instruction.py | 2 +- ifj2017/interpreter/state.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ifj2017/interpreter/instruction.py b/ifj2017/interpreter/instruction.py index 6c3f9d4..f7d6c62 100644 --- a/ifj2017/interpreter/instruction.py +++ b/ifj2017/interpreter/instruction.py @@ -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)] diff --git a/ifj2017/interpreter/state.py b/ifj2017/interpreter/state.py index 384235b..3a77b9b 100644 --- a/ifj2017/interpreter/state.py +++ b/ifj2017/interpreter/state.py @@ -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('? ')