diff --git a/Backends/RmlUi_Backend_SDL_SDLrenderer.cpp b/Backends/RmlUi_Backend_SDL_SDLrenderer.cpp index 893ded18d..f82a785fb 100644 --- a/Backends/RmlUi_Backend_SDL_SDLrenderer.cpp +++ b/Backends/RmlUi_Backend_SDL_SDLrenderer.cpp @@ -93,7 +93,7 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al SDL_RendererInfo renderer_info; if (SDL_GetRendererInfo(renderer, &renderer_info) == 0) { - data->system_interface.LogMessage(Rml::Log::LT_INFO, Rml::CreateString(128, "Using SDL renderer: %s\n", renderer_info.name)); + data->system_interface.LogMessage(Rml::Log::LT_INFO, Rml::CreateString("Using SDL renderer: %s\n", renderer_info.name)); } return true; diff --git a/Backends/RmlUi_BackwardCompatible/RmlUi_Renderer_BackwardCompatible_GL3.cpp b/Backends/RmlUi_BackwardCompatible/RmlUi_Renderer_BackwardCompatible_GL3.cpp index e3a7a0a57..977be990e 100644 --- a/Backends/RmlUi_BackwardCompatible/RmlUi_Renderer_BackwardCompatible_GL3.cpp +++ b/Backends/RmlUi_BackwardCompatible/RmlUi_Renderer_BackwardCompatible_GL3.cpp @@ -779,7 +779,7 @@ bool RmlGL3::Initialize(Rml::String* out_message) } if (out_message) - *out_message = Rml::CreateString(128, "Loaded OpenGL %d.%d.", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version)); + *out_message = Rml::CreateString("Loaded OpenGL %d.%d.", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version)); #endif return true; diff --git a/Backends/RmlUi_Renderer_GL3.cpp b/Backends/RmlUi_Renderer_GL3.cpp index a9d178c45..ed27756b9 100644 --- a/Backends/RmlUi_Renderer_GL3.cpp +++ b/Backends/RmlUi_Renderer_GL3.cpp @@ -939,7 +939,7 @@ void RenderInterface_GL3::EndFrame() else glDisable(GL_SCISSOR_TEST); - if(glstate_backup.enable_depth_test) + if (glstate_backup.enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); @@ -2145,7 +2145,7 @@ bool RmlGL3::Initialize(Rml::String* out_message) } if (out_message) - *out_message = Rml::CreateString(128, "Loaded OpenGL %d.%d.", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version)); + *out_message = Rml::CreateString("Loaded OpenGL %d.%d.", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version)); #endif return true; diff --git a/Backends/RmlUi_Renderer_VK.cpp b/Backends/RmlUi_Renderer_VK.cpp index 3c3109e83..1a3e77613 100644 --- a/Backends/RmlUi_Renderer_VK.cpp +++ b/Backends/RmlUi_Renderer_VK.cpp @@ -56,10 +56,10 @@ static Rml::String FormatByteSize(VkDeviceSize size) noexcept { constexpr VkDeviceSize K = VkDeviceSize(1024); if (size < K) - return Rml::CreateString(32, "%zu B", size); + return Rml::CreateString("%zu B", size); else if (size < K * K) - return Rml::CreateString(32, "%g KB", double(size) / double(K)); - return Rml::CreateString(32, "%g MB", double(size) / double(K * K)); + return Rml::CreateString("%g KB", double(size) / double(K)); + return Rml::CreateString("%g MB", double(size) / double(K * K)); } static VKAPI_ATTR VkBool32 VKAPI_CALL MyDebugReportCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severityFlags, diff --git a/Include/RmlUi/Core/StringUtilities.h b/Include/RmlUi/Core/StringUtilities.h index a81533c02..b5be7dd59 100644 --- a/Include/RmlUi/Core/StringUtilities.h +++ b/Include/RmlUi/Core/StringUtilities.h @@ -42,10 +42,10 @@ namespace Rml { class StringView; /// Construct a string using sprintf-style syntax. -RMLUICORE_API String CreateString(size_t max_size, const char* format, ...) RMLUI_ATTRIBUTE_FORMAT_PRINTF(2, 3); +RMLUICORE_API String CreateString(const char* format, ...) RMLUI_ATTRIBUTE_FORMAT_PRINTF(1, 2); /// Format to a string using sprintf-style syntax. -RMLUICORE_API int FormatString(String& string, size_t max_size, const char* format, ...) RMLUI_ATTRIBUTE_FORMAT_PRINTF(3, 4); +RMLUICORE_API int FormatString(String& string, const char* format, ...) RMLUI_ATTRIBUTE_FORMAT_PRINTF(2, 3); namespace StringUtilities { /// Expands character-delimited list of values in a single string to a whitespace-trimmed list @@ -80,9 +80,9 @@ namespace StringUtilities { /// Decode RML characters, eg. '<' to '<' RMLUICORE_API String DecodeRml(const String& string); - // Replaces all occurences of 'search' in 'subject' with 'replace'. + // Replaces all occurrences of 'search' in 'subject' with 'replace'. RMLUICORE_API String Replace(String subject, const String& search, const String& replace); - // Replaces all occurences of 'search' in 'subject' with 'replace'. + // Replaces all occurrences of 'search' in 'subject' with 'replace'. RMLUICORE_API String Replace(String subject, char search, char replace); /// Checks if a given value is a whitespace character. diff --git a/Include/RmlUi/Core/TypeConverter.inl b/Include/RmlUi/Core/TypeConverter.inl index 6f0848148..cb0ce83f2 100644 --- a/Include/RmlUi/Core/TypeConverter.inl +++ b/Include/RmlUi/Core/TypeConverter.inl @@ -313,7 +313,7 @@ STRING_VECTOR_CONVERTER(Colourf, float, 4); public: \ static bool Convert(const type& src, String& dest) \ { \ - if (FormatString(dest, 32, "%.3f", src) == 0) \ + if (FormatString(dest, "%.3f", src) == 0) \ return false; \ StringUtilities::TrimTrailingDotZeros(dest); \ return true; \ @@ -325,43 +325,43 @@ FLOAT_STRING_CONVERTER(double); template <> class TypeConverter { public: - static bool Convert(const int& src, String& dest) { return FormatString(dest, 32, "%d", src) > 0; } + static bool Convert(const int& src, String& dest) { return FormatString(dest, "%d", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const unsigned int& src, String& dest) { return FormatString(dest, 32, "%u", src) > 0; } + static bool Convert(const unsigned int& src, String& dest) { return FormatString(dest, "%u", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const long& src, String& dest) { return FormatString(dest, 32, "%ld", src) > 0; } + static bool Convert(const long& src, String& dest) { return FormatString(dest, "%ld", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const unsigned long& src, String& dest) { return FormatString(dest, 32, "%lu", src) > 0; } + static bool Convert(const unsigned long& src, String& dest) { return FormatString(dest, "%lu", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const long long& src, String& dest) { return FormatString(dest, 32, "%lld", src) > 0; } + static bool Convert(const long long& src, String& dest) { return FormatString(dest, "%lld", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const unsigned long long& src, String& dest) { return FormatString(dest, 32, "%llu", src) > 0; } + static bool Convert(const unsigned long long& src, String& dest) { return FormatString(dest, "%llu", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const byte& src, String& dest) { return FormatString(dest, 32, "%hhu", src) > 0; } + static bool Convert(const byte& src, String& dest) { return FormatString(dest, "%hhu", src) > 0; } }; template <> @@ -387,19 +387,19 @@ public: template <> class TypeConverter { public: - static bool Convert(void* const& src, String& dest) { return FormatString(dest, 32, "%p", src) > 0; } + static bool Convert(void* const& src, String& dest) { return FormatString(dest, "%p", src) > 0; } }; template <> class TypeConverter { public: - static bool Convert(ScriptInterface* const& src, String& dest) { return FormatString(dest, 32, "%p", static_cast(src)) > 0; } + static bool Convert(ScriptInterface* const& src, String& dest) { return FormatString(dest, "%p", static_cast(src)) > 0; } }; template <> class TypeConverter { public: - static bool Convert(const char& src, String& dest) { return FormatString(dest, 32, "%c", src) > 0; } + static bool Convert(const char& src, String& dest) { return FormatString(dest, "%c", src) > 0; } }; template diff --git a/Samples/basic/animation/src/main.cpp b/Samples/basic/animation/src/main.cpp index efaad9b17..f34664179 100644 --- a/Samples/basic/animation/src/main.cpp +++ b/Samples/basic/animation/src/main.cpp @@ -351,7 +351,7 @@ int main(int /*argc*/, char** /*argv*/) auto el = window->GetDocument()->GetElementById("fps"); float fps = float(count_frames) / dt; count_frames = 0; - el->SetInnerRML(Rml::CreateString(20, "FPS: %f", fps)); + el->SetInnerRML(Rml::CreateString("FPS: %f", fps)); } } diff --git a/Samples/basic/benchmark/src/main.cpp b/Samples/basic/benchmark/src/main.cpp index 6a5ef0cb3..210fdac3e 100644 --- a/Samples/basic/benchmark/src/main.cpp +++ b/Samples/basic/benchmark/src/main.cpp @@ -62,7 +62,7 @@ class DemoWindow { int route = rand() % 50; int max = (rand() % 40) + 10; int value = rand() % max; - Rml::String rml_row = Rml::CreateString(1000, R"( + Rml::String rml_row = Rml::CreateString(R"(
@@ -262,7 +262,7 @@ int main(int /*argc*/, char** /*argv*/) auto el = window->GetDocument()->GetElementById("fps"); count_frames = 0; - el->SetInnerRML(Rml::CreateString(20, "FPS: %f", fps_mean)); + el->SetInnerRML(Rml::CreateString("FPS: %f", fps_mean)); } } diff --git a/Samples/basic/custom_log/src/SystemInterface.cpp b/Samples/basic/custom_log/src/SystemInterface.cpp index 223e84783..c72b8eccd 100644 --- a/Samples/basic/custom_log/src/SystemInterface.cpp +++ b/Samples/basic/custom_log/src/SystemInterface.cpp @@ -69,7 +69,7 @@ bool SystemInterface::LogMessage(Rml::Log::Type type, const Rml::String& message #ifdef RMLUI_PLATFORM_WIN32 if (type == Rml::Log::LT_ASSERT) { - Rml::String assert_message = Rml::CreateString(1024, "%s\nWould you like to interrupt execution?", message.c_str()); + Rml::String assert_message = Rml::CreateString("%s\nWould you like to interrupt execution?", message.c_str()); // Return TRUE if the user presses NO (continue execution) return MessageBoxA(nullptr, assert_message.c_str(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_SYSTEMMODAL) == IDNO; diff --git a/Samples/basic/data_binding/src/main.cpp b/Samples/basic/data_binding/src/main.cpp index ff4ead0c6..7a4aebc7d 100644 --- a/Samples/basic/data_binding/src/main.cpp +++ b/Samples/basic/data_binding/src/main.cpp @@ -229,8 +229,7 @@ namespace InvadersExample { return false; // Register a custom getter for the Colourb type. - constructor.RegisterScalar( - [](const Rml::Colourb& color, Rml::Variant& variant) { variant = Rml::ToString(color); }); + constructor.RegisterScalar([](const Rml::Colourb& color, Rml::Variant& variant) { variant = Rml::ToString(color); }); // Register a transform function for formatting time constructor.RegisterTransformFunc("format_time", [](const Rml::VariantList& arguments) -> Rml::Variant { if (arguments.empty()) @@ -238,7 +237,7 @@ namespace InvadersExample { const double t = arguments[0].Get(); const int minutes = int(t) / 60; const double seconds = t - 60.0 * double(minutes); - return Rml::Variant(Rml::CreateString(10, "%02d:%05.2f", minutes, seconds)); + return Rml::Variant(Rml::CreateString("%02d:%05.2f", minutes, seconds)); }); // Structs are registered by adding all their members through the returned handle. diff --git a/Samples/basic/demo/src/DemoEventListener.cpp b/Samples/basic/demo/src/DemoEventListener.cpp index f3688f942..3190752f4 100644 --- a/Samples/basic/demo/src/DemoEventListener.cpp +++ b/Samples/basic/demo/src/DemoEventListener.cpp @@ -119,7 +119,7 @@ void DemoEventListener::ProcessEvent(Rml::Event& event) demo_window->SetTweeningParameters(tweening_parameters); if (auto el_duration = element->GetElementById("duration")) - el_duration->SetInnerRML(CreateString(20, "%2.2f", value)); + el_duration->SetInnerRML(CreateString("%2.2f", value)); } else if (value == "rating") { @@ -144,7 +144,7 @@ void DemoEventListener::ProcessEvent(Rml::Event& event) else emoji = emojis[Champion]; - el_rating->SetInnerRML(Rml::CreateString(30, "%d%%", value)); + el_rating->SetInnerRML(Rml::CreateString("%d%%", value)); el_rating_emoji->SetInnerRML(emoji); } } diff --git a/Samples/basic/demo/src/DemoWindow.cpp b/Samples/basic/demo/src/DemoWindow.cpp index 533e363a1..3958d43af 100644 --- a/Samples/basic/demo/src/DemoWindow.cpp +++ b/Samples/basic/demo/src/DemoWindow.cpp @@ -150,8 +150,8 @@ void DemoWindow::Update() float value_mapped = value_begin + value_gauge * (value_end - value_begin); gauge->SetAttribute("value", value_mapped); - auto value_gauge_str = CreateString(10, "%d %%", Math::RoundToInteger(value_gauge * 100.f)); - auto value_horizontal_str = CreateString(10, "%d %%", Math::RoundToInteger(value_horizontal * 100.f)); + auto value_gauge_str = CreateString("%d %%", Math::RoundToInteger(value_gauge * 100.f)); + auto value_horizontal_str = CreateString("%d %%", Math::RoundToInteger(value_horizontal * 100.f)); if (auto el_value = document->GetElementById("gauge_value")) el_value->SetInnerRML(value_gauge_str); diff --git a/Samples/invaders/src/Game.cpp b/Samples/invaders/src/Game.cpp index 8c0c10ea1..03d08f242 100644 --- a/Samples/invaders/src/Game.cpp +++ b/Samples/invaders/src/Game.cpp @@ -212,7 +212,7 @@ void Game::SetScore(int score) Rml::Element* score_element = context->GetDocument("game_window")->GetElementById("score"); if (score_element != nullptr) - score_element->SetInnerRML(Rml::CreateString(128, "%d", score).c_str()); + score_element->SetInnerRML(Rml::CreateString("%d", score).c_str()); // Update the high score if we've beaten it. if (score > HighScores::GetHighScore()) @@ -223,7 +223,7 @@ void Game::SetHighScore(int score) { Rml::Element* high_score_element = context->GetDocument("game_window")->GetElementById("hiscore"); if (high_score_element != nullptr) - high_score_element->SetInnerRML(Rml::CreateString(128, "%d", score).c_str()); + high_score_element->SetInnerRML(Rml::CreateString("%d", score).c_str()); } void Game::SetLives(int lives) @@ -232,7 +232,7 @@ void Game::SetLives(int lives) Rml::Element* score_element = context->GetDocument("game_window")->GetElementById("lives"); if (score_element != nullptr) - score_element->SetInnerRML(Rml::CreateString(128, "%d", defender_lives).c_str()); + score_element->SetInnerRML(Rml::CreateString("%d", defender_lives).c_str()); } void Game::SetWave(int wave) @@ -241,7 +241,7 @@ void Game::SetWave(int wave) Rml::Element* waves_element = context->GetDocument("game_window")->GetElementById("waves"); if (waves_element != nullptr) - waves_element->SetInnerRML(Rml::CreateString(128, "%d", wave).c_str()); + waves_element->SetInnerRML(Rml::CreateString("%d", wave).c_str()); } void Game::RemoveLife() diff --git a/Samples/invaders/src/HighScores.cpp b/Samples/invaders/src/HighScores.cpp index bf5e00e8b..68d9dafd6 100644 --- a/Samples/invaders/src/HighScores.cpp +++ b/Samples/invaders/src/HighScores.cpp @@ -176,7 +176,7 @@ void HighScores::SaveScores() Rml::String colour_string; Rml::TypeConverter::Convert(score.colour, colour_string); - Rml::String score_str = Rml::CreateString(1024, "%s\t%s\t%d\t%d\n", score.name.c_str(), colour_string.c_str(), score.wave, score.score); + Rml::String score_str = Rml::CreateString("%s\t%s\t%d\t%d\n", score.name.c_str(), colour_string.c_str(), score.wave, score.score); fputs(score_str.c_str(), scores_file); } diff --git a/Samples/lua_invaders/src/Game.cpp b/Samples/lua_invaders/src/Game.cpp index 298921f7f..38730e987 100644 --- a/Samples/lua_invaders/src/Game.cpp +++ b/Samples/lua_invaders/src/Game.cpp @@ -210,7 +210,7 @@ void Game::SetScore(int score) Rml::Element* score_element = context->GetDocument("game_window")->GetElementById("score"); if (score_element != nullptr) - score_element->SetInnerRML(Rml::CreateString(128, "%d", score).c_str()); + score_element->SetInnerRML(Rml::CreateString("%d", score).c_str()); // Update the high score if we've beaten it. if (score > HighScores::GetHighScore()) @@ -221,7 +221,7 @@ void Game::SetHighScore(int score) { Rml::Element* high_score_element = context->GetDocument("game_window")->GetElementById("hiscore"); if (high_score_element != nullptr) - high_score_element->SetInnerRML(Rml::CreateString(128, "%d", score).c_str()); + high_score_element->SetInnerRML(Rml::CreateString("%d", score).c_str()); } void Game::SetLives(int lives) @@ -230,7 +230,7 @@ void Game::SetLives(int lives) Rml::Element* score_element = context->GetDocument("game_window")->GetElementById("lives"); if (score_element != nullptr) - score_element->SetInnerRML(Rml::CreateString(128, "%d", defender_lives).c_str()); + score_element->SetInnerRML(Rml::CreateString("%d", defender_lives).c_str()); } void Game::SetWave(int wave) @@ -239,7 +239,7 @@ void Game::SetWave(int wave) Rml::Element* waves_element = context->GetDocument("game_window")->GetElementById("waves"); if (waves_element != nullptr) - waves_element->SetInnerRML(Rml::CreateString(128, "%d", wave).c_str()); + waves_element->SetInnerRML(Rml::CreateString("%d", wave).c_str()); } void Game::RemoveLife() diff --git a/Samples/lua_invaders/src/HighScores.cpp b/Samples/lua_invaders/src/HighScores.cpp index bf5e00e8b..68d9dafd6 100644 --- a/Samples/lua_invaders/src/HighScores.cpp +++ b/Samples/lua_invaders/src/HighScores.cpp @@ -176,7 +176,7 @@ void HighScores::SaveScores() Rml::String colour_string; Rml::TypeConverter::Convert(score.colour, colour_string); - Rml::String score_str = Rml::CreateString(1024, "%s\t%s\t%d\t%d\n", score.name.c_str(), colour_string.c_str(), score.wave, score.score); + Rml::String score_str = Rml::CreateString("%s\t%s\t%d\t%d\n", score.name.c_str(), colour_string.c_str(), score.wave, score.score); fputs(score_str.c_str(), scores_file); } diff --git a/Source/Core/ComputeProperty.cpp b/Source/Core/ComputeProperty.cpp index c6806e3f3..cfcfc15c4 100644 --- a/Source/Core/ComputeProperty.cpp +++ b/Source/Core/ComputeProperty.cpp @@ -268,7 +268,7 @@ String GetFontFaceDescription(const String& font_family, Style::FontStyle style, else font_attributes.resize(font_attributes.size() - 2); - return CreateString(font_attributes.size() + font_family.size() + 8, "'%s' [%s]", font_family.c_str(), font_attributes.c_str()); + return CreateString("'%s' [%s]", font_family.c_str(), font_attributes.c_str()); } } // namespace Rml diff --git a/Source/Core/DataExpression.cpp b/Source/Core/DataExpression.cpp index c584753ff..272a4777f 100644 --- a/Source/Core/DataExpression.cpp +++ b/Source/Core/DataExpression.cpp @@ -168,9 +168,9 @@ class DataParser { { const char c = Look(); if (c == '\0') - Error(CreateString(expected_symbols.size() + 50, "Expected %s but found end of string.", expected_symbols.c_str())); + Error(CreateString("Expected %s but found end of string.", expected_symbols.c_str())); else - Error(CreateString(expected_symbols.size() + 50, "Expected %s but found character '%c'.", expected_symbols.c_str(), c)); + Error(CreateString("Expected %s but found character '%c'.", expected_symbols.c_str(), c)); } void Expected(char expected) { Expected(String(1, '\'') + expected + '\''); } @@ -194,12 +194,12 @@ class DataParser { if (!reached_end) { parse_error = true; - Error(CreateString(50, "Unexpected character '%c' encountered.", Look())); + Error(CreateString("Unexpected character '%c' encountered.", Look())); } if (!parse_error && program_stack_size != 0) { parse_error = true; - Error(CreateString(120, "Internal parser error, inconsistent stack operations. Stack size is %d at parse end.", program_stack_size)); + Error(CreateString("Internal parser error, inconsistent stack operations. Stack size is %d at parse end.", program_stack_size)); } return !parse_error; @@ -246,7 +246,7 @@ class DataParser { RMLUI_ASSERT(num_arguments >= 0); if (program_stack_size < num_arguments) { - Error(CreateString(128, "Internal parser error: Popping %d arguments, but the stack contains only %d elements.", num_arguments, + Error(CreateString("Internal parser error: Popping %d arguments, but the stack contains only %d elements.", num_arguments, program_stack_size)); return; } @@ -284,7 +284,7 @@ class DataParser { DataAddress address = expression_interface.ParseAddress(name); if (address.empty()) { - Error(CreateString(name.size() + 50, "Could not find data variable with name '%s'.", name.c_str())); + Error(CreateString("Could not find data variable with name '%s'.", name.c_str())); return; } int index = int(variable_addresses.size()); @@ -401,7 +401,7 @@ namespace Parse { if (!first_match) { if (!silent) - parser.Error(CreateString(100, "Invalid number literal. Expected '0-9' or '.' but found '%c'.", c)); + parser.Error(CreateString("Invalid number literal. Expected '0-9' or '.' but found '%c'.", c)); return String(); } @@ -907,7 +907,7 @@ static String DumpProgram(const Program& program) for (size_t i = 0; i < program.size(); i++) { String instruction_str = program[i].data.Get(); - str += CreateString(50 + instruction_str.size(), " %4zu '%c' %s\n", i, char(program[i].instruction), instruction_str.c_str()); + str += CreateString(" %4zu '%c' %s\n", i, char(program[i].instruction), instruction_str.c_str()); } return str; } @@ -986,7 +986,7 @@ class DataInterpreter { case Register::L: L = stack.back(); stack.pop_back(); break; case Register::C: C = stack.back(); stack.pop_back(); break; // clang-format on - default: return Error(CreateString(50, "Invalid register %d.", int(reg))); + default: return Error(CreateString("Invalid register %d.", int(reg))); } } break; @@ -1080,9 +1080,9 @@ class DataInterpreter { if (i < arguments.size() - 1) arguments_str += ", "; } - return Error(CreateString(60 + function_name.size() + arguments_str.size(), "Failed to execute %s: %s(%s)", - instruction == Instruction::TransformFnc ? "transform function" : "event callback", function_name.c_str(), - arguments_str.c_str())); + return Error( + CreateString("Failed to execute %s: %s(%s)", instruction == Instruction::TransformFnc ? "transform function" : "event callback", + function_name.c_str(), arguments_str.c_str())); } } break; @@ -1118,7 +1118,7 @@ class DataInterpreter { if (num_arguments < 0) return Error("Invalid number of arguments."); if (stack.size() < size_t(num_arguments)) - return Error(CreateString(100, "Cannot pop %d arguments, stack contains only %zu elements.", num_arguments, stack.size())); + return Error(CreateString("Cannot pop %d arguments, stack contains only %zu elements.", num_arguments, stack.size())); const auto it_stack_begin_arguments = stack.end() - num_arguments; out_arguments.insert(out_arguments.end(), std::make_move_iterator(it_stack_begin_arguments), std::make_move_iterator(stack.end())); diff --git a/Source/Core/DataTypeRegister.cpp b/Source/Core/DataTypeRegister.cpp index d398f1591..ff933f14a 100644 --- a/Source/Core/DataTypeRegister.cpp +++ b/Source/Core/DataTypeRegister.cpp @@ -83,7 +83,7 @@ DataTypeRegister::DataTypeRegister() String format_specifier = String(remove_trailing_zeros ? "%#." : "%.") + ToString(precision) + 'f'; String result; - if (FormatString(result, 64, format_specifier.c_str(), value) == 0) + if (FormatString(result, format_specifier.c_str(), value) == 0) return {}; if (remove_trailing_zeros) diff --git a/Source/Core/DecoratorTiled.cpp b/Source/Core/DecoratorTiled.cpp index 9206ee5fa..45e75f79d 100644 --- a/Source/Core/DecoratorTiled.cpp +++ b/Source/Core/DecoratorTiled.cpp @@ -168,17 +168,17 @@ void DecoratorTiled::Tile::GenerateGeometry(Mesh& mesh, const ComputedValues& co case REPEAT: final_tile_dimensions = surface_dimensions; repeat_factor = surface_dimensions / tile_dimensions; - break; + break; case REPEAT_X: final_tile_dimensions = Vector2f(surface_dimensions.x, tile_dimensions.y); repeat_factor.x = surface_dimensions.x / tile_dimensions.x; offset_and_clip_tile = true; - break; + break; case REPEAT_Y: final_tile_dimensions = Vector2f(tile_dimensions.x, surface_dimensions.y); repeat_factor.y = surface_dimensions.y / tile_dimensions.y; offset_and_clip_tile = true; - break; + break; } Vector2f tile_offset(0, 0); @@ -249,32 +249,32 @@ void DecoratorTiledInstancer::RegisterTileProperty(const String& name, bool regi { TilePropertyIds ids = {}; - ids.src = RegisterProperty(CreateString(32, "%s-src", name.c_str()), "").AddParser("string").GetId(); + ids.src = RegisterProperty(CreateString("%s-src", name.c_str()), "").AddParser("string").GetId(); String additional_modes; if (register_fit_modes) { - String fit_name = CreateString(32, "%s-fit", name.c_str()); + String fit_name = CreateString("%s-fit", name.c_str()); ids.fit = RegisterProperty(fit_name, "fill") .AddParser("keyword", "fill, contain, cover, scale-none, scale-down, repeat, repeat-x, repeat-y") .GetId(); - String align_x_name = CreateString(32, "%s-align-x", name.c_str()); + String align_x_name = CreateString("%s-align-x", name.c_str()); ids.align_x = RegisterProperty(align_x_name, "center").AddParser("keyword", "left, center, right").AddParser("length_percent").GetId(); - String align_y_name = CreateString(32, "%s-align-y", name.c_str()); + String align_y_name = CreateString("%s-align-y", name.c_str()); ids.align_y = RegisterProperty(align_y_name, "center").AddParser("keyword", "top, center, bottom").AddParser("length_percent").GetId(); additional_modes += ", " + fit_name + ", " + align_x_name + ", " + align_y_name; } - ids.orientation = RegisterProperty(CreateString(32, "%s-orientation", name.c_str()), "none") + ids.orientation = RegisterProperty(CreateString("%s-orientation", name.c_str()), "none") .AddParser("keyword", "none, flip-horizontal, flip-vertical, rotate-180") .GetId(); RegisterShorthand(name, - CreateString(256, ("%s-src, %s-orientation" + additional_modes).c_str(), name.c_str(), name.c_str(), name.c_str(), name.c_str(), name.c_str(), + CreateString(("%s-src, %s-orientation" + additional_modes).c_str(), name.c_str(), name.c_str(), name.c_str(), name.c_str(), name.c_str(), name.c_str()), ShorthandType::FallThrough); diff --git a/Source/Core/Elements/InputTypeRange.cpp b/Source/Core/Elements/InputTypeRange.cpp index 0801b4d16..193c20843 100644 --- a/Source/Core/Elements/InputTypeRange.cpp +++ b/Source/Core/Elements/InputTypeRange.cpp @@ -45,7 +45,7 @@ InputTypeRange::~InputTypeRange() String InputTypeRange::GetValue() const { - return CreateString(32, "%f", widget->GetValue()); + return CreateString("%f", widget->GetValue()); } void InputTypeRange::OnUpdate() diff --git a/Source/Core/EventDispatcher.cpp b/Source/Core/EventDispatcher.cpp index 5d1fdf48c..ec331c632 100644 --- a/Source/Core/EventDispatcher.cpp +++ b/Source/Core/EventDispatcher.cpp @@ -257,7 +257,7 @@ String EventDispatcher::ToString() const auto add_to_result = [&result](EventId id, int count) { const EventSpecification& specification = EventSpecificationInterface::Get(id); - result += CreateString(specification.type.size() + 32, "%s (%d), ", specification.type.c_str(), count); + result += CreateString("%s (%d), ", specification.type.c_str(), count); }; EventId previous_id = listeners[0].id; diff --git a/Source/Core/Layout/BlockFormattingContext.cpp b/Source/Core/Layout/BlockFormattingContext.cpp index 40783976f..f05ff28b4 100644 --- a/Source/Core/Layout/BlockFormattingContext.cpp +++ b/Source/Core/Layout/BlockFormattingContext.cpp @@ -118,7 +118,7 @@ UniquePtr BlockFormattingContext::Format(ContainerBox* parent_contain #ifdef RMLUI_TRACY_PROFILING RMLUI_ZoneScopedC(0xB22222); - auto name = CreateString(80, "%s %x", element->GetAddress(false, false).c_str(), element); + auto name = CreateString("%s %x", element->GetAddress(false, false).c_str(), element); RMLUI_ZoneName(name.c_str(), name.size()); #endif @@ -214,7 +214,7 @@ bool BlockFormattingContext::FormatBlockContainerChild(BlockContainer* parent_co { #ifdef RMLUI_TRACY_PROFILING RMLUI_ZoneScoped; - auto name = CreateString(80, ">%s %x", element->GetAddress(false, false).c_str(), element); + auto name = CreateString(">%s %x", element->GetAddress(false, false).c_str(), element); RMLUI_ZoneName(name.c_str(), name.size()); #endif diff --git a/Source/Core/Log.cpp b/Source/Core/Log.cpp index fa8e5d491..78ef81195 100644 --- a/Source/Core/Log.cpp +++ b/Source/Core/Log.cpp @@ -82,7 +82,7 @@ void Log::ParseError(const String& filename, int line_number, const char* fmt, . bool Assert(const char* msg, const char* file, int line) { - String message = CreateString(1024, "%s\n%s:%d", msg, file, line); + String message = CreateString("%s\n%s:%d", msg, file, line); bool result = true; if (SystemInterface* system_interface = GetSystemInterface()) diff --git a/Source/Core/LogDefault.cpp b/Source/Core/LogDefault.cpp index 3da501712..309eb553b 100644 --- a/Source/Core/LogDefault.cpp +++ b/Source/Core/LogDefault.cpp @@ -43,7 +43,7 @@ bool LogDefault::LogMessage(Log::Type type, const String& message) #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) if (type == Log::LT_ASSERT) { - String message_user = CreateString(1024, "%s\nWould you like to interrupt execution?", message.c_str()); + String message_user = CreateString("%s\nWould you like to interrupt execution?", message.c_str()); // Return TRUE if the user presses NO (continue execution) return (IDNO == MessageBoxA(nullptr, message_user.c_str(), "Assertion Failure", MB_YESNO | MB_ICONSTOP | MB_DEFBUTTON2 | MB_TASKMODAL)); diff --git a/Source/Core/StringUtilities.cpp b/Source/Core/StringUtilities.cpp index e04e397cf..f83456941 100644 --- a/Source/Core/StringUtilities.cpp +++ b/Source/Core/StringUtilities.cpp @@ -76,7 +76,7 @@ static int FormatString(String& string, const char* format, va_list argument_lis return length; } -int FormatString(String& string, size_t /*max_size*/, const char* format, ...) +int FormatString(String& string, const char* format, ...) { va_list argument_list; va_start(argument_list, format); @@ -84,7 +84,7 @@ int FormatString(String& string, size_t /*max_size*/, const char* format, ...) va_end(argument_list); return result; } -String CreateString(size_t /*max_size*/, const char* format, ...) +String CreateString(const char* format, ...) { String result; va_list argument_list; diff --git a/Source/Core/TypeConverter.cpp b/Source/Core/TypeConverter.cpp index 24d1b0267..f59e784e1 100644 --- a/Source/Core/TypeConverter.cpp +++ b/Source/Core/TypeConverter.cpp @@ -295,9 +295,9 @@ bool TypeConverter::Convert(const BoxShadowList& src, Str bool TypeConverter::Convert(const Colourb& src, String& dest) { if (src.alpha == 255) - return FormatString(dest, 32, "#%02hhx%02hhx%02hhx", src.red, src.green, src.blue) > 0; + return FormatString(dest, "#%02hhx%02hhx%02hhx", src.red, src.green, src.blue) > 0; else - return FormatString(dest, 32, "#%02hhx%02hhx%02hhx%02hhx", src.red, src.green, src.blue, src.alpha) > 0; + return FormatString(dest, "#%02hhx%02hhx%02hhx%02hhx", src.red, src.green, src.blue, src.alpha) > 0; } bool TypeConverter::Convert(const String& src, Colourb& dest) diff --git a/Source/Debugger/ElementInfo.cpp b/Source/Debugger/ElementInfo.cpp index 6ba6e5453..66e8f6c3f 100644 --- a/Source/Debugger/ElementInfo.cpp +++ b/Source/Debugger/ElementInfo.cpp @@ -448,13 +448,13 @@ void ElementInfo::UpdateSourceElement() name = "id"; value = source_element->GetId(); if (!value.empty()) - attributes += CreateString(name.size() + value.size() + 32, "%s: %s
", name.c_str(), value.c_str()); + attributes += CreateString("%s: %s
", name.c_str(), value.c_str()); } { name = "class"; value = source_element->GetClassNames(); if (!value.empty()) - attributes += CreateString(name.size() + value.size() + 32, "%s: %s
", name.c_str(), value.c_str()); + attributes += CreateString("%s: %s
", name.c_str(), value.c_str()); } } @@ -464,14 +464,14 @@ void ElementInfo::UpdateSourceElement() auto& variant = pair.second; String value = StringUtilities::EncodeRml(variant.Get()); if (name != "class" && name != "style" && name != "id") - attributes += CreateString(name.size() + value.size() + 32, "%s: %s
", name.c_str(), value.c_str()); + attributes += CreateString("%s: %s
", name.c_str(), value.c_str()); } // Text is not an attribute but useful nonetheless if (auto text_element = rmlui_dynamic_cast(source_element)) { const String& text_content = text_element->GetText(); - attributes += CreateString(text_content.size() + 32, "Text: %s
", text_content.c_str()); + attributes += CreateString("Text: %s
", text_content.c_str()); } } @@ -548,7 +548,7 @@ void ElementInfo::UpdateSourceElement() ToString(box.GetEdge(BoxArea::Padding, edge1)); const String edge2_str = ToString(box.GetEdge(BoxArea::Padding, edge2)) + "|" + ToString(box.GetEdge(BoxArea::Border, edge2)) + "|" + ToString(box.GetEdge(BoxArea::Margin, edge2)); - return CreateString(256, "%s <%s> %s", edge1_str.c_str(), ToString(content_size).c_str(), edge2_str.c_str()); + return CreateString("%s <%s> %s", edge1_str.c_str(), ToString(content_size).c_str(), edge2_str.c_str()); }; position = "left: " + ToString(element_offset.x) + "px
" + // @@ -579,7 +579,7 @@ void ElementInfo::UpdateSourceElement() while (element_ancestor) { String ancestor_name = element_ancestor->GetAddress(false, false); - ancestors += CreateString(ancestor_name.size() + 32, "

%s

", ancestor_depth, ancestor_name.c_str()); + ancestors += CreateString("

%s

", ancestor_depth, ancestor_name.c_str()); element_ancestor = element_ancestor->GetParentNode(); ancestor_depth++; } @@ -620,7 +620,7 @@ void ElementInfo::UpdateSourceElement() const char* non_dom_string = (i >= num_dom_children ? " class=\"non_dom\"" : ""); - children += CreateString(child_name.size() + 40, "

%s

", i, non_dom_string, child_name.c_str()); + children += CreateString("

%s

", i, non_dom_string, child_name.c_str()); } } diff --git a/Source/Debugger/ElementLog.cpp b/Source/Debugger/ElementLog.cpp index f693b1adb..ec81802c7 100644 --- a/Source/Debugger/ElementLog.cpp +++ b/Source/Debugger/ElementLog.cpp @@ -210,7 +210,7 @@ void ElementLog::OnUpdate() int num_messages = 0; while (next_type != -1 && num_messages < MAX_LOG_MESSAGES) { - messages += CreateString(128, "
%s

", + messages += CreateString("

%s

", log_types[next_type].class_name.c_str(), log_types[next_type].alert_contents.c_str()); messages += log_types[next_type].log_messages[log_pointers[next_type]].message; messages += "

"; diff --git a/Tests/Source/Benchmarks/DataBinding.cpp b/Tests/Source/Benchmarks/DataBinding.cpp index ad435e44c..4a453c3a2 100644 --- a/Tests/Source/Benchmarks/DataBinding.cpp +++ b/Tests/Source/Benchmarks/DataBinding.cpp @@ -227,7 +227,7 @@ TEST_CASE("data_binding") bench.run("Reference (Arrays)", [&] { element_array->SetInnerRML( - Rml::CreateString(128, "%d %d %d ", rng.bounded(5000), rng.bounded(5000), rng.bounded(5000))); + Rml::CreateString("%d %d %d ", rng.bounded(5000), rng.bounded(5000), rng.bounded(5000))); context->Update(); }); diff --git a/Tests/Source/Benchmarks/Element.cpp b/Tests/Source/Benchmarks/Element.cpp index ae8e29d9b..0b7b630ff 100644 --- a/Tests/Source/Benchmarks/Element.cpp +++ b/Tests/Source/Benchmarks/Element.cpp @@ -52,7 +52,7 @@ static const String document_rml = R"( width: 1300px; height: 600px; } - #performance + #performance { width: 800px; height: 300px; @@ -122,7 +122,7 @@ static String GenerateRml(const int num_rows, const char* row) int route = rng() % 50; int max = (rng() % 40) + 10; int value = rng() % max; - Rml::String rml_row = Rml::CreateString(10000, row, index, route, max, value); + Rml::String rml_row = Rml::CreateString(row, index, route, max, value); rml += rml_row; } @@ -148,7 +148,7 @@ TEST_CASE("element.creation_and_destruction") context->Render(); TestsShell::RenderLoop(); - String msg = Rml::CreateString(128, "\nElement construction and destruction of %d total elements.\n", GetNumDescendentElements(el)); + String msg = Rml::CreateString("\nElement construction and destruction of %d total elements.\n", GetNumDescendentElements(el)); msg += TestsShell::GetRenderStats(); MESSAGE(msg); @@ -211,7 +211,7 @@ TEST_CASE("element.long_texts") context->Render(); TestsShell::RenderLoop(); - String msg = Rml::CreateString(128, "\nElement construction and destruction of %d total very long elements.\n", GetNumDescendentElements(el)); + String msg = Rml::CreateString("\nElement construction and destruction of %d total very long elements.\n", GetNumDescendentElements(el)); msg += TestsShell::GetRenderStats(); MESSAGE(msg); diff --git a/Tests/Source/Benchmarks/FontEffect.cpp b/Tests/Source/Benchmarks/FontEffect.cpp index 2ef7c2d82..cdb3577b9 100644 --- a/Tests/Source/Benchmarks/FontEffect.cpp +++ b/Tests/Source/Benchmarks/FontEffect.cpp @@ -68,7 +68,7 @@ TEST_CASE("font_effect") { constexpr int effect_size = 8; - const String rml_document = CreateString(rml_font_effect_document.size() + 100, rml_font_effect_document.c_str(), effect_name, effect_size); + const String rml_document = CreateString(rml_font_effect_document.c_str(), effect_name, effect_size); ElementDocument* document = context->LoadDocumentFromMemory(rml_document); document->Show(); diff --git a/Tests/Source/Benchmarks/Selectors.cpp b/Tests/Source/Benchmarks/Selectors.cpp index 6aac13b1a..3617ae004 100644 --- a/Tests/Source/Benchmarks/Selectors.cpp +++ b/Tests/Source/Benchmarks/Selectors.cpp @@ -40,7 +40,7 @@ using namespace Rml; static constexpr const char* document_rml_template = R"( - + Benchmark Sample