diff --git a/README.MD b/README.MD index 05a0db7..ab15962 100644 --- a/README.MD +++ b/README.MD @@ -1,22 +1,45 @@ # JKSV Rewrite +

+ + Language + + + GitHub stars + + + GitHub forks + + + GitHub downloads + + + GitHub release + + + License + + +

+ +--- +

-If you appreciate my work, or if JKSM or JKSV has gotten you out of a jam, please consider supporting development through a donation. Any contribution is appreciated, but never required! Creating and maintaining these tools takes a lot of time and effort. + If you appreciate my work, or if JKSM or JKSV has gotten you out of a jam, please consider supporting development through a donation. Any contribution is appreciated, but never required! Creating and maintaining these tools takes a lot of time and effort.

-Support me for the countless hours I poured into JKSV + Support me for the countless hours I poured into JKSV

- ## Rewritten from the ground up: JKSV's rewrite aims to accomplish the following: -- **Clean up and modernize the codebase:** The original master branch code became a mess over time and is extremely difficult to navigate and maintain. +- **Clean up and modernize the codebase:** The original master branch code became a mess over time and is extremely difficult to navigate and maintain. - **Zero global variables:** Everything is encapsulated via interfaces. This alone makes the rewrite easier to work with and **much** less fragile in comparison to the original. - **Improved error logging:** The master branch did an extremely poor job at logging errors. The rewrite corrects this greatly. Each error is logged with the file, line, and column making errors and bugs easier to track down. - **Designed with translations in mind:** Unlike the original, translations weren't a feature that were tacked on later. This also made the original difficult to maintain. - **Use standard formats:** JKSV originally used a custom file parser for data files. This has been removed in favor of JSON using libjson-c. -- **Uses [FsLib](https://github.com/J-D-K/FsLib) instead of [fs_dev.c](https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/devices/fs_dev.c):** +- **Uses [FsLib](https://github.com/J-D-K/FsLib):** - All file operations are handled using FsLib. FsLib is a C++ wrapper I wrote around libnx's FS API. - FsLib also handles SD card redirection so libraries that depend on C standard I/O can read and write files to and from the SD card. - **More convenient Google Drive login.** @@ -27,7 +50,7 @@ JKSV's rewrite aims to accomplish the following: - **Polymorphism and state patterns** instead of scattered global variables and logic. - **Smart pointers** to enure no memory leaks can occur. - **C APIs wrapped in smart pointers and classes** to ensure proper cleanup. - - **Templated task system** to reduce code duplication and complexity. + - **Thread-pooled task system** Reduces overhead by reusing threads for tasks rather than creating and destroying them repeatedly. - **SDL textures** are all wrapped and managed by a central texture manager. JKSV's rewrite is a ground-up rewrite. It shares none of the original's code **at all**. **Everything** has been reworked and rewritten. diff --git a/source/stringutil.cpp b/source/stringutil.cpp index 29b586d..7e620a5 100644 --- a/source/stringutil.cpp +++ b/source/stringutil.cpp @@ -10,9 +10,14 @@ #include #include +namespace +{ + constexpr std::array FORBIDDEN = + {L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*', L'™', L'©', L'®'}; +} + // Defined at bottom. -static std::unordered_set &get_forbidden_characters(); -static std::unordered_map &get_replacement_table(); +static const std::unordered_map &get_replacement_table(); std::string stringutil::get_formatted_string(const char *format, ...) { @@ -50,9 +55,8 @@ void stringutil::strip_character(char c, std::string &target) bool stringutil::sanitize_string_for_path(const char *stringIn, char *stringOut, size_t stringOutSize) { uint32_t codepoint{}; - const int length = std::char_traits::length(stringIn); - auto &forbiddenChars = get_forbidden_characters(); - auto &replacementTable = get_replacement_table(); + const int length = std::char_traits::length(stringIn); + const auto &replacementTable = get_replacement_table(); for (int i = 0, outOffset = 0; i < length;) { @@ -61,7 +65,7 @@ bool stringutil::sanitize_string_for_path(const char *stringIn, char *stringOut, if (count <= 0 || outOffset + count >= static_cast(stringOutSize)) { return false; } // If it's forbidden, skip. - const bool isForbidden = forbiddenChars.find(codepoint) != forbiddenChars.end(); + const bool isForbidden = std::find(FORBIDDEN.begin(), FORBIDDEN.end(), codepoint) != FORBIDDEN.end(); if (isForbidden) { i += count; @@ -77,7 +81,7 @@ bool stringutil::sanitize_string_for_path(const char *stringIn, char *stringOut, const size_t remainingSize = stringOutSize - outOffset; const std::span stringSpan{&stringOut[outOffset], remainingSize}; - std::copy(replacement.data(), replacement.data() + replacementLength, stringSpan.begin()); + std::copy(replacement.begin(), replacement.end(), stringSpan.begin()); outOffset += replacementLength; i += count; @@ -132,17 +136,9 @@ std::string stringutil::get_date_string(stringutil::DateFormat format) return std::string(stringBuffer); } -static std::unordered_set &get_forbidden_characters() +static const std::unordered_map &get_replacement_table() { - static std::unordered_set forbidden = - {L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*', L'™', L'©', L'®'}; - - return forbidden; -} - -static std::unordered_map &get_replacement_table() -{ - static std::unordered_map replacementTable = { + static const std::unordered_map replacementTable = { {L'Á', "A"}, {L'À', "A"}, {L'Â', "A"}, {L'Ä', "A"}, {L'Ã', "A"}, {L'Å', "A"}, {L'Ā', "A"}, {L'Ă', "A"}, {L'Ą', "A"}, {L'Ǎ', "A"}, {L'Ǻ', "A"}, {L'Ȁ', "A"}, {L'Ȃ', "A"}, {L'Ǟ', "A"}, {L'Ǡ', "A"}, {L'á', "a"}, {L'à', "a"}, {L'â', "a"}, {L'ä', "a"}, {L'ã', "a"}, {L'å', "a"}, {L'ā', "a"}, {L'ă', "a"}, {L'ą', "a"},