From 5057e333cd7a1830581a1e88ed1107e7b7df2223 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 19 Nov 2022 17:43:23 +0800 Subject: [PATCH] re --- src/obj.h | 2 +- src/pocketpy.h | 4 ++-- src/str.h | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/obj.h b/src/obj.h index b2396844..618bbe4d 100644 --- a/src/obj.h +++ b/src/obj.h @@ -10,7 +10,7 @@ const _Int _Int_MAX_NEG = -9223372036854775807LL; const _Float _FLOAT_INF_POS = INFINITY; const _Float _FLOAT_INF_NEG = -INFINITY; -#define PK_VERSION "0.2.5" +#define PK_VERSION "0.2.6" class CodeObject; class BasePointer; diff --git a/src/pocketpy.h b/src/pocketpy.h index d0d7ab2d..233d41a8 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -309,12 +309,12 @@ void __initializeBuiltinFunctions(VM* _vm) { _vm->bindMethod("str", "__repr__", [](VM* vm, PyVarList args) { const _Str& _self = vm->PyStr_AS_C(args[0]); - return vm->PyStr("'" + _self.__escape(true).str() + "'"); + return vm->PyStr(_self.__escape(true)); }); _vm->bindMethod("str", "__json__", [](VM* vm, PyVarList args) { const _Str& _self = vm->PyStr_AS_C(args[0]); - return vm->PyStr("\"" + _self.__escape(false) + "\""); + return vm->PyStr(_self.__escape(false)); }); _vm->bindMethod("str", "__eq__", [](VM* vm, PyVarList args) { diff --git a/src/str.h b/src/str.h index f641ee90..9c88b8c0 100644 --- a/src/str.h +++ b/src/str.h @@ -207,6 +207,7 @@ public: _Str __escape(bool single_quote) const { _StrStream ss; + ss << (single_quote ? '\'' : '"'); for (auto c = _s->cbegin(); c != _s->cend(); c++) { switch (*c) { case '"': @@ -230,6 +231,7 @@ public: } } } + ss << (single_quote ? '\'' : '"'); return ss.str(); } };