blueloveTH 3 лет назад
Родитель
Сommit
5057e333cd
3 измененных файлов с 5 добавлено и 3 удалено
  1. 1 1
      src/obj.h
  2. 2 2
      src/pocketpy.h
  3. 2 0
      src/str.h

+ 1 - 1
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;

+ 2 - 2
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) {

+ 2 - 0
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();
     }
 };