diff --git a/include/pocketpy/str.h b/include/pocketpy/str.h index 612b720b..4a4b4ded 100644 --- a/include/pocketpy/str.h +++ b/include/pocketpy/str.h @@ -23,7 +23,7 @@ struct Str{ char* data; char _inlined[16]; - const char* _cached_c_str = nullptr; + mutable const char* _cached_c_str = nullptr; bool is_inlined() const { return data == _inlined; } @@ -124,7 +124,7 @@ struct Str{ Str substr(int start, int len) const; Str substr(int start) const; char* c_str_dup() const; - const char* c_str(); + const char* c_str() const; std::string_view sv() const; std::string str() const; Str lstrip() const; diff --git a/src/str.cpp b/src/str.cpp index d98bb24d..35cb1f2b 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -103,7 +103,7 @@ namespace pkpy { return p; } - const char* Str::c_str(){ + const char* Str::c_str() const{ if(_cached_c_str == nullptr){ _cached_c_str = c_str_dup(); }