This commit is contained in:
blueloveTH 2022-11-19 17:43:23 +08:00
parent 0b1ba59024
commit 5057e333cd
3 changed files with 5 additions and 3 deletions

View File

@ -10,7 +10,7 @@ const _Int _Int_MAX_NEG = -9223372036854775807LL;
const _Float _FLOAT_INF_POS = INFINITY; const _Float _FLOAT_INF_POS = INFINITY;
const _Float _FLOAT_INF_NEG = -INFINITY; const _Float _FLOAT_INF_NEG = -INFINITY;
#define PK_VERSION "0.2.5" #define PK_VERSION "0.2.6"
class CodeObject; class CodeObject;
class BasePointer; class BasePointer;

View File

@ -309,12 +309,12 @@ void __initializeBuiltinFunctions(VM* _vm) {
_vm->bindMethod("str", "__repr__", [](VM* vm, PyVarList args) { _vm->bindMethod("str", "__repr__", [](VM* vm, PyVarList args) {
const _Str& _self = vm->PyStr_AS_C(args[0]); 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) { _vm->bindMethod("str", "__json__", [](VM* vm, PyVarList args) {
const _Str& _self = vm->PyStr_AS_C(args[0]); 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) { _vm->bindMethod("str", "__eq__", [](VM* vm, PyVarList args) {

View File

@ -207,6 +207,7 @@ public:
_Str __escape(bool single_quote) const { _Str __escape(bool single_quote) const {
_StrStream ss; _StrStream ss;
ss << (single_quote ? '\'' : '"');
for (auto c = _s->cbegin(); c != _s->cend(); c++) { for (auto c = _s->cbegin(); c != _s->cend(); c++) {
switch (*c) { switch (*c) {
case '"': case '"':
@ -230,6 +231,7 @@ public:
} }
} }
} }
ss << (single_quote ? '\'' : '"');
return ss.str(); return ss.str();
} }
}; };