Skip to content

Commit

Permalink
CreateString and FormatString: Remove the now unused max_size argum…
Browse files Browse the repository at this point in the history
…ent from API
  • Loading branch information
mikke89 committed Jul 7, 2024
1 parent 0f8c707 commit 553b6f4
Show file tree
Hide file tree
Showing 41 changed files with 134 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Backends/RmlUi_Backend_SDL_SDLrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Backends/RmlUi_Renderer_GL3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Backends/RmlUi_Renderer_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions Include/RmlUi/Core/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,9 +80,9 @@ namespace StringUtilities {
/// Decode RML characters, eg. '&lt;' 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.
Expand Down
22 changes: 11 additions & 11 deletions Include/RmlUi/Core/TypeConverter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -325,43 +325,43 @@ FLOAT_STRING_CONVERTER(double);
template <>
class TypeConverter<int, String> {
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<unsigned int, String> {
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<long, String> {
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<unsigned long, String> {
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<long long, String> {
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<unsigned long long, String> {
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<byte, String> {
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 <>
Expand All @@ -387,19 +387,19 @@ public:
template <>
class TypeConverter<void*, String> {
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<ScriptInterface*, String> {
public:
static bool Convert(ScriptInterface* const& src, String& dest) { return FormatString(dest, 32, "%p", static_cast<void*>(src)) > 0; }
static bool Convert(ScriptInterface* const& src, String& dest) { return FormatString(dest, "%p", static_cast<void*>(src)) > 0; }
};

template <>
class TypeConverter<char, String> {
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 <typename SourceType, typename InternalType, int count>
Expand Down
2 changes: 1 addition & 1 deletion Samples/basic/animation/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Samples/basic/benchmark/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
<div class="row">
<div class="col col1"><button class="expand" index="%d">+</button>&nbsp;<a>Route %d</a></div>
<div class="col col23"><input type="range" class="assign_range" min="0" max="%d" value="%d"/></div>
Expand Down Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Samples/basic/custom_log/src/SystemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions Samples/basic/data_binding/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,15 @@ namespace InvadersExample {
return false;

// Register a custom getter for the Colourb type.
constructor.RegisterScalar<Rml::Colourb>(
[](const Rml::Colourb& color, Rml::Variant& variant) { variant = Rml::ToString(color); });
constructor.RegisterScalar<Rml::Colourb>([](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())
return {};
const double t = arguments[0].Get<double>();
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.
Expand Down
4 changes: 2 additions & 2 deletions Samples/basic/demo/src/DemoEventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Samples/basic/demo/src/DemoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Samples/invaders/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Samples/invaders/src/HighScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void HighScores::SaveScores()
Rml::String colour_string;
Rml::TypeConverter<Rml::Colourb, Rml::String>::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);
}

Expand Down
8 changes: 4 additions & 4 deletions Samples/lua_invaders/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Samples/lua_invaders/src/HighScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void HighScores::SaveScores()
Rml::String colour_string;
Rml::TypeConverter<Rml::Colourb, Rml::String>::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);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/ComputeProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 553b6f4

Please sign in to comment.