Skip to content

Commit

Permalink
Moved removeEscapeCharFromText() function from 'laf/base/string' to '…
Browse files Browse the repository at this point in the history
…ui/intern'
  • Loading branch information
Gasparoken committed May 22, 2024
1 parent 4276729 commit 94909e8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/app/commands/cmd_tiled_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "app/pref/preferences.h"
#include "filters/tiled_mode.h"
#include "fmt/format.h"
#include "ui/intern.h"

namespace app {

Expand Down Expand Up @@ -79,7 +80,7 @@ std::string TiledModeCommand::onGetFriendlyName() const {
case filters::TiledMode::X_AXIS: mode = Strings::main_menu_view_tiled_mode_x(); break;
case filters::TiledMode::Y_AXIS: mode = Strings::main_menu_view_tiled_mode_y(); break;
}
mode = base::removeEscapeCharFromText(mode, '&');
mode = ui::details::removeEscapeCharFromText(mode, '&');
return fmt::format(getBaseFriendlyName(), mode);
}

Expand Down
21 changes: 20 additions & 1 deletion src/ui/intern.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -9,6 +9,7 @@
#include "config.h"
#endif

#include "base/utf8_decode.h"
#include "ui/manager.h"
#include "ui/system.h"
#include "ui/theme.h"
Expand Down Expand Up @@ -76,5 +77,23 @@ void reinitThemeForAllWidgets()
}
}

std::string removeEscapeCharFromText(const std::string& original,
const int escapeChar)
{
std::wstring newText; // wstring is used to properly push_back() multibyte chars
newText.reserve(original.size());

base::utf8_decode decode(original);
while (int chr = decode.next()) {
if (chr == escapeChar) {
chr = decode.next();
if (!chr)
break; // Ill-formed string (it ends with escape character)
}
newText.push_back(chr);
}
return base::to_utf8(newText);
}

} // namespace details
} // namespace ui
4 changes: 4 additions & 0 deletions src/ui/intern.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -34,6 +35,9 @@ namespace ui {
void reinitThemeForAllWidgets();
int old_guiscale();

std::string removeEscapeCharFromText(const std::string& original,
const int escapeChar);

} // namespace details

} // namespace ui
Expand Down

0 comments on commit 94909e8

Please sign in to comment.