diff --git a/src/text_editor/buffer_helpers.cpp b/src/text_editor/buffer_helpers.cpp index a07b164..3ddc96a 100644 --- a/src/text_editor/buffer_helpers.cpp +++ b/src/text_editor/buffer_helpers.cpp @@ -21,6 +21,12 @@ String16 GetString(Buffer *buffer, Range range = {0, INT64_MAX}) { return result; } +String AllocCharString(Allocator allocator, Buffer *buffer, Range range = {0, INT64_MAX}) { + String16 string16 = GetString(buffer, range); + String result = ToString(allocator, string16); + return result; +} + Int Clamp(const Buffer *buffer, Int pos) { Int result = Clamp(pos, (Int)0, buffer->len); return result; diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 869af96..798ec9f 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -384,16 +384,14 @@ void SaveBuffer(View *view) { // { // Scratch scratch; - // String16 string16 = GetString(buffer); - // String string = ToString(scratch, string16); + // String string = AllocCharString(scratch, buffer); // Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string); // Command_ReplaceWithoutMovingCarets(view, GetRange(buffer), {temp_buffer->str, temp_buffer->len}); // } - Scratch scratch; - String16 string16 = GetString(buffer); - String string = ToString(scratch, string16); - bool success = WriteFile(buffer->name, string); + Scratch scratch; + String string = AllocCharString(scratch, buffer); + bool success = WriteFile(buffer->name, string); if (success) { buffer->dirty = false; diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 136c74b..929e46b 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -300,9 +300,8 @@ void UpdateLua() { Buffer *lua_buffer = GetBuffer(LuaBufferID); if (lua_buffer->dirty == false && lua_buffer->change_id != LuaBufferChangeID) { - Scratch scratch; - String16 string16 = GetString(lua_buffer); - String string = ToString(scratch, string16); + Scratch scratch; + String string = AllocCharString(scratch, lua_buffer); if (luaL_dostring(LuaState, string.data) == LUA_OK) { if (lua_isstring(LuaState, -1)) { const char *text = lua_tostring(LuaState, -1);