diff --git a/src/core/base/version.cpp b/src/core/base/version.cpp index 82020abd..e81953d5 100644 --- a/src/core/base/version.cpp +++ b/src/core/base/version.cpp @@ -1,4 +1,7 @@ #include "core/base/version.h" +#include "core/base/version_gen.h" + +const std::string kVbamMainVersion = VBAM_CURRENT_VERSION; const std::string kVbamNameAndSubversion = VBAM_NAME_AND_SUBVERSION; const std::string kVbamVersion = VBAM_VERSION; diff --git a/src/core/base/version.h b/src/core/base/version.h index 4cb89a44..9e0201af 100644 --- a/src/core/base/version.h +++ b/src/core/base/version.h @@ -3,7 +3,9 @@ #include -#include "core/base/version_gen.h" +// Main version information, generated by the build system. +// e.g. "2.1.9" +extern const std::string kVbamMainVersion; // Full version information, generated by the build system. // e.g. "VisualBoyAdvance-M 2.1.9-316e4a43 msvc-316e4a43" diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index a3e952a3..593ab75f 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -31,6 +31,8 @@ set(VBAM_WX_COMMON config/option-proxy.h config/option.cpp config/option.h + config/strutils.cpp + config/strutils.h config/user-input.cpp config/user-input.h dialogs/accel-config.cpp @@ -60,8 +62,6 @@ set(VBAM_WX_COMMON opts.h panel.cpp rpi.h - strutils.cpp - strutils.h sys.cpp viewers.cpp viewsupt.cpp diff --git a/src/wx/autoupdater/autoupdater.h b/src/wx/autoupdater/autoupdater.h index 7c5aa9e4..d7c3403f 100644 --- a/src/wx/autoupdater/autoupdater.h +++ b/src/wx/autoupdater/autoupdater.h @@ -1,8 +1,8 @@ -#ifndef AUTOUPDATER_H -#define AUTOUPDATER_H +#ifndef VBAM_WX_AUTOUPDATER_AUTOUPDATER_H_ +#define VBAM_WX_AUTOUPDATER_AUTOUPDATER_H_ void initAutoupdater(); void checkUpdatesUi(); void shutdownAutoupdater(); -#endif // AUTOUPDATER_H +#endif // VBAM_WX_AUTOUPDATER_AUTOUPDATER_H_ diff --git a/src/wx/autoupdater/macos/autoupdater.cpp b/src/wx/autoupdater/macos/autoupdater.cpp index 485f4fe8..cf8f27ef 100644 --- a/src/wx/autoupdater/macos/autoupdater.cpp +++ b/src/wx/autoupdater/macos/autoupdater.cpp @@ -1,5 +1,6 @@ -#include "../autoupdater.h" -#include "sparkle-wrapper.h" +#include "wx/autoupdater/autoupdater.h" + +#include "wx/autoupdater/macos/sparkle-wrapper.h" SparkleWrapper autoupdater; diff --git a/src/wx/autoupdater/macos/sparkle-wrapper.h b/src/wx/autoupdater/macos/sparkle-wrapper.h index f83f39ed..524ed6bd 100644 --- a/src/wx/autoupdater/macos/sparkle-wrapper.h +++ b/src/wx/autoupdater/macos/sparkle-wrapper.h @@ -1,5 +1,5 @@ -#ifndef SPARKLE_WRAPPER_H -#define SPARKLE_WRAPPER_H +#ifndef VBAM_WX_AUTOUPDATER_MACOS_SPARKLE_WRAPPER_H_ +#define VBAM_WX_AUTOUPDATER_MACOS_SPARKLE_WRAPPER_H_ class SparkleWrapper { @@ -14,4 +14,4 @@ class SparkleWrapper Private* d; }; -#endif // SPARKLE_WRAPPER_H +#endif // VBAM_WX_AUTOUPDATER_MACOS_SPARKLE_WRAPPER_H_ diff --git a/src/wx/autoupdater/wxmsw/autoupdater.cpp b/src/wx/autoupdater/wxmsw/autoupdater.cpp index a7970d55..7f3a54a5 100644 --- a/src/wx/autoupdater/wxmsw/autoupdater.cpp +++ b/src/wx/autoupdater/wxmsw/autoupdater.cpp @@ -1,14 +1,13 @@ -#include "../autoupdater.h" +#include "wx/autoupdater/autoupdater.h" #include "core/base/version.h" -#include "../../strutils.h" -#include "winsparkle-wrapper.h" +#include "wx/autoupdater/wxmsw/winsparkle-wrapper.h" void initAutoupdater() { // even if we are a nightly, only check latest stable version - wxString version = strutils::split(kVbamVersion, '-')[0]; + const wxString version(kVbamMainVersion); #ifndef NO_HTTPS win_sparkle_set_appcast_url("https://data.visualboyadvance-m.org/appcast.xml"); #else diff --git a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp index 5de96086..cb225c96 100644 --- a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp +++ b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.cpp @@ -1,12 +1,13 @@ +#include "wx/autoupdater/wxmsw/winsparkle-wrapper.h" + #include -#include -#include +#include +#include +#include #include -#include "wx/wxvbam.h" -#include "winsparkle-wrapper.h" -#include "wx/msw/private.h" +#include "wx/autoupdater/wxmsw/winsparkle-rc.h" WinSparkleDllWrapper *WinSparkleDllWrapper::GetInstance() { diff --git a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h index 16354bc6..84309ee1 100644 --- a/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h +++ b/src/wx/autoupdater/wxmsw/winsparkle-wrapper.h @@ -4,8 +4,6 @@ #include #include -#include "winsparkle-rc.h" - class WinSparkleDllWrapper { public: static WinSparkleDllWrapper *GetInstance(); diff --git a/src/wx/config/bindings.cpp b/src/wx/config/bindings.cpp index d52bc63b..17bc375a 100644 --- a/src/wx/config/bindings.cpp +++ b/src/wx/config/bindings.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "wx/config/user-input.h" diff --git a/src/wx/config/bindings.h b/src/wx/config/bindings.h index 57615f69..0fd80383 100644 --- a/src/wx/config/bindings.h +++ b/src/wx/config/bindings.h @@ -3,7 +3,6 @@ #include #include -#include #include #include "wx/config/command.h" diff --git a/src/wx/config/command.cpp b/src/wx/config/command.cpp index dab3f839..daf1e462 100644 --- a/src/wx/config/command.cpp +++ b/src/wx/config/command.cpp @@ -6,7 +6,7 @@ #include #include "wx/config/cmdtab.h" -#include "wx/strutils.h" +#include "wx/config/strutils.h" namespace config { namespace { @@ -131,7 +131,7 @@ nonstd::optional Command::FromString(const wxString& name) { return nonstd::nullopt; } - auto parts = strutils::split(name, "/"); + auto parts = config::str_split(name, "/"); if (is_joypad) { if (parts.size() != 3) { wxLogDebug("Wrong split size: %d", parts.size()); diff --git a/src/wx/strutils.cpp b/src/wx/config/strutils.cpp similarity index 70% rename from src/wx/strutils.cpp rename to src/wx/config/strutils.cpp index 1ad95357..3d506d94 100644 --- a/src/wx/strutils.cpp +++ b/src/wx/config/strutils.cpp @@ -1,13 +1,13 @@ -#include "wx/strutils.h" +#include "wx/config/strutils.h" #include -namespace strutils { +namespace config { // From: https://stackoverflow.com/a/7408245/262458 // // Modified to ignore empty tokens or return sep for them. -wxArrayString split(const wxString& text, const wxString& sep, bool empty_token_is_sep) { +wxArrayString str_split(const wxString& text, const wxString& sep, bool empty_token_is_sep) { wxArrayString tokens; size_t start = 0, end = 0; @@ -32,9 +32,9 @@ wxArrayString split(const wxString& text, const wxString& sep, bool empty_token_ return tokens; } -wxArrayString split_with_sep(const wxString& text, const wxString& sep) +wxArrayString str_split_with_sep(const wxString& text, const wxString& sep) { - return split(text, sep, true); + return str_split(text, sep, true); } -} // namespace strutils +} // namespace config diff --git a/src/wx/config/strutils.h b/src/wx/config/strutils.h new file mode 100644 index 00000000..49fd6b07 --- /dev/null +++ b/src/wx/config/strutils.h @@ -0,0 +1,19 @@ +#ifndef VBAM_WX_CONFIG_STRUTILS_H_ +#define VBAM_WX_CONFIG_STRUTILS_H_ + +#include +#include + +namespace config { + +// From: https://stackoverflow.com/a/7408245/262458 +wxArrayString str_split(const wxString& text, const wxString& sep, bool empty_token_is_sep=false); + +// Same as above, but it includes the sep dir. +// If "A,,,B" is the text and "," is sep, then +// 'A', ',' and 'B' will be in the output. +wxArrayString str_split_with_sep(const wxString& text, const wxString& sep); + +} // namespace config + +#endif // VBAM_WX_CONFIG_STRUTILS_H_ diff --git a/src/wx/config/strutils_test.cpp b/src/wx/config/strutils_test.cpp new file mode 100644 index 00000000..ea061d33 --- /dev/null +++ b/src/wx/config/strutils_test.cpp @@ -0,0 +1,96 @@ +#include "wx/config/strutils.h" + +#include + +TEST(StrSplitTest, Basic) { + wxString foo = "foo|bar|baz"; + + auto vec = config::str_split(foo, '|'); + + EXPECT_EQ(vec.size(), 3); + + EXPECT_EQ(vec[0], "foo"); + EXPECT_EQ(vec[1], "bar"); + EXPECT_EQ(vec[2], "baz"); +} + +TEST(StrSplitTest, MultiCharSep) { + wxString foo = "foo|-|bar|-|baz"; + + auto vec = config::str_split(foo, "|-|"); + + EXPECT_EQ(vec.size(), 3); + + EXPECT_EQ(vec[0], "foo"); + EXPECT_EQ(vec[1], "bar"); + EXPECT_EQ(vec[2], "baz"); +} + +TEST(StrSplitTest, SkipEmptyToken) { + wxString foo = "|-|foo|-||-|bar|-|baz|-|"; + + auto vec = config::str_split(foo, "|-|"); + + EXPECT_EQ(vec.size(), 3); + + EXPECT_EQ(vec[0], "foo"); + EXPECT_EQ(vec[1], "bar"); + EXPECT_EQ(vec[2], "baz"); +} + +TEST(StrSplitTest, EmptyInput) { + wxString foo; + + auto vec = config::str_split(foo, "|-|"); + + EXPECT_EQ(vec.size(), 0); +} + +TEST(StrSplitTest, NoTokens) { + wxString foo = "|-||-||-||-||-|"; + + auto vec = config::str_split(foo, "|-|"); + + EXPECT_EQ(vec.size(), 0); +} + +TEST(StrSplitWithSepTest, Basic) { + wxString foo = "foo|bar|baz|"; + + auto vec = config::str_split_with_sep(foo, '|'); + + EXPECT_EQ(vec.size(), 4); + + EXPECT_EQ(vec[0], "foo"); + EXPECT_EQ(vec[1], "bar"); + EXPECT_EQ(vec[2], "baz"); + EXPECT_EQ(vec[3], "|"); +} + +TEST(StrSplitWithSepTest, MultiCharSep) { + wxString foo = "foo|-|bar|-|baz|-|"; + + auto vec = config::str_split_with_sep(foo, "|-|"); + + EXPECT_EQ(vec.size(), 4); + + EXPECT_EQ(vec[0], "foo"); + EXPECT_EQ(vec[1], "bar"); + EXPECT_EQ(vec[2], "baz"); + EXPECT_EQ(vec[3], "|-|"); +} + +TEST(StrSplitWithSepTest, MultipleSepTokens) { + wxString foo = "|-|foo|-||-|bar|-|baz|-|"; + + auto vec = config::str_split_with_sep(foo, "|-|"); + + EXPECT_EQ(vec.size(), 6); + + EXPECT_EQ(vec[0], "|-|"); + EXPECT_EQ(vec[1], "foo"); + EXPECT_EQ(vec[2], "|-|"); + EXPECT_EQ(vec[3], "bar"); + EXPECT_EQ(vec[4], "baz"); + EXPECT_EQ(vec[5], "|-|"); +} diff --git a/src/wx/config/user-input.cpp b/src/wx/config/user-input.cpp index 62f58114..361d8194 100644 --- a/src/wx/config/user-input.cpp +++ b/src/wx/config/user-input.cpp @@ -7,7 +7,7 @@ #include #include -#include "wx/strutils.h" +#include "wx/config/strutils.h" namespace config { @@ -186,7 +186,7 @@ UserInput StringToUserInput(const wxString& string) { // Not a joystick. // Non-ASCII keyboard input are treated as a pair of integers "key:mod". - const auto pair = strutils::split(string, ":"); + const auto pair = config::str_split(string, ":"); long mod = 0; long key = 0; if (pair.size() == 2 && pair[0].ToLong(&key) && pair[1].ToLong(&mod)) { @@ -330,7 +330,7 @@ std::unordered_set UserInput::FromConfigString(const wxString& string return user_inputs; } - for (const auto& token : strutils::split_with_sep(string, ",")) { + for (const auto& token : config::str_split_with_sep(string, ",")) { UserInput user_input = StringToUserInput(token); if (!user_input) { user_inputs.clear(); diff --git a/src/wx/strutils.h b/src/wx/strutils.h deleted file mode 100644 index e195175e..00000000 --- a/src/wx/strutils.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef VBAM_WX_STRUTILS_H_ -#define VBAM_WX_STRUTILS_H_ - -#include -#include - -namespace strutils { - -// From: https://stackoverflow.com/a/7408245/262458 -wxArrayString split(const wxString& text, const wxString& sep, bool empty_token_is_sep=false); - -// Same as above, but it includes the sep dir. -// If "A,,,B" is the text and "," is sep, then -// 'A', ',' and 'B' will be in the output. -wxArrayString split_with_sep(const wxString& text, const wxString& sep); - -} // namespace strutils - -#endif // VBAM_WX_STRUTILS_H_ diff --git a/src/wx/tests/CMakeLists.txt b/src/wx/tests/CMakeLists.txt index 1eb3a31e..c4620246 100644 --- a/src/wx/tests/CMakeLists.txt +++ b/src/wx/tests/CMakeLists.txt @@ -29,4 +29,4 @@ function(add_doctest_test test_src) doctest_discover_tests("${test_name}") endfunction() -add_doctest_test(strutils.cpp ../strutils.h ../strutils.cpp) +add_doctest_test(strutils.cpp ../config/strutils.h ../config/strutils.cpp) diff --git a/src/wx/tests/strutils.cpp b/src/wx/tests/strutils.cpp index 5134e50c..a172b898 100644 --- a/src/wx/tests/strutils.cpp +++ b/src/wx/tests/strutils.cpp @@ -1,11 +1,11 @@ -#include "wx/strutils.h" +#include "wx/config/strutils.h" #include "tests.hpp" -TEST_CASE("strutils::split() basic test") { +TEST_CASE("config::str_split() basic test") { wxString foo = "foo|bar|baz"; - auto vec = strutils::split(foo, '|'); + auto vec = config::str_split(foo, '|'); CHECK(vec.size() == 3); @@ -14,10 +14,10 @@ TEST_CASE("strutils::split() basic test") { CHECK(vec[2] == "baz"); } -TEST_CASE("strutils::split() multi-char separator") { +TEST_CASE("config::str_split() multi-char separator") { wxString foo = "foo|-|bar|-|baz"; - auto vec = strutils::split(foo, "|-|"); + auto vec = config::str_split(foo, "|-|"); CHECK(vec.size() == 3); @@ -26,10 +26,10 @@ TEST_CASE("strutils::split() multi-char separator") { CHECK(vec[2] == "baz"); } -TEST_CASE("strutils::split() skips empty tokens") { +TEST_CASE("config::str_split() skips empty tokens") { wxString foo = "|-|foo|-||-|bar|-|baz|-|"; - auto vec = strutils::split(foo, "|-|"); + auto vec = config::str_split(foo, "|-|"); CHECK(vec.size() == 3); @@ -38,26 +38,26 @@ TEST_CASE("strutils::split() skips empty tokens") { CHECK(vec[2] == "baz"); } -TEST_CASE("strutils::split() empty input") { +TEST_CASE("config::str_split() empty input") { wxString foo; - auto vec = strutils::split(foo, "|-|"); + auto vec = config::str_split(foo, "|-|"); CHECK(vec.size() == 0); } -TEST_CASE("strutils::split() no tokens, just separators") { +TEST_CASE("config::str_split() no tokens, just separators") { wxString foo = "|-||-||-||-||-|"; - auto vec = strutils::split(foo, "|-|"); + auto vec = config::str_split(foo, "|-|"); CHECK(vec.size() == 0); } -TEST_CASE("strutils::split_with_sep() basic test") { +TEST_CASE("config::str_split_with_sep() basic test") { wxString foo = "foo|bar|baz|"; - auto vec = strutils::split_with_sep(foo, '|'); + auto vec = config::str_split_with_sep(foo, '|'); CHECK(vec.size() == 4); @@ -67,10 +67,10 @@ TEST_CASE("strutils::split_with_sep() basic test") { CHECK(vec[3] == "|"); } -TEST_CASE("strutils::split_with_sep() multi-char sep") { +TEST_CASE("config::str_split_with_sep() multi-char sep") { wxString foo = "foo|-|bar|-|baz|-|"; - auto vec = strutils::split_with_sep(foo, "|-|"); + auto vec = config::str_split_with_sep(foo, "|-|"); CHECK(vec.size() == 4); @@ -80,10 +80,10 @@ TEST_CASE("strutils::split_with_sep() multi-char sep") { CHECK(vec[3] == "|-|"); } -TEST_CASE("strutils::split_with_sep() multiple sep tokens") { +TEST_CASE("config::str_split_with_sep() multiple sep tokens") { wxString foo = "|-|foo|-||-|bar|-|baz|-|"; - auto vec = strutils::split_with_sep(foo, "|-|"); + auto vec = config::str_split_with_sep(foo, "|-|"); CHECK(vec.size() == 6); diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index a2682bfe..afbeeddd 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -39,7 +39,7 @@ #include "wx/config/option-proxy.h" #include "wx/config/option.h" #include "wx/config/user-input.h" -#include "wx/strutils.h" +#include "wx/config/strutils.h" #include "wx/wayland.h" #include "wx/widgets/group-check-box.h" #include "wx/widgets/user-input-ctrl.h" @@ -433,7 +433,7 @@ bool wxvbamApp::OnInit() { // process command-line options for (size_t i = 0; i < pending_optset.size(); i++) { - auto parts = strutils::split(pending_optset[i], wxT('=')); + auto parts = config::str_split(pending_optset[i], wxT('=')); opt_set(parts[0], parts[1]); } @@ -773,7 +773,7 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) for (int i = 0; i < nparm; i++) { auto p = cl.GetParam(i); - auto parts = strutils::split(p, wxT('=')); + auto parts = config::str_split(p, wxT('=')); if (parts.size() > 1) { opt_set(parts[0], parts[1]);